Site icon Leonid Mamchenkov

Vim tips of the day

I’m using Vim text editor for more than decade now.  And I still can’t say I really know Vim.  I’m used to it and my fingers remember the commands.  And for those commands that I don’t remember, I’ve found some way of working around and got used to it too.  Today I came across not one, but two tips that I’m adding to my arsenal of Vim tricks.

Re-selecting visual block

Usually I only need to select the block once.  I then process it and never get back to it.  But sometimes, I need to select the same section of the text a few moments later.  Until today I was simply switching to visual selection and marking the block again.  Not too much of a problem, but it would be nice to have a shortcut for re-selecting the previous selection.  Of course, there is such a shortcut in Vim.  I just didn’t know it.  Simply type ‘gv‘ (without quotes) while in normal mode and your last visual selection will be selected again.

Increasing line limit on cross-file copying

There is no limit to number of lines copied between files, if all files are being edited in the same instance of Vim.  However if you copy a large selection from one file, then quit Vim, then open another file, and paste, you’ll probably see that only the first 50 lines or so were copied and the rest was lost.  Again this is not such a frequent scenario for me, and when it was happening I was simply opening both files in the same instance of Vim and copy all that I needed.  It turns out, I don’t really have to do that.

Vim uses ~/.viminfo file (default location) to remember things like command history, file marks, and registers between Vim instances.  There is a way to configure what and how much of what is going into this file.  If you are annoyed by any limits, you can easily raise them or totally remove them.  Have a look at “:help ‘viminfo’” manual page to see what is possible.   Adding “set viminfo=’100,<1000,s100” to ~/.vimrc file solved my problem.

 

P.S.: my messy Vim configuration files are available from GitHub, in case you wanted to take a pick at what else I have there.

Exit mobile version