Commits

Steve Losh committed 5868e62

Proof 32-37.

Comments (0)

Files changed (6)

chapters/32.markdown

     :::vim
     :nnoremap <leader>g :grep -R <cWORD> .<cr>
 
-Now try the mapping when your cursor is over something like "foo-bar".  Vim will
-grep for "foo-bar" instead of just part of the word.
+Now try the mapping when your cursor is over something like `foo-bar`.  Vim will
+grep for `foo-bar` instead of just part of the word.
 
 There's still a problem with our search term: if there are any special shell
 characters in it Vim will happily pass them along to the external grep command,
 --------------------------------
 
 There's still one more problem with the search term.  Try the mapping on the
-word "that's".  It won't work, because the single quote inside the word
+word `that's`.  It won't work, because the single quote inside the word
 interferes with the quotes in the grep command!
 
 To get around this we can use Vim's `shellescape` function.  Read `:help
     :::vim
     :nnoremap <leader>g :execute "grep -R " . shellescape("<cWORD>") . " ."<cr>
 
-Try it out by running it on a normal word like "foo".  It will work properly.
-Now try it out on a word with a quote in it, like "that's".  It still doesn't
+Try it out by running it on a normal word like `foo`.  It will work properly.
+Now try it out on a word with a quote in it, like `that's`.  It still doesn't
 work!  What happened?
 
 The problem is that Vim performed the `shellescape()` call *before* it expanded
 `<cWORD>` into the actual string *before* it gets passed to `shellescape`.
 
 Let's break this apart and see how it works, in steps.  Put your cursor over
-a word with a quote, like "that's", and run the following command:
+a word with a quote, like `that's`, and run the following command:
 
     :::vim
     :echom expand("<cWORD>")

chapters/33.markdown

     endfunction
 
 Write the file and source it with `:source %`.  Try it out by pressing
-`<leader>giw` to say "grep inside word".  Vim will echo "Test" *after* accepting
+`<leader>giw` to say "grep inside word".  Vim will echo `Test` *after* accepting
 the `iw` motion, which means we've laid out the skeleton.
 
 The function is simple and nothing we haven't seen before, but that mapping is
     vnoremap <leader>g :<c-u>call GrepOperator(visualmode())<cr>
 
 Write and source the file.  Now visually select something and press `<leader>g`.
-Nothing happens, but Vim does echo "Test", so our function is getting called.
+Nothing happens, but Vim does echo `Test`, so our function is getting called.
 
 We've seen the `<c-u>` in this mapping before but never explained what it did.
 Try visually selecting some text and pressing `:`.  Vim will open a command line
 the `visualmode()` we're passing as an argument is new.  This function is
 a built-in Vim function that returns a one-character string representing the
 last type of visual mode used: `"v"` for characterwise, `"V"` for
-linewise, and a `ctrl-v` character for blockwise.
+linewise, and a `Ctrl-v` character for blockwise.
 
 Motion Types
 ------------

chapters/34.markdown

 being considerate and making your users' lives easier.  We can do two more
 things to make our operator play nicely in the Vim ecosystem.
 
-
 Saving Registers
 ----------------
 
 Namespacing
 -----------
 
-Our script created a function named "GrepOperator" in the global namespace.
+Our script created a function named `GrepOperator` in the global namespace.
 This probably isn't a big deal, but when you're writing Vimscript it's far
 better to be safe than sorry.
 

chapters/35.markdown

     :::vim
     :echo [0, [1, 2]][1]
 
-Vim displays "[1, 2]".  You can also index from the end of the list, much like
+Vim displays `[1, 2]`.  You can also index from the end of the list, much like
 Python.  Try this command:
 
     :::vim
     :::vim
     :echo ['a', 'b', 'c', 'd', 'e'][0:2]
 
-Vim displays "['a', 'b', 'c']" (elements 0, 1 and 2).  You can safely exceed the
+Vim displays `['a', 'b', 'c']` (elements 0, 1 and 2).  You can safely exceed the
 upper bound as well.  Try this command:
 
     :::vim
     :::vim
     :echo ['a', 'b', 'c', 'd', 'e'][-2:-1]
 
-Vim displays "['d', 'e']" (elements -2 and -1).
+Vim displays `['d', 'e']` (elements -2 and -1).
 
 When slicing lists you can leave off the first index to mean "the beginning"
 and/or the last index to mean "the end".  Run the following commands:
     :echo ['a', 'b', 'c', 'd', 'e'][:1]
     :echo ['a', 'b', 'c', 'd', 'e'][3:]
 
-Vim displays "['a', 'b']" and "['d', 'e']".
+Vim displays `['a', 'b']` and `['d', 'e']`.
 
 Like Python, Vimscript allows you to index and slice strings too.  Run the
 following command:
     :::vim
     :echo "abcd"[0:2]
 
-Vim displays "abc". However, you can't use negative bare indices with strings.
+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).
+Vim displays `cd` (using a negative index silently resulted in an empty string).
 
 Concatenation
 -------------
     :::vim
     :echo ['a', 'b'] + ['c']
 
-Vim, unsurprisingly, displays "['a', 'b', 'c']".  There's not much else to say
+Vim, unsurprisingly, displays `['a', 'b', 'c']`.  There's not much else to say
 here -- Vimscript lists are surprisingly sane compared to the rest of the
 language.
 
     :call add(foo, 'b')
     :echo foo
 
-Vim mutates the list `foo` in-place to append `'b'` and displays "['a', 'b']".
+Vim mutates the list `foo` in-place to append `'b'` and displays `['a', 'b']`.
 Now run this command:
 
     :::vim
     :echo len(foo)
 
-Vim displays "2", the length of the list.  Try these commands:
+Vim displays `2`, the length of the list.  Try these commands:
 
     :::vim
     :echo get(foo, 0, 'default')
     :echo get(foo, 100, 'default')
 
-Vim displays "a" and "default".  The `get` function will get the item at the
+Vim displays `a` and `default`.  The `get` function will get the item at the
 given index from the given list, or return the given default value if the index
 is out of range in the list.
 
     :echo index(foo, 'b')
     :echo index(foo, 'nope')
 
-Vim displays "1" and "-1".  The `index` function returns the first index of the
+Vim displays `1` and `-1`.  The `index` function returns the first index of the
 given item in the given list, or `-1` if the item is not in the list.
 
 Now run this command:
     :echo join(foo, '---')
     :echo join([1, 2, 3], '')
 
-Vim displays "a b", "a---b", and "123".  `join` will join the items in the given
+Vim displays `a b`, `a---b`, and `123`.  `join` will join the items in the given
 list together into a string, separated by the given separator string (or a space
 if none is given), coercing each item to a string if necessary/possible.
 
     :call reverse(foo)
     :echo foo
 
-Vim displays "['b', 'a']" and then "['a', 'b']".  `reverse` reverses the given
+Vim displays `['b', 'a']` and then `['a', 'b']`.  `reverse` reverses the given
 list *in place*.
 
 Exercises
 ---------
 
-Read `:help List`.  All of it.  Notice the capital "L".
+Read `:help List`.  All of it.  Notice the capital `L`.
 
 Read `:help add()`.
 
 
 Skim `:help functions` to find some other list-related functions I haven't
 mentioned yet.  Run `:match Keyword /\clist/` to case-insensitively highlight
-the word "list" to make it easier to find what you're looking for.
+the word `list` to make it easier to find what you're looking for.

chapters/36.markdown

 
     :echom c
 
-Vim displays "10", which is the result of adding together each element in the
+Vim displays `10`, which is the result of adding together each element in the
 list.  Vimscript `for` loops iterate over lists (or dictionaries, which we'll
 cover later).
 
 
     :echom total
 
-Once again Vim displays "10".  This loop should be familiar to just about anyone
+Once again Vim displays `10`.  This loop should be familiar to just about anyone
 who's programmed before, so we won't spend any time on it.  You won't use it
 very often.  Keep it in the back of your mind for the rare occasions that you
 want it.

chapters/37.markdown

 Exercises
 ---------
 
-Read `:help Dictionary`.  All of it.  Notice the capital "D".
+Read `:help Dictionary`.  All of it.  Notice the capital `D`.
 
 Read `:help get()`.