KAJAN M

Oh my Vim!

January 04, 2021

productivityvim
I have recently started using Vim for full time in my work(inside my IDE). Initially it was bit hard, I had to consciously decide whether to…

I have recently started using Vim for full time in my work(inside my IDE). Initially it was bit hard, I had to consciously decide whether to press h, j, k or l. I tend to touch the mouse often, but now, after some practice, I feel very productive. I’m not a pro, but I’m documenting some of my thoughts, experience hoping it’ll help someone.

Table of Contents


What made me to learn Vim


The first time I heard about Vim, I didn’t bother to learn it. My to-learn list was already filled with higher priority items. Recently I came across a screencast where Kent C. Dodds did some magical stuff, and then suddenly Vim became my the highest priority to-learn item.

Is Vim a must-know tool


If you’re into DevOps or SRE(Site Reliability Engineering) then knowing Vim will help you a lot, almost all Linux flavors have Vi/Vim baked in it.

If you’re an application developer, learning Vim is not mandatory. It’s just a syntatic sugar, most of the stuffs you can handle through your IDE keybindings and other plugins. However, learning Vim boosts the productivity and pays off in time.

Some senior developers will not accept you as a true developer if you don’t know Vim 😅.

When is the correct time for me to learn Vim


If you are pretty comfortable with your main technology stack, already know your IDE keybinding to surround a code block or already using acejump, then you might want to give Vim a try.

If you don’t have at least a year of coding experience, and you’re in a doubt whether you should learn Vim, you might want to visit this topic sometimes later.

Can I use Vim inside my IDE along with the usual shortcuts


Yes!

If you like your IDE very much, not to worry, you don’t need to move away from your IDE. You don’t need to unlearn your favorite shortcuts as well. You can use Vim within your IDE, and get the best of both worlds. I’m also currently using Vim within my IDE.

I heavily use JetBrains products, JetBrains has ideavim plugin. VS Code, Atom also have similar plugin. Some IDE shortcuts will conflict with Vim. In that case, we need to configure our IDE Vim plugin to pick either the IDE/Vim action. I’ll write another post to set up Vim in JetBrains, VS Code.

IDE fans, hold on please


While using Vim inside IDE is cool, you might want to practice in the Vim editor first! IDE plugins have some limitations. Also, some IDE shortcuts might conflict with Vim. Using Vim editor will make the learning experience smooth.

Can Vim do that?


Most of the time the answer is yes. However, Vim is not an IDE, while we can add Vim plugins and make it more powerful, I don’t think it’s a replacement for IDE. Things get interesting when we use Vim within our IDE.

What about the learning curve


There’s a lot to learn in Vim. People say this is the case even after years of experience 🤷‍♂️.

Learning Vim is a process, we need to train our muscle memory through practice, it’ll take some time, and don’t expect to get immediate results.

As I remember, in my first two weeks I felt less productive. I had to spend some time practicing Vim in personal projects before using in my office work.

Having said that, don’t let this fact stop you from acquiring a valuable skill.

Don’t know how to add multiple cursors, no problem, note it down, google it, practice a few times, you will begin to love Vim.

Mapping Caps Lock to Esc


As we use Vim, we’ll soon realize that we frequently press Esc to switch to command mode.

Since Esc key is quite away from our hand it’s a good idea to map Esc action to Caps Lock which we don’t frequently use.

In Windows, we can use SharpKeys.

My .vimrc


let mapleader=","
let g:EasyMotion_smartcase=1
nmap s <Plug>(easymotion-s)
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
set hls is ic surround easymotion
set clipboard+=unnamed
set keep-english-in-normal-and-restore-in-insert

Plugins that I use


  1. easymotion
  2. surround.vim

Mostly used commands


  1. ^ - move to the first non-blank character in the line
  2. $ - move to the last character in the line
  3. [N]f[char] - move to the Nth occurrence of [char] to the right
  4. [N]F[char] - move to the Nth occurrence of [char] to the left
  5. [N]; - repeat the last "f", "F" action N times
  6. [N]. - repeat the last "f", "F" action N times in opposite direction
  7. :[N] - go to the first non blank character on line number N
  8. /[text-to-search] - forward search
  9. ?[text-to-search] - backward search
  10. n - repeat last search
  11. N - repeat last search in reversed direction
  12. w - move to the beginning of next word
  13. e - move to the end of word
  14. G - move to the end of the file
  15. gg - move to the beginning of the file
  16. * - move to the next occurrence
  17. # - move to the previous occurrence
  18. diw - delete word
  19. dd - delete line
  20. yiw - copy word
  21. p - paste
  22. P - paste before the cursor
  23. ciw - change word
  24. ctrl + v - select block
  25. [N][h/j/k/l] - left/down/up/right by N characters

Kajan
👋 Hi! Welcome to my blog. I'm Kajan, a Software Engineer focusing on ASP.NET Core, EF Core and JavaScript(Vue, React) stack. I am thankful to the internet community for helping me out on various occasions 🙏😘. I hope to give back to the community by sharing my experience, and knowledge.
Twitter
GitHub