Some vim useful tips 🤓

Carlos P. Jimeno
3 min readNov 18, 2018

--

TL/TR

👋 My name is Carlos, I’ve been using vim for a year and coding for about two and a half and I want to share all the stuff I would have loved to know when I started to learn vim (and even a few months ago).

Keyboard hacks

  • Remap your caps lock to ctrl

In Vim I strongly use the ctrl key. Remapping caps lock to ctrl is pretty easy from the keyboard settings and you can’t imagine how confortable and quick is to use ctrl in the caps key 😍

  • Increase key repeat and decrease delay until repeat

Dummy tip but I can’t imagine myself using Vim without these two options settled to the max. Easy to change from the keyboard settings.

  • Change your keyboard to US qwerty keyboard

It may sound stupid, but, I’m from Spain and I never thought about my keyboard type until one day, trying to increase my typing speed, I found a game that was meant to use with the US qwerty. It was like a disclosure, every coding sign and especially Vim keys position makes sense. I strongly recommend to use it if you don’t.

Basic Vim configuration

Without any plugins you can still add some custom configuration that can make your life easier as a vim user.

This configuration should be added to your configuration file either vim.init as a neovim user or .vimrc as a vim user. Just add the following lines, save and type :so % to try it.

  • Ctrl + c as Esc

If you did remap caps to ctrl as I told before its super confortable and fast to emulate Esc (which you need all the time). Just add the following line to your vim config file.

  • Copy to clipboard: the easy way

Usually you should type "*y to copy the selection text to the clipboard, you can save a few weird strokes by adding the following and just press capital Y to copy (yank) the selected text(via visual mode).

  • Turn on and off highlight search matches

As you probably know you can search in a file by pressing / and typing something or by pressing * on a word. And navigate between matches by pressing n or N .

In vim there is no highlighting of the matching result so you should set it in your config file (in neovim comes by default)

But it can be annoying to have it highlighted all the time so you can add the following line to turn off the highlighting on press Enter.

  • Highlight cursor line

Useful to quickly find the cursor line

  • Highlight Column

Useful for coding styles

  • Move up and down in the file

We know that we can navigate between file lines by pressing any number and then gg , G to go to the file bottom, gg to go to the top and so on. But I found useful to show the row relative number to the cursor position because it makes easier to go to a specific line by pressing the showed number and j or k. to do it add the following

  • Moving around between panes

I use to work with some splitted panes and its super easy to move around with the following configuration by holdingctrl and pressing any of the basic vim movements keys h/j/k/l.

Note: If you use tmux you should read this awesome post, Its super useful to move between terminal panes the same as in you editor.

  • Basic indentation

If you, like me, want to keep indentations on wrapping lines and add just to spaces on tab press add the following

  • Avoid backups and extra files creation

Vim tends to create extra files that can be annoying to clean even more if you are working in a project with non vim users. To avoid them and prevent vim for using extra memory add

Append

Some other modules that I found interesting and I will write about it are:

Hope that you found something interesting that can help to increase your love for vim 🙃

🍻

--

--

Carlos P. Jimeno

Front End developer at @Influencity • Alunmi @ironhack • Crafting React Apps ⚛