Tuesday, October 26, 2010

Re: Behavior like 'scrolloff', but only for jumps?

On Tue, 26 Oct 2010, Andy Wokula wrote:

> Am 26.10.2010 19:28, schrieb Benjamin R. Haskell:
>> When searching through files, I'd like to have "context" in the sense
>> that 'scrolloff' provides. But I don't want it for normal editing.
>>
>> E.g. I'd like to be able to manually scroll such that the cursor is
>> on the last line of the window, but when jumping around via 'n', I
>> don't ever want to end up on the last line.
>>
>> Is there such an option already?
>>
>> If not, how could I simply wrap the built-in normal mode 'n' command
>> with a save-and-restore of 'so'?
>>
>> First attempt: (guessing it fails because of calling feedkeys from w/in
>> a mapping?)
>>
>> fun! NoEndJump()
>> let so=&l:so
>> call feedkeys('n','n')
>> let &l:so=so
>> endfun
>> nnoremap n <C-O>:call NoEndJump()<CR>
>
> Smoked too much of that 'scrolloff' thing?
> :nnoremap n nzz

I do have a tendency to run with things a bit too far. :-)

Your solution's close, but no cigar. It accomplishes my goal (not
ending up on the last line of the window) by always ending up in the
middle of the screen (which will never be the bottom). But, I only want
any scrolling at all if the next match is off-screen. (Which works
right with 'so' enabled.)

Running with your solution, this is what I was looking for:

:nnoremap n nzv3j3k

(zv ensures folds are open after landing at the search destination, and
the jk sequence ensures there are at least three lines visible below the
search match)

--
Thanks much,
Ben

--
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: