# HG changeset patch # User Steve Losh # Date 1353036065 18000 # Node ID cc9d7d8f821443e480355c2ccde77aec1dab1509 # Parent 495eedad2b7721ce680a9d9d9d1dcf98e6ee3920 Proof 17-18. diff -r 495eedad2b77 -r cc9d7d8f8214 chapters/17.markdown --- a/chapters/17.markdown Sat Nov 10 17:36:05 2012 -0500 +++ b/chapters/17.markdown Thu Nov 15 22:21:05 2012 -0500 @@ -58,11 +58,11 @@ the information is displayed. Run the following command: :::vim - :set statusline=%4l + :set statusline=[%4l] -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. +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. By default the padding spaces are added on the left side of the value. Run this command: @@ -129,8 +129,10 @@ Splitting --------- -We'll come back to status lines later in the book, but there's one more simple -code that can be very useful immediately. Run the following commands: +We're not going to cover status lines in too much detail here (Vim's own +documentation on them is very extensive if you want to learn more), but there's +one more simple code that can be very useful immediately. Run the following +commands: :::vim :set statusline=%f " Path to the file @@ -155,5 +157,5 @@ lines, and add a comment on each line to document what each piece does. Try using autocommands and `setlocal` to define different status lines for -different filetypes. Make sure to wrap the autocommands in groups as always to -prevent duplication. +different filetypes. Make sure to wrap the autocommands in groups to prevent +duplication (as always). diff -r 495eedad2b77 -r cc9d7d8f8214 chapters/18.markdown --- a/chapters/18.markdown Sat Nov 10 17:36:05 2012 -0500 +++ b/chapters/18.markdown Thu Nov 15 22:21:05 2012 -0500 @@ -7,13 +7,13 @@ In the next part of the book we're going to dive into Vimscript as a real programming language, but before we do that I want to talk a bit about how to -stay sane while writing larger chunks of Vimscript. +stay sane while writing large amounts of Vimscript. Commenting ---------- Vimscript is extremely powerful, but has grown organically over the years into -a twisty maze ready to ensnare the unwary who enter it. +a twisty maze ready to ensnare the 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,11 +21,11 @@ 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! +help topic mention it in that 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 -GitHub (which I highly recommend). +Bitbucket or GitHub (which I highly recommend). Grouping -------- @@ -35,8 +35,9 @@ to grow out of control and become hard to navigate. One way to combat this is to use Vim's code folding capabilities and group lines -into sections. If you've never used Vim's folding before check out this great -tutorial. +into sections. If you've never used Vim's folding you should look into it as +soon as you can. Some people (myself included) find it indispensable in our day +to day coding. First we need to set up folding for Vimscript files. Add the following lines to your `~/.vimrc` file: @@ -48,7 +49,9 @@ augroup END This will tell Vim to use the `marker` method of folding for any Vimscript -files. Go ahead and run `:setlocal foldmethod=marker` the window with your +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. @@ -73,11 +76,12 @@ code with folding comments is just noisy to anyone else looking at the code in something other than Vim. -Vimscript files a special case, though. It's highly unlikely that someone who +Vimscript files are special case, though. It's highly unlikely that someone who doesn't use Vim will be reading your code, and it's especially important to -group things explicitly and thoughtfully when writing Vimscript. +group things explicitly and thoughtfully when writing Vimscript so you don't go +crazy. -Try it out for a while and there's a good chance the idea will grow on you. +Try these explicit folds out for a while. You might grow to love them. Short Names ----------- @@ -91,7 +95,7 @@ I'd like to *strongly* caution you against using these abbreviations in your `~/.vimrc` file and in plugins that you write. Vimscript is terse and cryptic -enough to begin with -- shortening things further is only going to make it even +enough to begin with; shortening things further is only going to make it even harder to read. Even if *you* know what a certain short command means, someone else reading your code might not. @@ -117,7 +121,7 @@ information inside. Create a git or Mercurial repository, move the file into it, and symlink that file to `~/.vimrc`. -Commit the repository you just made and put it on BitBucket or GitHub so other +Commit the repository you just made and put it on Bitbucket or GitHub so other people can see it and get ideas for their own. Be sure to commit and push the repository fairly often so your changes are recorded.