Skip to content

Commit

Permalink
Holy shit.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Apr 4, 2013
1 parent 094f242 commit 0aea17a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chapters/32.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ cursor, it's time to concatenate it into our mapping! Run the following
command:

:::vim
:nnoremap <leader>g :execute "grep -R " . shellescape(expand("<cWORD>")) . " ."<cr>
:nnoremap <leader>g :exe "grep -R " . shellescape(expand("<cWORD>")) . " ."<cr>

Try it out. This mapping won't break if the word we're searching for happens to
contain strange characters.
Expand Down
47 changes: 35 additions & 12 deletions chapters/51.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ Change the `sections.vim` file to contain this:
function! s:NextSection(type, backwards)
endfunction

noremap <script> <buffer> <silent> ]] :call <SID>NextSection(1, 0)<cr>
noremap <script> <buffer> <silent> [[ :call <SID>NextSection(1, 1)<cr>
noremap <script> <buffer> <silent> ]]
\ :call <SID>NextSection(1, 0)<cr>

noremap <script> <buffer> <silent> ][ :call <SID>NextSection(2, 0)<cr>
noremap <script> <buffer> <silent> [] :call <SID>NextSection(2, 1)<cr>
noremap <script> <buffer> <silent> [[
\ :call <SID>NextSection(1, 1)<cr>

noremap <script> <buffer> <silent> ][
\ :call <SID>NextSection(2, 0)<cr>

noremap <script> <buffer> <silent> []
\ :call <SID>NextSection(2, 1)<cr>

I used Vimscript's long line continuation feature here because the lines were
getting a bit long for my taste. Notice how the backslash to escape long lines
comes at the *beginning* of the second line. Read `:help line-continuation` for
more information.

Notice that we're using `<SID>` and a script-local function to avoid polluting
the global namespace with our helper function.
Expand Down Expand Up @@ -319,21 +330,33 @@ Now we need to update the existing mappings to pass `0` in for the new `visual`
argument:

:::vim
noremap <script> <buffer> <silent> ]] :call <SID>NextSection(1, 0, 0)<cr>
noremap <script> <buffer> <silent> [[ :call <SID>NextSection(1, 1, 0)<cr>
noremap <script> <buffer> <silent> ]]
\ :call <SID>NextSection(1, 0, 0)<cr>

noremap <script> <buffer> <silent> [[
\ :call <SID>NextSection(1, 1, 0)<cr>

noremap <script> <buffer> <silent> ][ :call <SID>NextSection(2, 0, 0)<cr>
noremap <script> <buffer> <silent> [] :call <SID>NextSection(2, 1, 0)<cr>
noremap <script> <buffer> <silent> ][
\ :call <SID>NextSection(2, 0, 0)<cr>

noremap <script> <buffer> <silent> []
\ :call <SID>NextSection(2, 1, 0)<cr>

Nothing too complex there. Now let's add the visual mode mappings as the final
piece of the puzzle:

:::vim
vnoremap <script> <buffer> <silent> ]] :<c-u>call <SID>NextSection(1, 0, 1)<cr>
vnoremap <script> <buffer> <silent> [[ :<c-u>call <SID>NextSection(1, 1, 1)<cr>
vnoremap <script> <buffer> <silent> ]]
\ :<c-u>call <SID>NextSection(1, 0, 1)<cr>

vnoremap <script> <buffer> <silent> [[
\ :<c-u>call <SID>NextSection(1, 1, 1)<cr>

vnoremap <script> <buffer> <silent> ][
\ :<c-u>call <SID>NextSection(2, 0, 1)<cr>

vnoremap <script> <buffer> <silent> ][ :<c-u>call <SID>NextSection(2, 0, 1)<cr>
vnoremap <script> <buffer> <silent> [] :<c-u>call <SID>NextSection(2, 1, 1)<cr>
vnoremap <script> <buffer> <silent> []
\ :<c-u>call <SID>NextSection(2, 1, 1)<cr>

These mappings all pass `1` for the `visual` argument to tell Vim to reselect
the last selection before performing the movement. They also use the `<c-u>`
Expand Down
12 changes: 6 additions & 6 deletions chapters/54.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ Now that we have an idea of what sections we'll include, add the following to
the `potion.txt` file:

:::text
==============================================================================
CONTENTS *PotionContents*
====================================================================
CONTENTS *PotionContents*

1. Usage ................ |PotionUsage|
2. Mappings ............. |PotionMappings|
Expand Down Expand Up @@ -179,11 +179,11 @@ Sections
You can create section headers like this:

:::text
==============================================================================
Section 1: Usage *PotionUsage*
====================================================================
Section 1: Usage *PotionUsage*

This plugin with automatically provide syntax highlighting for Potion files
(files ending in .pn).
This plugin with automatically provide syntax highlighting for
Potion files (files ending in .pn).

It also...

Expand Down
12 changes: 12 additions & 0 deletions introduction.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ The book is [copyright][license] 2013 by Steve Losh, all rights reserved. You
can redistribute it as long as you don't make any changes and don't charge for
it.

The book will always be free to read online.

You can buy an ebook (PDF, epub, mobi) version for $8 on Leanpub at:
<http://leanpub.org/learnvimscriptthehardway>

You can buy a paperback copy for $20 on Lulu at:
<http://bit.ly/lvsthw-paperback>

You can buy a hardcover copy for $40 on Lulu at:
<http://bit.ly/lvsthw-hardcover>

The source code to the book is available [on BitBucket][hg] and [on
GitHub][git]. If you find any mistakes or feel you could improve it feel free
to send a pull request, but I'm retaining the copyright on the book, so if
Expand All @@ -29,3 +40,4 @@ you're not comfortable with that I understand.
[git]: http://github.com/sjl/learnvimscriptthehardway/
[license]: http://learnvimscriptthehardway.stevelosh.com/license.html
[leanpub]: http://leanpub.com/learnvimscriptthehardway
[lulu]: http://lulu.com/learnvimscriptthehardway

0 comments on commit 0aea17a

Please sign in to comment.