From Sublime to vim. I'm Starting to Believe
Over the past couple years I’ve been trying to teach myself how to program. It’s not easy, but I’ve also found that my experience working my way through a file was subpar. Jumping lines, selecting and deleting lines of text. I used my mouse. It was slow. I cried a little inside.
1. Vimtutor
Fire up terminal, and type vimtutor
What you will see next is an “interactive” tutorial for all the goodness that vim provides. If you hate this already just type *:q! *(This will exit out the file) and start acting like terminal again. Follow the tutorial. Then do it again. Keep doing this until the majority of challenges start making sense. I found the best way to learn is by doing. Just keep practicing.
Basic Movement
You will need to learn how to use the h, j, k, l keys to move around the text file. This seems very strange, and I agree with you. I highly recommend keeping your hands on the normal home row position (j, k, l, ;), and simply using your pointer finger for the h and j keys. It feels much better (at least for me.)
Modes
There are three different modes in vim that I use:
- Normal Mode – As the name suggests, this is the default mode you will be using. In this mode, you will be jumping around to different parts of the file.
- **Visual Mode **– Essentially the same thing as normal mode, except all movement is highlighted. This is good for copying/cutting large amounts of code.
- Insert Mode – This is where you write code. I’ve found the easiest way to switch to this mode is by hitting the ‘a’ key. It begins insert mode after the current selection. If you want to just go to insert mode, simply type ‘i’.
How do I return to normal mode?
If you hit the escape key, it will return vim to normal mode. I can’t seem to reach this key easily, so I remapped the escape key to jk and jj (see this blog post for instructions – the “smash”.)
2. Plugins
There are tons of plugins out there for vim, so I spent quite a bit of time trying to find the most useful plugins that modeled my past behavior with Sublime.
- Rails.vim – I’m still trying to learn how to use this plugin. There’s plenty of different shortcuts available.
- Command-T – Similar to Cmd + P for Sublime text (easily one of my favorite features), this plugin does a great job of jumping between files based on particular keywords (for lack of a better word.)
- NERDTree – A nice looking directory structure plugin for vim. It’s easy to see the hierarchy of files and folders in your directory. It’s a nice plugin, but I find myself using Command-T more often.
- Vim Git Gutter – For those of you who use Git, this plugin is a great way to view a git diff in the editor of the gutter.
Lesson Learned
There’s a pretty extensive process of setting up your environment. This is pretty common for any editor one uses. It has taken me a few hours to research, setup, and learn. Overall, I feel more confortable jumping through code, yet I still have a long ways to go. I’ll be updating this post with more tips and goodies over the next few months.
update: I’m back to Sublime (where I work uses Sublime very heavily), yet using vintage mode. For those of you learning vim, I hope this helps!