“Vim the nimble and dexterous.”
Editor, editor, editor… The neverending topic on the tool that is used the most by IT professionals. One of these is Vim, a three letter program that easily starts heated discussions by loyal fans when asked about their favourite text editor (especially if it gets compared to Emacs).
Vi as we know it today was created in 1979 and Vim came to light in 1991 as a superset of Vi, timeless gems that haven’t changed much in appearance. Most of the historical information can be found all over the internet with a simple search so I won’t go deep into historical details if at all, but this should set the tone for how powerful these are.
The purpose of this post is to showcase some good techniques to ease everyday tasks. As a fitting example, if you ever log in over ssh to a remote host or do some local development in the terminal, it’s good to know at least how to open and close Vi/Vim :)
Anyway, I find myself typing in Vim quite a lot and it’s quite easy to switch in and out while working in the terminal. Vim is supported on multiple platforms, even for Windows too, but I can’t promise the same magical flow as on GNU/Linux or MacOS which is mostly known for.
First and foremost in case you type vi or vim, how do you get out? One command that will efficiently exit Vi/Vim is :q! (quit without saving. Yes, press that key combination in the terminal). This is by far easier if you compare it to some other editors like the mighty Emacs!
There are four common modes in Vim: Normal, Insert, Visual and Command line.
Normal mode could be called presentation and starting mode, Insert is when you are able to type text, Visual for manipulating text (copy, paste, delete…) and Command line for using teminal-like commands (searching within the document or quitting).
So, here is a list of subjectively preferred Vim commands that won’t let you miss your mouse and might improve overall productivity:
|i||start typing text||insert|
|o||insert new line below the cursor||insert|
|O||insert new line above the cursor||insert|
|shift+v||select the whole line||visual|
|v||free text selection||visual|
|shift+g||go to the last line||normal|
|gg||go to the first line||normal|
|$||go to the end of the line||normal|
|0||go to the beginning of the line||normal|
|:set nu||display number lines||command line|
|/||search for a string||command line|
|:w||save document||command line|
|:q||exit vim||command line|
Also besides the arrow keys, you can use h, j, k and l keys to move the cursor around.
So, these should get you started. There are many more to explore if curiosity gets to you.
Next in line are some tips on giving your Vim instance some color and extra functions (note that when you ssh to a server, you load the host’s configuration and that’s usually the default version of vi/vim without any customizations).
A good plugin manager to start with is vim-plug. It’s also installable in one simple command:
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
As for the plugins, here are some to spice up the classic terminal look and feel:
A light and configurable statusline/tabline plugin for Vim.
The NERDTree is a file system explorer for the Vim editor. Using this plugin, users can visually browse complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.
emmet-vim is a vim plug-in which provides support for expanding abbreviations similar to emmet.
You can also checkout my Vim configuration for Vuejs development blazing-vue which contains additional improvements.
In the end as old as the editor is, it still gets security patches and has a vibrant community. Read more about here.
Other vim-like variations worth mentioning are Neovim and Spacemacs.