(fix DrChip changed URL + minor manual clean) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
Line 13: | Line 13: | ||
When reading text, it can be useful to make a wide window, then split it vertically so two consecutive pages of text can be seen in the left and right windows. |
When reading text, it can be useful to make a wide window, then split it vertically so two consecutive pages of text can be seen in the left and right windows. |
||
− | With a large monitor, you might enter < |
+ | With a large monitor, you might enter <code>:set columns=160</code> to make the screen 160 columns wide. This tip can then be used to split the screen to show two windows, with the '<code>scrollbind</code>' option set so that scrolling one window also scrolls the other window. |
==Mapping== |
==Mapping== |
||
Line 21: | Line 21: | ||
</pre> |
</pre> |
||
− | With the default leader, you can now press < |
+ | With the default leader, you can now press <code>\vs</code> to vertically split the screen into two windows with '<code>scrollbind</code>' set. To display only a single window, press Ctrl-W then <code>o</code>. |
The mapping performs these operations: |
The mapping performs these operations: |
||
Line 36: | Line 36: | ||
</pre> |
</pre> |
||
− | The mapping clears '< |
+ | The mapping clears '<code>scrollbind</code>' before manipulating the windows so that the position of the second window can be adjusted without scrolling the first window. Setting '<code>scrolloff</code>' to 0 allows the cursor to be positioned at the bottom of the screen (with command <code>L</code>). |
;Problems |
;Problems |
||
− | *If the cursor is in the last line when the mapping is executed, the mapping fails because < |
+ | *If the cursor is in the last line when the mapping is executed, the mapping fails because <code>j</code> cannot move the cursor down (and the remaining commands are not executed). |
*Register z is changed. |
*Register z is changed. |
||
Latest revision as of 06:39, 13 July 2012
created 2009 · complexity basic · author Nsg · version 7.0
When reading text, it can be useful to make a wide window, then split it vertically so two consecutive pages of text can be seen in the left and right windows.
With a large monitor, you might enter :set columns=160
to make the screen 160 columns wide. This tip can then be used to split the screen to show two windows, with the 'scrollbind
' option set so that scrolling one window also scrolls the other window.
Mapping[]
Enter the following command (or put in your vimrc):
:noremap <silent> <Leader>vs :<C-u>let @z=&so<CR>:set so=0 noscb<CR>:bo vs<CR>Ljzt:setl scb<CR><C-w>p:setl scb<CR>:let &so=@z<CR>
With the default leader, you can now press \vs
to vertically split the screen into two windows with 'scrollbind
' set. To display only a single window, press Ctrl-W then o
.
The mapping performs these operations:
:<C-u> " clear command line (if in visual mode) let @z=&so " save scrolloff in register z :set so=0 noscb " set scrolloff to 0 and clear scrollbind :bo vs " split window vertically, new window on right Ljzt " jump to bottom of window + 1, scroll to top :setl scb " setlocal scrollbind in right window <C-w>p " jump to previous window :setl scb " setlocal scrollbind in left window :let &so=@z " restore scrolloff
The mapping clears 'scrollbind
' before manipulating the windows so that the position of the second window can be adjusted without scrolling the first window. Setting 'scrolloff
' to 0 allows the cursor to be positioned at the bottom of the screen (with command L
).
- Problems
- If the cursor is in the last line when the mapping is executed, the mapping fails because
j
cannot move the cursor down (and the remaining commands are not executed). - Register z is changed.
See also[]
- vim_use discussion
- MPage plugin that supports multiple windows (two or more) with sequential text
Comments[]
I put this into a function:
noremap <silent> <Leader>ac :exe AddColumn()<CR> function! AddColumn() exe "norm \<C-u>" let @z=&so set noscb so=0 bo vs exe "norm \<PageDown>" setl scrollbind wincmd p setl scrollbind let &so=@z endfunction
Except when I try to scroll one of the buffer windows by one line or more. In that case, the line-difference between each buffer is reduced to zero. Curiously, this works perfectly when done by hand in the command prompt.
I have read that that line-difference is meant for 2 different files. However, we are using the same file, but in two different windows. Then, how do I keep that line difference valid between the windows on_scroll?