Vim Tips Wiki
Nsg (talk | contribs)
(pre)
No edit summary
Line 18: Line 18:
 
set scrollbind
 
set scrollbind
 
</pre>
 
</pre>
  +
  +
Here is a macro you can map to:
  +
  +
<pre>
  +
" display current file in two columns
  +
noremap<silent> ZC :<C-U>let @z=&so<CR>:set so=0<CR>maHmz:set noscb<CR>
  +
\:vs<CR><C-W>wLzt:set scb<CR><C-W>p:set scb<CR>
  +
\`zzt`a:let &so=@z<CR>
  +
</pre>
  +
  +
Replace ZC with your mapping of choice. This will:
  +
:<C-U>let @z=&so " enter the command line, clear it, and save the current 'scrolloff' in register z
  +
:set so=0 " set scrolloff to 0 so the cursor can get to the edge of the page
  +
maHmz " save cursor position using marks a and z so we can get back later
  +
:set noscb " reset 'scrollbind' so we can scroll in the new window
  +
:vs<CR><C-W>w " split a vertical window and switch to it
  +
Lzt " move to the bottom and scroll it to the top
  +
:set scb<CR><C-W>p:set scb<CR> " scrollbind both windows
  +
`zzt`a:let &so=@z " restore cursor position and 'scrolloff'
  +
   
 
[[Category:Usage]]
 
[[Category:Usage]]

Revision as of 09:54, 20 February 2009

View text file in two columns

Large wide monitors can be utilized better if text can be viewed in multiple columns.

The idea is to make wide widow (132, 160 or even more characters wide), then split it vertically, view 2 consequtive pages of the same text in left and right split widows and, finally, scrollbind them together to keep them synchronized.

This can be accomplished by issuing the following commands:

" view file in 2 columns
set noscrollbind
set nowrap
normal mb50%zz
vert split
exe "normal Lma\<c-w>l'azt"
set scrollbind
exe "normal \<c-w>h"
set scrollbind

Here is a macro you can map to:

" display current file in two columns
noremap<silent> ZC :<C-U>let @z=&so<CR>:set so=0<CR>maHmz:set noscb<CR>
                  \:vs<CR><C-W>wLzt:set scb<CR><C-W>p:set scb<CR>
                  \`zzt`a:let &so=@z<CR>

Replace ZC with your mapping of choice. This will:

<C-U>let @z=&so " enter the command line, clear it, and save the current 'scrolloff' in register z
set so=0 " set scrolloff to 0 so the cursor can get to the edge of the page

maHmz " save cursor position using marks a and z so we can get back later

set noscb " reset 'scrollbind' so we can scroll in the new window
vs<CR><C-W>w " split a vertical window and switch to it

Lzt " move to the bottom and scroll it to the top

set scb<CR><C-W>p:set scb<CR> " scrollbind both windows

`zzt`a:let &so=@z " restore cursor position and 'scrolloff'