I'm donning my flame-proof suit for this post. Vim is arguably one of the two most popular text-editors used in the free software world: built on vi (its name stands for VIiMproved) it will be found as a default package in many GNU/Linux distributions. The other popular editor is EMACS (although I am sure there are those who will argue that EMACS is much more than a mere text-editor). I use Vim a lot in my work and have found it to be a little like chess: a moment to learn a lifetime to master. With that in mind here are some of the tips and handy commands I have picked up over the years. I thought I'd pass them on in case they help.
I'm going to assume you are familiar with the basics of Vim: moving the cursor, entering modes and adding/editing content. I'm also going to presume you know what entering a command that starts with a
: means. This is not a beginners class, but it's not an expert one either. This is not the place to begin learning Vim - sorry. Some of these were seemingly obvious to me, but unknown to other Vim users I've encountered. The rest are the reverse of that scenario. I've limited myself to ten, because honestly something like this go on forever without such a limit. These are not necessarily the best or most needed tips but they are the ones I found were best received by vim users when they first heard them (including me).
]}moves to the end of the current codeblock.
Ctrl+Iwill move forward in the list of locations.
Ctrl+Pdoes this by going forward through the list of words.
Ctrl+Ndoes it by going backwards.
.". Giving a number before it will repeat the command that many times.
:e, write to a different one with
:wor open one alongside the current one with
:vs. An annoyance to me was always that Vim's autocomplete when specifying file names is to give you the full path of the first file that matched rather than the way BASH does it, which is to stop on the first ambiguity and give you the choice of where to go next. Setting the wildmode option as shown will make Vim behave more like BASH in these instances.
Ctrl+Wand a cursor key to switch between the files.
There are times when you might use Vim to edit a non-coding file (no really, it's true).
Ctrl+Gwill display something like
Col 179 of 179; Line 23 of 24; Word 791 of 791; Byte 4312 of 4314at the bottom of the screen. If you select some text first (using
vfor example) you will be presented with the stats for the selection and not the whole file.
patternin the file
As said, this is not an exhaustive list and I appreciate this is a bit of a niche topic and I'm not expecting big reading figures here, but these kinds of tips are the ones you often rack your brain trying to remember so having them in a blog post will hopefully save your little grey cells the effort. One of the things about free software is the multiplicity of options available to you, and I am sure there are plenty who can think of "better" ways to do some if not all of this. If so, feel free to post them as comments here. If you want to read more tips on using Vim (at various levels of expertise) have a look at the Vim Tips Wiki. I'd expect most if not all of these tips to be on there (along with a myriad of others) but it's not where I got them from.