I've been using vim daily for almost a year now; it has been a wonderful (sometimes frustrating) experience. Today, a friend of mine was informing me about his interest in jumping into Vim. I thought I'd give him some advice from what I have learned over this period of time as a Vim beginner.
If you're reading this, I assume that you're already sold on Vim and determined to get into it. Compared to other editors, Vim is hard to learn and use properly. It's easy to fall into using Vim just like you do with conventional editors like Sublime, and this might lead you to miss all of Vim's power and slow down your work.
Here is a summary of the most important practices to adopt in order to improve your skills and reach the other side of the river.
Embrace the Vim mindset
Vim is tricky to learn and use properly compared to other common editors, and you shouldn't be using it like a common one. Since it provides a totally different experience, embracing Vim's principles is crucial in order for you to move forward.
- Understand and use Vim's modal editing system instead of doing everything while in insert mode
- Learn to move in Vim without using the arrow keys
- Understand command combinations and use them to speed up operations
- Learn to use Vim's search and replace features
- Leverage macros to save time and effort on repetitive patterns
Connect yourself with experienced users
Since there are different ways to do things, it is easy to adopt bad habits in Vim. One of the best ways to discover better practices is to connect with more experience Vim users. Watch them how they use the editor, ask them questions, pair program on Vim and let them help you out in improving your experience.
As a matter of fact, most of the tips in this post are direct advice from my good friend (and Vim ninja) Omar Abou Mrad, who helped me a lot in improving my skills.
You could also get some amazing help from the folks at #vim on Freenode.
Dropping the arrow keys
One of the important things to do early on, is to disable your arrow keys on all modes and not rely on them for navigation. This might sound like an odd start for beginners, but here is why I think you should:
The letter based navigation keys allow you to navigate the text without taking your hands away from standard typing configuration. This is more efficient and faster than moving your hand to hit the arrow keys every time you want to navigate text.
In normal mode, Vim provides numerous efficient shortcuts for moving around beyond HJKL, such as by space, words, paragraphs, line search etc...
You might say, "What about navigating in insert mode?" Well you shouldn't be moving around in insert mode, this mode is meant only for entering text.
So do yourself a favour and disable the arrow keys, by pasting this snippet into your vimrc:
noremap <Up> "" noremap! <Up> <Esc> noremap <Down> "" noremap! <Down> <Esc> noremap <Left> "" noremap! <Left> <Esc> noremap <Right> "" noremap! <Right> <Esc>
While it is crucial for a beginner to get rid of the arrow key habit, eventually you can configure and bind the arrow keys to serve other purposes that you might find useful to add.
Tabs is just another way to open files, and not your most efficient option
When I started using Vim, I came from a Sublime Text background. In the Sublime world, tabs are heavily used for opening and storing documents in the editor.
When using Vim at first, one might expect that tabs would behave just like all the other editors or browser out there. Unfortunately, that is not the case with Vim.
In Vim, tabs are not meant to be used as containers of documents and to navigate between them back and forth. Dealing with tabs on this premise will slow down your work.
Instead, you should be looking at how to work with buffers in order to load files and navigate between them. Here is an excellent article that highlights exactly this point and explains the use case of Tab, Window, and Buffer in Vim.
Practice is key
Speed in Vim depends a lot on muscle memory, and in order to develop that, you have to be using Vim constantly. The hard and preferred way is going into it head first and integrating it into your daily workflow as soon as you can.
Getting out of your Sublime comfort zone is painful in the beginning but you have to keep going through, and as you learn more, the experience starts to feel much more sweet.
When it comes to learning, one great resource to watch and learn about new Vim keys, tips and tricks is Vimcasts.
In addition to that, constantly practicing through exercises will give your learning experience a huge boost. One highly recommended training resource is Vim Golf, make sure you check it out.
Ignore pre-loaded packages and fancy extensions
It is very important to understand Vim on a raw level before jumping into installing packages, add-ons and extensions. Installing bundles of extensions and pre-made configs early on, will pollute your Vim experience and distract you from focusing on Vim's core features.
Try fighting the urge to replicate functionality in Vim that you're already used to in other editors. Vim is NOT these editors.
Slowly craft your own Vimrc
It is highly recommended that you craft your own .vimrc and know exactly what you're adding to it. Pasting large chunks of config code into it will eventually harm your Vim experience. In addition to that, understanding the basics of VimL will also help you know your Vimrc better and customise it as needed.
Keep an eye on repetitive patterns
Every time you find tedious editing tasks, look for a way to make them less tedious or repetitive. Always assume that there's a better way that can save you time.
Useful extensions to consider
Here is a list of recommended basic extensions, and that you might find useful to look into for your Vim journey:
Ctrlp: Hitting Ctrl+P will allow you to use fuzzy search to find your files
Snipmate: Allows storing snippets and using them on the fly in your files
That was a summary of what I have learned so far about Vim, hopefully its clear enough for beginners to checkout out and learn a thing or two from it.
Whether you are a beginner or an experienced Vim user, I would love to hear your feedback on this piece, make sure to share your thoughts in the comments below. Happy Vimming!↑ Back to top