What vimrc setting controls number of scroll lines - vim

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.

Related

Vim window resizing

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?

auto-scrollable pagination with vim using vertical split

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.

vim smart tabbing

In emacs, whenever tab is pressed, the cursor moves to the appropriate location on the current line. However, in vim, this does not happen, the tab is a given length and will go that far every time I press tab. Is there a way to enable "smart tabbing" in vim?
I'm not exactly sure what behavior you expect, but this is probably it.
:set smarttab
Also consider setting:
:set smartindent
:set autoindent
I assume your question is the following. You have text like:
This is line 1
$ (lots of white space) This is line 2
This is line 3
Now, you are in normal mode, your cursor is after $, and you would like it get just before T. If so, just press 'w' (to traverse a 'w'ord) and you would achieve your objective.
Perhaps you just want to use == to auto-indent the current line.

How to tab without losing block

I have been using vim for about 3 weeks now and have been having problem with tabs.
What I usually do is do gg to go to the top, do a ctrl+v for visual block, do a G to select everything to below(one column), do a $ to select to the right, then press < or > to tab.
However having to do all this, I lose the selection and I have to do all those commands to do another tab.
How do I not lose selection? Or is there a better way?
NOTE: I sometimes don't need to select everything sometimes just a portion of the file.
To reselect a visual selection use the gv command followed by your command. Although this is not the best way.
Instead select the whole buffer with ggVG then indent with >. This will indent the selection. To repeat the command again just press .. The . command will repeat the last normal command, in this case the > command. If you have indent a few times to many just use the undo command, u, as many times as necessary. This vimcast is a great screencast describing this technique and this one describe more indention techniques.
Others prefer the following mappings:
xnoremap <Tab> >gv
xnoremap <S-Tab> <gv
I am not sure what is important here: being able to do multiple indents in a single go or keeping the visual block. Assuming you want to do multiple indents, just prefix the > with a number, e.g. 3> will indent the selected block three times.
Also, you don't need to select the entire line to indent it (i.e. the $ is not needed).

Configure Macvim's text selection to not include character under cursor

Using macvim, when I copy a text selection, it always includes the character under the cursor.
For example, if the cursor is at the far left and I press shift-down arrow, it selects the entire line plus the first character of the next line (since the cursor is sitting over the next line's first character).
Is there a way to configure macvim to not include the cursor character in text selections?
Take a look at the selection option. By default it's set to inclusive, but you can change it to exclusive to make text selections act the way you want:
:set selection=exclusive
You can also set it to exclusive with the behave command:
:behave mswin
This also sets several other options, however, which may or may not be what you want. See the Vim help for the specifics.
:help :behave
:help 'selection'
I am guessing that shift-down arrow activates visual character mode, and moves the cursor down a line. If you are trying to select entire lines, you would be better off using visual line mode, which is activated from normal mode by pressing V (shift-v). This will select the current line in its entirety. You can then extend your selection to include the lines above and below using the k (or up arrow) and j (or down arrow) keys.
When using Vim, I think it is better to go with the grain rather than to fight against it. Don't expect it to work the same way as other text editors. Accept that the Vim way is different.

Resources