Everything I Wish To Have When I Started Working With VIM

When you start with something new, a great thing is to find a source to get some hints and help you to learn faster. It is more important when you’re getting out your comfort zone. VIM is a huge tool and here I will show you some nice stuff that I wish to have when I started. Enjoy!

Matheus Marsiglio
7 min readJan 18, 2016

This post was originally posted on my personal blog.

When you decide to go to VIM, I assume that: you are not to play; or you don’t know what you’re getting into. But if you are here and want to continue, keep calm and get ready for some paragraphs.

Important notes

Just for the record, I came from Sublime Text Editor, already tried Atom and some others. When I started working with VIM, I had people in my team who already used it for years and I could get some help with it. I truly do not recommend you to drastically change on your job if you don’t have this same case than mine. Neither I did that. I worked with both at the same time. My productivity wasn’t the best at all, I used Sublime to work with mostly of the files and VIM to work just when I was working on one or two files, in small things. I managed pretty well this workflow like a sacrifice for the VIM, but it is not a formula. Maybe you prefer working with VIM from home and just when you really get used with it you start at your job. It’s your call.

Why VIM?

There are several reasons for people start using VIM. I never heard something like:“well, I learned on it. Was the first text editor I saw”; and I doubt that it is going to happen someday.

At first I just thought that could be cool to learn something new, but VIM is a highly configurable text editor that enables you to make it perfect for you, taking actions when you want, with everything under your control and it makes your configurations be easily changeable and manageable. Why not go deeply?

This is an image taken from VIM’s about website:

Same environment, any computers

After a while, you will have plugins, functions and set ups that you like to use and you will feel like you don’t have a leg without this plugin. On your configuration file of VIM (.vimrc — we will talk about it soon) you will have functions and helpers to your VIM works just like you want, your plugins will be saved as submodules and everything is working pretty well. And with that, you will be able to have the same environment in any computers with just a few commands.

A small step for the human kind, but big for you

If you are in a Unix Operational System (Linux, Mac), open your terminal and just type:

$ vimtutor

It’s your first first start. You really can’t keep going without checking the at least some vimtutor topics. You don’t need to expend too much time per lesson, but take a look will help you a lot. The vimtutor is a complete tutorial for who wants to start at VIM. You just need to dedicate a weekend on it (if want to take it really serious) and you will get ready with the basics. And yes… with… the… basics….

What is new here?

Okay, let’s assume that you already know about navigation keys (H J K L), saving (:w), quiting (:q), insert mode (i), visual mode (v), how to search (/), yankee (y), paste (p), delete line (dd), delete character under the cursor (x) and about to forget your mice existence.

If you don’t know what are these stuff, I have here two options to you:

  • 1 — The blue pill: if you choose this one, you can go back to your bed, sleep like an angel and wake up tomorrow without any memory of this and can keep using yournice text editor; or
  • 2 — The red pill: Go back and check out the vimtutor and you will be able to see “how far the rabbit whole goes”.

If you already know these stuff, I’m sorry dear friend, you already took the red pill.

What is the .vimrc file?

If you have some familiarity with command line, you probably know what is .bashrc. The .vimrc file is something really close to it, but to VIM. This file is used as optional settings that loads when VIM is started. You can find it on the user folder (~/). If you don’t find it there, just create it:

$ touch ~/.vimrc

As I said, VIM is a highly configurable text editor and these configurations are made inside this file. There are many possibilities and all of them are easily found on Google. You can try to find some stuff searching or just getting some .vimrc from someone and start reading it and understanding what is happening on that file. Here is a small example:

The DeleteTrialingWS function works cleaning white space on files, but it is just the function, you need ti give to it some action. On line 170 I made the action, saying that everytime those files are saved, the function will be called. You can make it work for all files, but I do not recommend because some files need the white spaces and it can be annoying when you do not need it. You can define the files you usually work or run the function using something called leader key, which I will explain soon. Let’s keep going.

IMPORTANT NOTE:

Forget about trying to decorate reserved words, you can search for .vimrc’s from everyone who works with it and normally you will get a pretty well documented code. There are many developers who has a GitHub repository called dotfiles or vimfiles (or anything like that) and you can check their functions and settings to get something useful to you. By the way, here is mine.

Leader keys

Ok, leader keys are one of the most exciting things on VIM. It’s like you are playing like a just nice super hero, but now you are Batman, with the toolbelt and Batmobile!

In theory, it is sequences of shortcuts defined by you to perform a command. If you are asking which one is, remember: “highly configurable text editor”. By default, it is used the backslash, but it can be the key that you want. You need to see which one you feel comfortable to use, there is no better key. I use the comma, I like its arrangement on the keyboard and that is it.

To configure your leader key:

let mapleader = ‘,’

SOME USES

An easy one: You can configure it to instead :w to save the file, you can use leader w. You type your leader key and after that the w key. And you wont need to type shift to press the :. It will make your savings better. Here is how you set this configuration:

nmap <leader>w :w!<cr>

Just put in your .vimrc and restart VIM.

Or type on VIM:

:so ~/.vimrc

It will reload your .vimrc file without exiting from your VIM.

A pro one: Did you know that VIM has spell checking for English? And you can get some on other languages on internet to help you with your texts. You may set a leader ss and make some magic:

map <leader>ss :setlocal spell!<cr>

More about how to use this here: http://vimdoc.sourceforge.net/htmldoc/spell.html

Leader keys configurations are a huge step for making your tools at VIM starting to work to you. Try some new and if you find something cool, share it with everyone. VIM users are always learning about VIM.

Color schemes

You probably already saw the ugly thing it is. And you are just about to go back to your old text editor, but wait a minute, take a breath and just see it: Vimcolors. VIM has a huge community and it is a good reason for having everything, like a lot of color schemes.

Ok, how do you use it? In your ‘~/’ path, must have a folder called ‘.vim’ (if you thought this dot-folder weird and don’t know about it, it is okay. It is just protected from listing and it’s common on unix like systems. Here is something with more details). Try to go to this path:

cd .vim

If the folder doesn’t exist, just create it and go to it. Now create a folder called ‘colors’. Inside this folders you can put color scheme files, which are named with .vim extension. You just need to choose one of the vimcolors.com, get the ‘colorschemename.vim’ file and call it inside your .vimrc file:

colorscheme monokai

It will automagically get the file called monokai.vim inside ‘~/.vim/colors/’. And if for some reason you want to change your colorscheme for any one inside the colors folder, just type from inside your VIM:

:colorscheme solarized

Now you have a configured VIM, with some colors and making some magics These were your baby steps. Some research and curiosity will make you a pro VIM user soon.

--

--

Matheus Marsiglio

I make code to solve problems you much probably don't even know you have. Software Developer. \n 4096R/3F04F86A: CCCD 8C99 3F04 F86A