When people in the development community hear the word vim, they generally think one of three things:
That nightmare program that I can never seem to exit, much less learn. mainly used by elitists.
A powerful and customizable text editor that is worth the steep learning curve.
The fact you are not using Emacs sickens me to my very core
Today we are going to look at vim, and see why when utilized correctly, it can be an essential tool in your toolbox.
Don’t get me wrong, emacs is cool, and I have colleagues who use it and love it. Emacs can certainly do many things that vim cannot, which is both a blessing and a curse. If you recall my first post, I refer to the Unix philosophy as a guiding principle to my workflow. Unfortunately, when used to it’s fullest capacity, emacs goes against that philosophy.
Emacs is a great operating system… All it needs is a good text editor.
This is a quip I hear often around developers, many who use emacs themselves. Like vim, emacs is quite extensible, taking advantage of a custom scripting language called Emacs-lisp, or elisp. The combination of elisp with a GUI emacs client has lead to a large ecosystem of user created applications and extensions that work right within emacs. Inherently, there is nothing wrong with this. Extensibility like this is part of makes vim great. However, at a certain point I have to question the scope of how a text editor should be used in one’s workflow,
On Milkypostman’s Emacs Lisp Package Archive or MELPA, one can browse over 4,000 emacs packages, from calendars to fully fledged multimedia systems. If you really set your mind to it, you could build an emacs that contains every tool you need in your workflow, and work without every having to leave emacs. As you can see, this is quite contrary to the unix philosophy of every program being very good at one thing.
I use separate programs to handle separate tasks, and I wouldn’t really use the apps available to emacs. Without these features, there is nothing that sets emacs apart over vim, besides more difficult keybinds. At that point they are both text editors and do that job well.
To answer the original question I posed in this section; I use vim because it is efficient, and it is universal. No matter the job, whether that be spinning up virtual machines or SSHing into remote servers to work, I can count on a vim-like program being installed. You may not have all your customizations, but that is quickly fixed by copying over your .vimrc file.
If you haven’t used vim before, I reccommend getting used to the commands. If you are running classic vim, you can run
vimtutor in your terminal, and you can work through these examples. If not, there are fun ways to get acquainted with the system.
Learning the language of vim commands allows you to surgically edit files at lightning speed, all without leaving the comfort of your terminal. In this post, I’ll go over some of the customizations that really take vim to the next level.
I use a fork of vim called neovim. Neovim adds a lot of much needed features to vim, and has even better support for extensions and customization. However, most of these tips should translate to legacy vim as well.
To see my full and up to date configuration, take a look at my init.vim file.
Changing some defaults
" Statusline Config: Show filename and leave room for extensions to show output set statusline+=%* set statusline+=%F set cmdheight=2 " Tab Settings: 1 tab = 4 spaces set expandtab set tabstop=4 set shiftwidth=4 " Misc set showmatch "shows matching braces/parens set formatoptions+=o set number set nocompatible filetype off set background=dark colorscheme wal set clipboard=unnamed " Relative line numbers augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * set relativenumber autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber augroup END " Show next 3 lines while scrolling. if !&scrolloff set scrolloff=3 endif " Show next 5 columns while side-scrolling. if !&sidescrolloff set sidescrolloff=5 endif
For a plugin manager, I chose Vundle. Most plugin managers for vim are similar in use, and instructions for popular ones can be found on the pages for most vim plugins.
To enable vundle, we add the following to our vim configuration:
set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' call vundle#end()
The third line of this excerpt declares Vundle, which itself is a plugin. However, we can follow this format and add any plugin using it’s github repo (username/repo). Here is a list of some of the must have plugins I use.
deoplete: Great autocompletion engine
ALE: All purpose linter. Highlights errors and warnings in most programming languages.
After you add the plugins you want to your config, open any vim buffer and run :PluginInstall, which will attempt to… Well, install your plugins.
Look in my init.vim to see all of the specific plugins I use and how I configure them.
This is only the tip of the iceberg. I am constantly discovering new plugins to enhance vim, all without leaving it’s scope as a text editor.