3 easy Vim add-ons for first timers.

I like to use at least two editors: A full featured editor such as Atom, for most of my everyday coding needs (when I’m not in a Jupyter Notebook), and a second lightweight editor that I can use to make fast edits. For my lightweight editor, I use Vim. Vim is a command line based code editor, depending on how deep you dive into Vim, it is either a lightweight editor for small edits or a full featured code editor with the ability to drastically increase your productivity. In this article I’m going to go through a few add-on’s and modifications that I use to improve my Vim experience.

Some of you may be familiar with a .bashrc file. The vimrc file works in a similar manner, you can use it to add functionality and change your vim preferences. You can navigate to the file by simply typing:

vim ~/.vimrc

If the file is not found, that might mean that you do not have Vim installed on your computer (it usually comes pre-installed on many computers). If you need to download Vim, please follow these instructions based on your operating system.

The most useful modification i’ve made to my Vim config was to map the F9 key to run the current script I’m working on. To do this, just open your ~/.vimrc and paste the following code towards the top of the file.

autocmd FileType python map <buffer> <F9> :w<CR>:exec '!python3' shellescape(@%, 1)<CR>

Now, you can create a new .py file, write some code, and hit F9. Your code will now run! If you want to get back to the editor you can hit Escape.

If you have never messed around with your vimrc before, then you have a clean slate configuration. This can make Vim seem like a tedious option when it comes to editing code. One area where this is apparent is with spaces. By default, Vim spacing will not act like you will expect, and you will spend a lot of time hitting the space bar and tab key to keep your cursor where you want it to be. To make things a little more intuitive, i’ve set some spacing options:

set expandtab           " enter spaces when tab is pressed
set textwidth=120 " break lines when line length increases
set tabstop=4 " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4 " number of spaces to use for auto indent
set autoindent " copy indent from current line when starting a new line
set smartindent
set smarttab
set expandtab
set number

" make backspaces more powerful
set backspace=indent,eol,start

set ruler " show line and column number
set showcmd " show (partial) command in status line

Copy and paste these options into your Vimrc to add intuitive spacing options, line numbers, and a command status line.

I am a big fan of syntax highlighting. It just makes code easier to read and scan through. Turning on Syntax highlighting is easy in Vim, all you have to do is add the following command to your vimrc file.

syntax on

What I’ve described above are 3 very simple modifications that you can make to your vimrc in order to make Vim a more enjoyable “quick and dirty” code editor. There is a LOT to learn if you want to become an efficient user of Vim. You can find a list of Vim commands here, if you learn these you will drastically increase your efficiency using the program. Also there are many vim add on’s such as NERDTree and powerline, which I also suggest you download and add to your personal vim configuration!

Happy Coding!

Check out my website 💻!

Turning over rocks and seeing what crawls out.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store