(Adjust previous/next navigation) |
JohnBeckett (talk | contribs) (rewrite and rough merge in from tip 281) |
||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=182 |
|id=182 |
||
|previous=181 |
|previous=181 |
||
|next=184 |
|next=184 |
||
− | |created= |
+ | |created=2001 |
|complexity=basic |
|complexity=basic |
||
− | |author= |
+ | |author= |
− | |version= |
+ | |version=6.0 |
|rating=24/18 |
|rating=24/18 |
||
|category1= |
|category1= |
||
|category2= |
|category2= |
||
}} |
}} |
||
+ | When jumping around in a large file, you may like to keep the cursor line in the middle of the window (vertically centered). To do this, enter the command: |
||
− | I hope i don't hear a collective 'DUH!' from around the world but i just did this and i think it's kinda cool. |
||
+ | <pre> |
||
− | |||
⚫ | |||
− | In your [[vimrc]] add: |
||
+ | </pre> |
||
+ | To restore normal behavior, enter: |
||
<pre> |
<pre> |
||
+ | :set so=0 |
||
− | map j jzz |
||
− | map k kzz |
||
</pre> |
</pre> |
||
⚫ | |||
− | So whenever you go up or down, Vim does that and then re-centers. Obviously it doesn't work when you page up/ down. |
||
+ | Alternatively, you might want vertical centering only following some commands, such as moving the cursor down/up with <tt>j</tt> and <tt>k</tt>. To achieve that, you could remap the keys: |
||
⚫ | |||
+ | <pre> |
||
⚫ | |||
+ | :nnoremap j jzz |
||
+ | :nnoremap k kzz |
||
+ | </pre> |
||
+ | ==Rough merge in from tip 281== |
||
⚫ | |||
+ | Do you find yourself hitting 'zz' all the time in order to see some context of what you're currently working on? If so, then this tip might be for you. If you add the following line in your vimrc, you can toggle zz mode by pressing <Leader>zz. |
||
+ | <pre> |
||
+ | " maintain a constant zz state, second call will toggle it back off |
||
+ | map <Leader>zz :let &scrolloff=999-&scrolloff<CR> |
||
+ | </pre> |
||
+ | ==See also== |
||
− | Try it and see what happens. It's also compatible with PgUp/Down, arrow keys, ^B/^F, and other scrolling commands. |
||
+ | *[[Make search results appear in the middle of the screen]] |
||
+ | ==References== |
||
− | ---- |
||
+ | *{{help|'scrolloff'}} |
||
− | The "set so=9999" setting works better, but it renders "H", "M", "L" useless which is a pain |
||
+ | *{{help|zz}} |
||
⚫ | |||
− | ---- |
Revision as of 09:35, 25 February 2010
When jumping around in a large file, you may like to keep the cursor line in the middle of the window (vertically centered). To do this, enter the command:
:set so=999
To restore normal behavior, enter:
:set so=0
The 'scrolloff' option (abbreviated as 'so') sets how many lines of context are maintained above and below the cursor. If you set this to a large value, the cursor will stay in the center of the screen when possible.
Alternatively, you might want vertical centering only following some commands, such as moving the cursor down/up with j and k. To achieve that, you could remap the keys:
:nnoremap j jzz :nnoremap k kzz
Rough merge in from tip 281
Do you find yourself hitting 'zz' all the time in order to see some context of what you're currently working on? If so, then this tip might be for you. If you add the following line in your vimrc, you can toggle zz mode by pressing <Leader>zz.
" maintain a constant zz state, second call will toggle it back off map <Leader>zz :let &scrolloff=999-&scrolloff<CR>