Thursday, August 18, 2016

Three Minutes Daily Vim Tip: Split Views

To open up a split view, type in
:sp file_to_open.c
:vsp file_to_open.c
The first will open up a horizontal split view, while the latter will open up a vertical one.

To move your cursor between views, type in
<Ctrl> [w] + [h]
<Ctrl> [w] + [j]
<Ctrl> [w] + [k]
<Ctrl> [w] + [l]
where h,j,k,l will move into the corresponding directions, i.e., left, down, up, and right.

To change size automatically, type in
<Ctrl> [w] + [=]

For manual size manipulation, type in
:resize 60
:vertical resize 60
where the first will move the horizontal divider, while the second will move the vertical divider.

To quit all views at once, type in
:wqa
:qa!
where the first will save and exit all views, while the latter will quit all views without saving.

Lastly, for easy navigation between split views, append the following into ~/.vimrc file:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

You should now be able to navigate between split views with
<Ctrl> [h]
<Ctrl> [j]
<Ctrl> [k]
<Ctrl> [l]

No comments:

Post a Comment