DEV Community

Cover image for How I Use Vim for Productivity and Efficiency
jones268
jones268

Posted on

How I Use Vim for Productivity and Efficiency

I use vim (a text editor) for my product development work, which is full of repetitive tasks. For example, I’m currently working on a project that has many, many files and many, many lines of code. In total, there are over 10,000 lines of code that I have to navigate through. It would take me forever if I didn’t have vim on my side.

I have used a variety of text editors in my career. I started with pico on my workstations, worked briefly with joe on Solaris and then moved to emacs and nano. When I moved to Linux as my primary operating system, I started using vim to edit text files. Then I learned about vim and how to use it and that is when I really fell in love with vim.

I am not going to go into all of the details about vim but if you are new to vim I recommend this tutorial.

Vim Tricks

I am just going to highlight some tricks that I have found useful.

So how exactly does a guy like me get used to typing commands left and right? It took some time and patience, but it was well worth it.

  • keyboard macros You can start recording your keys with ESC followed by qh. Then whatever you type in vim (including commands) will be recorded. Press ESC q to stop recording. Now press @h to replay your key strokes.

  • repeat action if you want to repeat an action, just type a number followed by the action. To delete 10 lines press 10dd. To press 50 lines type 50dd. You can do this for keyboard recording too, 50@h.

  • run commands you can run commands right from within vim. !ls runs the command ls in your terminal. You can do this for any command.

  • scrolling you can scroll inside vim with the keys ctrl+e and ctrl+y, no need to use the mouse

  • move to end/begin you can use the keys 0 and $ to move to the beginning and end of a line. No need to hold down the cursor key for several seconds.

  • jump to line press the keys 140G to jump to line 140. You can also use :140 if you prefer those keys.

  • set your .vimrc you should have a good .vimrc file in place so that you have all the settings ready to go. This means options for colours, font, tab settings etc. You can put this on git and pull whenever you access another computer. That way your settings stay in sync no matter what computer you use.

  • vim mode if you have to use an IDE for work, you can enable vim emulation. This works in visual studio, jetbrains IDEs and probably tons of others.

Top comments (0)