I want to achieve the following: I want to split a vim session into two (or more) vertical windows (with the :vsplit command). Then, I want to have each window contents vertically offsetted so that the line after the last visible one of the first window becomes the first line of the second window. Then, when I use the arrows to scroll around, the vertical windows are scrollbound so that text flows from the second window into the first. How can I achieve this?
There are plugins for that: MultiPage
You can also use a oneliner described in this post by Chip Campbell:
:nmap <silent> <Leader>ef :vsplit<bar>wincmd l<bar>exe "norm! Ljz<c-v><cr>"<cr>:set scb<cr>:wincmd h<cr> :set scb<cr>
This will bind <Leader>ef to open a vsplit and make the splits continuous.
First, split your window normally and position it according to your needs (last line in one, first line in the other).
Now, run :set scrollbind in the first window. Jump to the second one and do the same, you can also use :set scb for short.
That's it!
And be sure to read :h scroll-binding.
Related
Whenever I create a vertical split in VIM using the :vs command, the newly created panel is a duplicate of the first, and it updates both panels in real-time as I type.
How can I turn this behaviour off and make it revert to opening a second independent panel?
That's exactly what's supposed to happen. If you don't want what a command does, use another command that does what you want.
From :help :vsplit:
Like :split, but split vertically.
From :help :split:
Split current window in two. The result is two viewports on the same file.
If you scroll down a bit you can find :help :vnew:
Like :new, but split vertically.
Which leads you to :help :new:
Create a new window and start editing an empty file in it.
So… what you want is :vnew.
When using Ctrl-E and Ctrl-Y in vim, I would like it to scroll multiple lines instead of one at a time. How would I set up my vimrc to specify the number of lines for just these 2 commands?
You can override the default bindings with counted versions.
noremap <C-e> 2<C-e>
noremap <C-y> 2<C-y>
Use noremap to avoid recursion.
You don't need to do any particular setup. Instead, you can just scroll one page at a time using CTRL+F (forward) or CTRL+B (backwards) as an alternative solution.
This is not exactly what you want, but I hope it helps.
Regarding Ctrl+E and Ctrl+Y, I'm afraid that the only way may be to precede the command with a line count. So, if you want to scroll down five lines, you press 5, then Ctrl+E.
But you can, by default, use Ctrl+D to scroll half a page downwards, and Ctrl+U to scroll half a page upwards, and you can also set how many lines you want to go up or down with the scroll variable.
So, in your .vimrc, add the line set scroll=N, where N is the number of lines you want to scroll with the Ctrl+D and Ctrl+U commands.
I split my windows in Vim horizontally. But after I split, the new window occupies half of the original window size, I want to change this and make sure the new window occupies almost the entire old window.
Basically if I open three files using horizontal split in Vim, I should see three status bars at the bottom of the screen the third file occupying the rest of the screen. The files as I already know can be navigated through Ctrl+W+arrow keys. So if I navigate to second file now, I should see one status bar at the bottom and one status bar at the top.
Kindly let me know how to configure the same. I looked up online all I could find is options to dynamically change the size or resize, but I want static one-time config (for example, in vimrc or bashrc).
If you set the winheight option to 999, the current window occupies as much of the screen as possible, and all other windows occupy only one line (I have seen this called "Rolodex mode"):
set winheight=999
You can type in command mode :res[ize] +N or :res[ize] -N where N is the amount in which your window will grow or shrink respectively.
Go to point 6 (Window resizing) http://vimdoc.sourceforge.net/htmldoc/windows.html but the article has everything on windows management in VIM
Hope this helps!
You might prefer just using vim tabs, which work rather like how you described.
Try this:
vim -p file1 file2 file3
Then use :tabn and :tabp to cycle fwd and back through the tabs.
I also like this mapping in .vimrc to use ctrl-l and ctrl-h to cycle fwd and back respectively:
noremap <C-h> :tabp<CR>
noremap <C-l> :tabn<CR>
Command for split window:
:[N]sp[lit] [++opt] [+cmd]
Where N is height of new window. Default is to use for half the height current window. Same thing for vertcal splitting:
:[N]vsp[lit] [++opt] [+cmd]
N is width for split window.
And so on:
[N]new, [N]vnew
For details read the
:help split
But I can't understand why you do not use buffers?
Say I want to run the key combo <C-e> five times from a Vim script. Is that possible? If so, how is it done?
Specifically, I need this because I want to map a key to nudge the viewport one fourth of the screen height in a direction. For that I need to combine the function winheight(".") with the key combo <C-e> somehow.
Note: I know I can change the option 'scroll' to set the number of lines <C-u> and <C-d> scroll, but that key combo also moves the cursor. Additionally, I don't know how to set the 'scroll' option to scroll a portion of the window height, except that it scrolls half the window height when I set it to 0.
For simple commands, :norm[al][!] is sufficient. For example, to yank a line:
norm! yy
For special characters, use :exe[cute] "norm[al][!]". For example, to do 5<C-e>:
exe "norm! 5\<C-e>"
With exe, other code can be inserted by using multiple arguments:
exe "norm!" winheight(".")/4 "\<C-e>"
However, arguments are joined with spaces, which are then interpreted literally. To avoid this, use . to join arguments. Thus, for the desired effect:
exe "norm!" winheight(".")/4 . "\<C-e>"
See :help norm and :help exe for more information.
Suppose I have opened two different files in two vertical screens in vim. Is a there a single command to move the line under cursor to other screen?
Not to my knowledge. Delete it, switch panes and paste it.
dd<ctrl>ww</ctrl>p
Of course if this is something you do regularly you can write a macro for it, just like for any other sequence of commands in vim. For example to map CtrlX to this function, you could run this in your buffer or set it in your ~/.vimrc file:
:map <C-x> dd<C-w><C-w>p<C-w><C-w>
If you want to do this on a regular basis, just map it to a keystroke. e.g.
map <C-A> dd<C-W><C-W>P<C-W><C-W>