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.
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
qh. Then whatever you type in vim (including commands) will be recorded. Press
qto stop recording. Now press
@hto 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,
run commands you can run commands right from within vim.
!lsruns the command ls in your terminal. You can do this for any command.
scrolling you can scroll inside vim with the keys
ctrl+y, no need to use the mouse
move to end/begin you can use the keys
$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
140Gto jump to line 140. You can also use
:140if 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.