# HG changeset patch # User Steve Losh # Date 1365039617 14400 # Node ID 4fa876d7523c20ecae2788d45ee994387327dda5 # Parent 436f8ce22479db82223fb871392dc96b3be212d9 Proof 13-18. diff -r 436f8ce22479 -r 4fa876d7523c chapters/14.markdown --- a/chapters/14.markdown Wed Apr 03 21:16:19 2013 -0400 +++ b/chapters/14.markdown Wed Apr 03 21:40:17 2013 -0400 @@ -7,10 +7,10 @@ :autocmd BufWrite * :echom "Writing buffer!" Now write the current buffer with `:write` and run `:messages` to view the -message log. You should see the "Writing buffer!" message in the list. +message log. You should see the `Writing buffer!` message in the list. Now write the current buffer again and run `:messages` to view the message log. -You should see the "Writing buffer!" message in the list twice. +You should see the `Writing buffer!` message in the list twice. Now run the exact same autocommand again: @@ -18,7 +18,7 @@ :autocmd BufWrite * :echom "Writing buffer!" Write the current buffer one more time and run `:messages`. You will see the -"Writing buffer!" message in the list *four* times. What happened? +`Writing buffer!` message in the list *four* times. What happened? When you create an autocommand like this Vim has no way of knowing if you want it to replace an existing one. In our case, Vim created two *separate* @@ -73,7 +73,7 @@ The indentation in the middle two lines is insignificant. You don't have to type it if you don't want to. -Write a buffer and check `:messages`. You should see both "Foo" and "Bar". Now +Write a buffer and check `:messages`. You should see both `Foo` and `Bar`. Now run the following commands: :::vim @@ -90,7 +90,7 @@ What happened when you wrote the file? Was it what you expected? -If you thought Vim would "replace" the group, you can see that you guessed +If you thought Vim would replace the group, you can see that you guessed wrong. Don't worry, most people think the same thing at first (I know I did). When you use `augroup` multiple times Vim will *combine* the groups each time. @@ -105,7 +105,7 @@ :augroup END Now try writing your file and checking `:messages`. This time Vim only echoed -"Cats" when you wrote the file. +`Cats` when you wrote the file. Using Autocommands in Your Vimrc -------------------------------- @@ -136,3 +136,4 @@ Try to figure out what the mapping in the last example does. Read `:help autocmd-groups`. + diff -r 436f8ce22479 -r 4fa876d7523c chapters/15.markdown --- a/chapters/15.markdown Wed Apr 03 21:16:19 2013 -0400 +++ b/chapters/15.markdown Wed Apr 03 21:40:17 2013 -0400 @@ -65,8 +65,8 @@ return foo -Put you cursor on the `i` in the second line and press `db`. What happened? -Vim deleted the entire body of the function, all the way up until the "return", +Put your cursor on the `i` in the second line and press `db`. What happened? +Vim deleted the entire body of the function, all the way up until the `return`, which our mapping used Vim's normal search to find. When you're trying to think about how to define a new operator-pending movement, @@ -98,7 +98,7 @@ :::python print foo(bar) -Put your cursor somewhere in the word "print" and type `cin(`. Vim will delete +Put your cursor somewhere in the word `print` and type `cin(`. Vim will delete the contents of the parentheses and place you in insert mode between them. You can think of this mapping as meaning "inside next parentheses", and it will @@ -114,16 +114,16 @@ Try it out on some text of your own to make sure it works. So how do these mappings work? First, the `` is something special that you -can ignore for now -- just know that it needs to be there to make the mappings -work in all cases. If we remove that we're left with: +can ignore for now -- just trust me that it needs to be there to make the +mappings work in all cases. If we remove that we're left with: :::vim :normal! F)vi( `:normal!` is something we'll talk about in a later chapter, but for now it's -enough to know that it's a command that can be used to simulate pressing keys in -normal mode. For example, running `:normal! dddd` will delete two lines, just -like pressing `dddd`. The `` at the end of the mapping is what executes the +enough to know that it is a command used to simulate pressing keys in normal +mode. For example, running `:normal! dddd` will delete two lines, just like +pressing `dddd`. The `` at the end of the mapping is what executes the `:normal!` command. So now we know that the mapping is essentially just running the last block of diff -r 436f8ce22479 -r 4fa876d7523c chapters/16.markdown --- a/chapters/16.markdown Wed Apr 03 21:16:19 2013 -0400 +++ b/chapters/16.markdown Wed Apr 03 21:40:17 2013 -0400 @@ -32,7 +32,7 @@ This mapping is pretty complicated, so put your cursor in one of the paragraphs (not the headings) and type `cih`. Vim will delete the heading of whatever -section you're in and put you in insert mode. +section you're in and put you in insert mode ("change inside heading"). It uses some things we've never seen before, so let's look at each piece individually. The first part of the mapping, `:onoremap ih` is just the mapping @@ -68,13 +68,13 @@ Execute ------- -The `execute` takes a Vimscript string (which we'll cover in more detail later) -and performs it as a command. Run this: +The `execute` command takes a Vimscript string (which we'll cover in more detail +later) and performs it as a command. Run this: :::vim :execute "write" -Vim will write your file, just as if you had typed `:write`. Now run this +Vim will write your file, just as if you had typed `:write`. Now run this command: :::vim @@ -165,7 +165,7 @@ Try it by putting your cursor in a section's text and typing `cah`. This time Vim will delete not only the heading's text but also the line of equal signs -that denotes a heading. You can think of this movement as "around this +that denotes a heading. You can think of this movement as "*around* this section's heading". What's different about this mapping? Let's look at them side by side: @@ -213,3 +213,4 @@ Create a "inside next email address" operator-pending mapping so you can say "change inside next email address". `in@` is a good candidate for the keys to map. You'll probably want to use `/...some regex...` for this. + diff -r 436f8ce22479 -r 4fa876d7523c chapters/17.markdown --- a/chapters/17.markdown Wed Apr 03 21:16:19 2013 -0400 +++ b/chapters/17.markdown Wed Apr 03 21:40:17 2013 -0400 @@ -14,7 +14,7 @@ :::vim :set statusline=%f\ -\ FileType:\ %y -Now you'll see something like "foo.markdown - FileType: [markdown]" in the +Now you'll see something like `foo.markdown - FileType: [markdown]` in the status line. If you're familiar with C's `printf` or Python's string interpolation the format @@ -49,7 +49,7 @@ :set statusline+=%L " Total lines Now the status line contains only the current line number and number of lines in -the file, and looks something like "12/223". +the file, and looks something like `12/223`. Width and Padding ----------------- @@ -94,7 +94,7 @@ :::vim :set statusline=%04l -Now your status line will read "0012" when on line twelve. +Now your status line will read `0012` when on line twelve. Finally, you can also set the maximum width of a code's output. Run this command: diff -r 436f8ce22479 -r 4fa876d7523c chapters/18.markdown --- a/chapters/18.markdown Wed Apr 03 21:16:19 2013 -0400 +++ b/chapters/18.markdown Wed Apr 03 21:40:17 2013 -0400 @@ -13,7 +13,7 @@ ---------- Vimscript is extremely powerful, but has grown organically over the years into -a twisty maze ready to ensnare the unwary programmers who enter it. +a twisty maze ready to ensnare unwary programmers who enter it. Options and commands are often terse and hard to read, and working around compatibility issues can increase the complexity of your code. Writing a plugin @@ -21,7 +21,7 @@ Be defensive when writing anything that takes more than a few lines of Vimscript. Add a comment explaining what it does, and if there is a relevant -help topic mention it in that comment! +help topic, mention it in the comment! This not only benefits you when you try to maintain it months or years later, but also helps other people understand it if you share your `~/.vimrc` file on @@ -52,11 +52,12 @@ files. Go ahead and run `:setlocal foldmethod=marker` in the window with your -`~/.vimrc` now. Sourcing the file won't work, because Vim has already set the -FileType for this file and the autocommand only fires when that happens. In the -future you won't need to do it manually. +`~/.vimrc` file now. Sourcing the file won't work, because Vim has already set +the FileType for this file and the autocommand only fires when that happens. In +the future you won't need to do it manually. -Now add lines before and after that autocommand group so that it looks like this: +Now add lines before and after that autocommand group so that it looks like +this: :::vim " Vimscript file settings ---------------------- {{{