Posted on in vim
In this post, I’ll just list some things I love about Vim. This post is not intended to teach you how to use Vim, I won’t deeply explain the commands I use, I just want you to see how easy things can be with Vim.
Something I love about Vim is that it allows you to repeat commands. And I don’t mean macros, I’m talking about the power of the
. operator, which repeats the last thing you made. It’s one of my favourite commands as it gives you quite a lot of power. A very common use case is changing the name of a variable in a file:
What I did was simply step on the word I want to change, press
* to search for the next occurrence. Once I’m on it, I simply change it to something else, the Vim way to do it is
cw<Type text here><ESC>. Now comes the fun part, Using
n. I search for the next word, and repeat my last action, which was change it’s name, running
n. again gets the job done. The complete command list used is
Another common use for this is spacing and formatting lines, for example, if we wanted to space all
+ signs in this statement, we can get away with repeating commands again.
The full command here is
f+s + <ESC>;.;.;., nothing too different, only that instead of using
* we actually use a motion to move to the plus sign using
f+, because of this, the next command changes and instead of using
n we use
Normally I limit my lines to 80 columns. So I have
textwidth set to 80 in my
.vimrc file. With this I can use
gq to format a selection to 80 columns.
You can of course always format code using
=, even though sometimes it breaks… Note the usage of
% which matches the closing tag of an element, which is extremely handy, especially in visual line mode and HTML.
The full command list used there is
Vl%=, that’s it.
Visual block mode
Vim has several selection modes, most of the time I use line mode but this one is super handy and works similarly to Sublime’s multiple cursors.
Visual block mode is accessed though
<Ctrl-V> in Vim, but it also works with
<Ctrl-Q> which I prefer.
Sorting CSS lines
Sorting is as easy as selecting the lines and using the
That’s just the tip of the iceberg
Everything I’ve showed requires no plugins, is just plain old Vim. If you want to try it out, I recommend Practical Vim, it’s a really good book, only with reading the first few chapters you can already get a taste of Vim’s power!