# HG changeset patch # User Steve Losh # Date 1350084768 14400 # Node ID 405fe87b3cf811283e9d91be90d661d92e0448bb # Parent e3bb00c0db497432446d7c33a549024b3bee3a9e# Parent 3f2a0e4680be3c6bc0bb3e8a91323be6f0df96ce Merge. diff -r 3f2a0e4680be -r 405fe87b3cf8 .ffignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.ffignore Fri Oct 12 19:32:48 2012 -0400 @@ -0,0 +1,12 @@ +syntax: literal +\.DS_Store +\.ropeproject +tags +build +venv + +syntax: regex +.*\.pyc +.*\.swp +.*\.swo +.*\.un~ diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/07.markdown --- a/chapters/07.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/07.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -1,7 +1,7 @@ Editing Your Vimrc ================== -Before we move on to learning more Vimscript lets find a way to make it easier +Before we move on to learning more Vimscript let's find a way to make it easier to add new mappings to our `~/.vimrc` file. When you're coding away furiously at a problem and realize a new mapping would diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/09.markdown --- a/chapters/09.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/09.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -76,8 +76,8 @@ instead of double quotes. Try using `vnoremap` to add a mapping that will wrap whatever text you have -*visually selected* in quotes. You'll probably need the ```<`` and ```>`` -commands for this, so read up on them with ``:help `<``. +*visually selected* in quotes. You'll probably need the `` `< `` and `` `> `` +commands for this, so read up on them with `` :help `< ``. Map `H` in normal mode to go to the beginning of the current line. Since `h` moves left you can think of `H` as a "stronger" `h`. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/16.markdown --- a/chapters/16.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/16.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -48,7 +48,9 @@ ------ The `:normal` command takes a set of characters and performs whatever action -they would do if they were typed in normal mode. Run this command: +they would do if they were typed in normal mode. We'll go into greater detail +in a later chapter, but we've seen it a few times already so it's time to at +least get a taste. Run this command: :::vim :normal gg @@ -60,13 +62,8 @@ Vim will indent the current line. -In our mapping we're using a version of `:normal` with a `!` at the end. This -version will *not* take any existing mappings into account, whereas plain -`:normal` will use them. - -In effect, `:normal!` is to `:normal` as `nnoremap` is to `nmap`. You should -*always* prefer `:normal!` for the same reasons you should always use -`nnoremap`, which we discussed in an earlier chapter. +For now, don't worry about the `!` after `normal` in our mapping. We'll talk +about that later. Execute ------- diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/17.markdown --- a/chapters/17.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/17.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -60,7 +60,7 @@ :::vim :set statusline=%4l -The line number in the status line will now be proceeded by enough spaces to +The line number in the status line will now be preceded by enough spaces to make it at least four characters wide (for example: " 12"). This can be useful to prevent the text in the status line from shifting around distractingly. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/18.markdown --- a/chapters/18.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/18.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -58,8 +58,8 @@ :::vim " Vimscript file settings ---------------------- {{{ augroup filetype_vim - au! - au FileType vim setlocal foldmethod=marker + autocmd! + autocmd FileType vim setlocal foldmethod=marker augroup END " }}} diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/19.markdown --- a/chapters/19.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/19.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -56,7 +56,8 @@ integer "0" as "false" and the integer "1" as "true". It's reasonable to assume that Vim treats *any* non-zero integer as "truthy", and this is indeed the case. -We can also *set* options as variables. Run the following commands: +We can also *set* options as variables using the `let` command. Run the +following commands: :::vim :let &textwidth = 100 diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/23.markdown --- a/chapters/23.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/23.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -9,7 +9,7 @@ :::vim :function meow() -You might think this would start defining a function named `Meow`. +You might think this would start defining a function named `meow`. Unfortunately this is not the case, and we've already run into one of Vimscript's quirks. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/24.markdown --- a/chapters/24.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/24.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -81,7 +81,7 @@ : echo a:000 :endfunction - :call Varg("a", "b", "c") + :call Varg2("a", "b", "c") We can see that Vim puts "a" into the named argument `a:foo`, and the rest are put into the list of varargs. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/31.markdown --- a/chapters/31.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/31.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -104,7 +104,7 @@ * First, `execute` takes a String, so the double backslashes we used turn into single backslashes by the time they get to `normal!`. -* Vim, has *four* different "modes" of parsing regular expressions! The default +* Vim has *four* different "modes" of parsing regular expressions! The default mode requires a backslash before the `+` character to make it mean "1 or more of the preceding character" instead of "a literal plus sign". diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/33.markdown --- a/chapters/33.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/33.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -128,7 +128,7 @@ :::vim nnoremap g :set operatorfunc=GrepOperatorg@ - vnoremap g :call GrepOperator(visualmode()) + vnoremap g :call GrepOperator(visualmode()) function! GrepOperator(type) if a:type ==# 'v' @@ -191,7 +191,7 @@ :::vim nnoremap g :set operatorfunc=GrepOperatorg@ - vnoremap g :call GrepOperator(visualmode()) + vnoremap g :call GrepOperator(visualmode()) function! GrepOperator(type) if a:type ==# 'v' @@ -217,7 +217,7 @@ :::vim nnoremap g :set operatorfunc=GrepOperatorg@ - vnoremap g :call GrepOperator(visualmode()) + vnoremap g :call GrepOperator(visualmode()) function! GrepOperator(type) if a:type ==# 'v' diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/34.markdown --- a/chapters/34.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/34.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -18,7 +18,7 @@ :::vim nnoremap g :set operatorfunc=GrepOperatorg@ - vnoremap g :call GrepOperator(visualmode()) + vnoremap g :call GrepOperator(visualmode()) function! GrepOperator(type) let saved_unnamed_register = @@ @@ -60,7 +60,7 @@ :::vim nnoremap g :set operatorfunc=GrepOperatorg@ - vnoremap g :call GrepOperator(visualmode()) + vnoremap g :call GrepOperator(visualmode()) function! s:GrepOperator(type) let saved_unnamed_register = @@ diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/35.markdown --- a/chapters/35.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/35.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -76,7 +76,14 @@ :::vim :echo "abcd"[0:2] -Vim displays "abc". +Vim displays "abc". However, you can't use negative bare indices with strings. +You *can* use negative indices when slicing strings though! Run the following +command: + + :::vim + :echo "abcd"[-1] . "abcd"[-2:] + +Vim displays "cd" (using a negative index silently resulted in an empty string). Concatenation ------------- diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/39.markdown --- a/chapters/39.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/39.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -62,7 +62,7 @@ function! Assoc(l, i, val) let new_list = deepcopy(a:l) - let newlist[a:i] = a:val + let new_list[a:i] = a:val return new_list endfunction diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/43.markdown --- a/chapters/43.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/43.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -112,7 +112,7 @@ Create a Mercurial or Git repository for your plugin, called `potion`. You can put it anywhere you like and symlink it into `~/.vim/bundle/potion/` or just put -it directory in `~/.vim/bundle/potion/`. +it directly in `~/.vim/bundle/potion/`. Create `README` and `LICENSE` files in the repository and commit them. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/44.markdown --- a/chapters/44.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/44.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -72,8 +72,8 @@ :set filetype? This time Vim displays `filetype=potion`. When Vim started up it loaded the -autocommand group inside `~/.vim/bundle/ftdetect/potion.vim`, and when it opened -`factorial.pn` the autocommand fired, setting the `filetype` to `potion`. +autocommand group inside `~/.vim/bundle/potion/ftdetect/potion.vim`, and when it +opened `factorial.pn` the autocommand fired, setting the `filetype` to `potion`. Now that we've taught Vim to recognize Potion files we can move on to actually creating some useful behavior in our plugin. diff -r 3f2a0e4680be -r 405fe87b3cf8 chapters/49.markdown --- a/chapters/49.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/chapters/49.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -245,7 +245,7 @@ If the current line has some non-whitespace characters it won't match and we'll just return `'0'` as before. -If the current line *does* match the regex (i.e. is it's empty or just +If the current line *does* match the regex (i.e. if it's empty or just whitespace) we return the string `'-1'`. Earlier I said that a line's foldlevel can be zero or a positive integer, so @@ -514,7 +514,7 @@ d 1 e 0 -You could, of course, combine these two cases with `&&`, but I prefer to keep +You could, of course, combine these two cases with `||`, but I prefer to keep them separate to make it more explicit. You might feel differently. It's a style issue. @@ -658,7 +658,7 @@ i string print 1 '! is: ' print 1 factorial (i) string print 1 - "\n" print. 1 + "\n" print. The same thing happens when the next line's indentation is *less* than the current line's: diff -r 3f2a0e4680be -r 405fe87b3cf8 introduction.markdown --- a/introduction.markdown Fri Jul 06 12:01:19 2012 +0300 +++ b/introduction.markdown Fri Oct 12 19:32:48 2012 -0400 @@ -1,10 +1,10 @@ -[Learn Vimscript the Hard Way][book] is a short book for users of the Vim editor +[Learn Vimscript the Hard Way][book] is a book for users of the [Vim][] editor who want to learn how to customize Vim. Before reading this book you should be comfortable using Vim and know what terms like "buffer", "window" and "insert mode" mean. -LVSTHW is divided into three sections: +LVSTHW is divided roughly into three sections: * The first covers basic Vim commands that you can use in your `~/.vimrc` file to customize Vim quickly and easily. @@ -28,6 +28,7 @@ if you're not comfortable with that I understand. [book]: / +[Vim]: http://www.vim.org/ [hg]: http://bitbucket.org/sjl/learnvimscriptthehardway/ [git]: http://github.com/sjl/learnvimscriptthehardway/ [license]: /license.html diff -r 3f2a0e4680be -r 405fe87b3cf8 outline.org --- a/outline.org Fri Jul 06 12:01:19 2012 +0300 +++ b/outline.org Fri Oct 12 19:32:48 2012 -0400 @@ -1,51 +1,13 @@ -* part 3 - creating a full plugin -** ... stuff that's done ... -** TODO mapping -*** run and view output -*** run and view bytecode + output -*** :nnoremap ]] /\v^\S:noh -*** :nnoremap [[ ?\v^\S:noh -** TODO indent files -** TODO customization -*** mappings -**** custom leader -**** disable entirely -**** autoinsert period -*** behaviour -**** vertical/horizontal preview splits -**** split sizes -** TODO dynamic status lines +* remaining chapters +** TODO run and view output ** TODO autoload ** TODO documentation -*** TOC -*** Mappings -*** Configuration -*** Bugs -*** License ** TODO distributing -*** GitHub -*** Vim.org -*** a Web page -* TODO Where to go from here -** Omnicomplete -** makeprg, errorfmt -** Read the fucking documentation -** Read the source of some popular plugins -*** Powerline for a mindfuck -*** Fugitive -* Ideas -** MOAR SYNTAX -** MOAR MAPPING -*** -*** -** String Escaping -** Character theory - i.e. n vs n -** -** -** ! -** GUI-Specific stuff -** Color schemes -** command! -** Case Studies -*** Visual mode * from Scrooloose +** TODO Where to go from here +*** Omnicomplete +*** makeprg, errorfmt +*** Color schemes +*** Read the fucking documentation +*** Read the source of some popular plugins +**** Powerline for a mindfuck +**** Fugitive diff -r 3f2a0e4680be -r 405fe87b3cf8 publish.sh --- a/publish.sh Fri Jul 06 12:01:19 2012 +0300 +++ b/publish.sh Fri Oct 12 19:32:48 2012 -0400 @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -./venv/bin/python ../bookmarkdown/bookmarkdown/bookmarkdown build +python ../bookmarkdown/bookmarkdown/bookmarkdown build rsync --delete -az build/html/ sl:/var/www/vimscript/