On Mar 21, 2007, at 11:44 PM, A.J.Mechelynck wrote:
Dave Land wrote:
Shawn & Vim friends,
On Mar 21, 2007, at 6:21 PM, shawn bright wrote:
cool, thanks, i knew there had to be something.
And it keeps getting better. Due to Vim's extensive
programmability and keystroke mapping and the endless creativity
of its developer and user communities), you can extend its
behavior to your needs.
When you use the n and N keystrokes to step forward and backwards
through the list of matches for a pattern, the focus inevitably
moves down the screen from match to match until it reaches the
last match on the screen, then the screen scrolls up or down to
bring the next of-screen match into view... I tire of having to
follow the cursor up and down the screen following the cursor, so
I came up with a solution that works for me.
Now, I happen to use a Mac, so the keystrokes I've mapped make
sense to me, but might be different for someone else... This is a
chunk out of my .vimrc file:
" Command-[ and Command-] put the prev/next match at top of screen
map <D-[> kNz<CR> " put prev match at top of screen
map <D-]> jnz<CR> " put next match at top of screen
Thus, after having typed something like:
/foo
with my mappings, I can type command-] to go to the next match AND
scroll it to the top of my screen. That way, my tired old eyes can
sit in one place and watch the matches come to them.
This is especially handy when I'm editing a data file that has a
lot of lines that are formatted quite similarly: as the matched
lines replace each other as the "first" line on the screen, I
clearly see the parts that stay the same and the parts that change
-- I make a lot fewer mistakes that way.
I don't think j and k are necessary in your mappings; they may be
downright counter-productive (going back forever to the same match)
after a ? search.
Thanks for the correction, Tony, but at least I was _half_-right :-)
I generally don't use backwards searches (?), only forwards searches
(/). My mappings _do_ behave badly for backwards searches, and while
I'm sure something could be done to improve them, I think I'll stick
with my forward searches for now...
As you point out, though, even for forward searches (/), my mappings
were not quite right:
- The "k" command in my mapping for moving backward didn't create a
loop, as you suggested, but caused a match to the right of the
current character, but on the line above the current line, to be
skipped:
k (move up one line)
N (find backwards -- sometimes skipping a match on that line)
z<CR> (scroll line to top of screen)
- The "j" command in my mapping for moving forward is still needed,
however, because the "z<CR>" sequence puts the cursor at the first
non-blank character of the line. Without the "j", you really _would_
keep finding the same match.
Thanks again,
Dave