Sunday, August 21, 2011

Re: motion.txt suggested mappings for [[, ][, ]] and []

On 08/21/2011 03:48 PM, Guido Van Hoecke wrote:
> Csharp class methods do not have the { in column one, so I would like to modify
> the [[, ][, ]] and [] mappings as suggested in motion.txt, lines 495-500:
>
> If your '{' or '}' are not in the first column, and you would like to use "[["
> and "]]" anyway, try these mappings:
> :map [[ ?{<CR>w99[{

?{<cr> search backwards for a "{" [1]
w go to the next word
99[{ go to the 99th[2] unmatched "{"

> :map ][ /}<CR>b99]}

/}<cr> search forwards for a "}" [1]
b go to the previous word
99]} go to the 99th[2] unmatched "}"

> :map ]] j0[[%/{<CR>

j go down one line
0 go to the 1st character on the line
[[ do the "[[" mapping defined above
% go to the matching/closing "}"
/{<cr> search for the next "{"

> :map [] k$][%?}<CR>

k go up one line
$ go to the end of that line
][ do the "][" mapping defined above
% go to the matching/opening "{"
?}<cr> search backwards for the previous "}"

> Could somebody please explain these to me?

Hope that sheds a little light on how those break down.

[1] this may get thrown off by a "{" in string-literals

[2] it will stop at the outermost unmatched "{", so "99" is just
a big number. If for some obscene reason, you have more than 99
nested "{...} blocks, you should (a) increase the 99 to something
bigger, or more importantly (b) refactor your code :)

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: