So after picking up Vim less than a year ago, and spending a lot of time with it, I can say for sure it is the best text editor I have ever used.
Okay, that’s all the Vim propaganda you’ll find in this post.
The main aim of this post is to get people new to Vim into a comfortable environment, while also teaching you how to get plugins into your vim config since you’ll probably want to customize it, once you get a feel of Vim.
I’ll be assuming you are working on a GNU/Linux operating system. It is probably already installed, just type
vim in a terminal to check. Install it using your chosen package manager if you haven’t got it.
The Ultimate Vimrc
The title of this post isn’t a boast on the comprehensiveness of this guide; this is actually supposed to be a guide on getting the ‘Ultimate Vimrc’ from GitHub, and customizing it. So not technically clickbait.
Head to the github page if you want to read about it, otherwise just follow these instructions:
- Open up a terminal.
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
That’s it, now you’ve got a pretty decent vim config, enter
vim in the terminal to have a look. The vimrc we just installed comes with a nice selection of plugins, see this, but you’ll likely want to add your own eventually.
If you want to update the vimrc to get any changes from github, just run these two commands:
git pull --rebase
You don’t need to do this very often, maybe once a month.
Adding plugins, with pathogen
Find a plugin you like on github, we’ll use vimtex for demonstration (which happens to be the first plugin I wanted to install for vim, when I realised I didn’t know how to, with the ultimate vimrc - leading me to write this guide).
cd ~/.vim_runtime/my_plugins(the ultimate vimrc creates a directory for you to add any plugins)
git clone https://github.com/lervag/vimtex.git(replace the https link with the github source code for your plugin)
That’s it, you’ve installed the plugin! Now the ultimate vimrc will do the rest.
To give it a test, open up vim and enter
:h Vimtex, replacing Vimtex with the plugin you added. It should open up the docs for your plugin, although it is possible that your plugin might not come with docs.
Edit: if vimtex doesn’t work properly, double-check that you have actually installed latex first.
You might want to set some additional variables or settings to your vimrc.
Let’s add hybrid/relative numbers, have a look at this blog post to compare the differences between line number types. In any case, you’d want to add some kind of line numbers; my config did not have line numbers on by default.
vim ~/.vimrc(begin editing your vimrc)
- Add a line to the bottom:
set number relativenumber(it’s best to add it to the bottom of the config file so it overwrites any settings made in the pre-installed config files)
- Write and quit vim. (
Open up vim and have a look at your new line numbers.
I chose to simply add it to the .vimrc file in the home directory, instead of one of the vimrcs in the vim_runtime, since it keeps all of your custom configs separate from the preconfigured vimrc you installed.