Switching to VIM - the first month
About a month ago, I decided that I would try and switch to Vim as my only editor. I’ve been a pretty hard core Textmate for about 5 years now, and haven’t really had any issues. So why bother switching? My first reason is I spend a ton of time in SSH + terminals. Due to working with many headless virtual machines and computers in far-away lands, I’m in a terminal quite often. There is no Textmate in a terminal, so I used vim. Having to remember two sets of keyboard commands to do the same thing started to bug me. I’ve also seen people work pretty damn fast in vim if they knew what they were doing. Being able to get faster at something I do all day grabbed my interest as well.
Installing vim
While vim is already installed in most non-windows computers, I also installed MacVim mostly so I could get some normal OSX bindings, and ease myself into vim. MacVim also supports more colours than terminal vim which is nice. I heard one of the keys to using vim is to get a good .vimrc
file. So after installing MacVim, I installed Janus. While Janus is a bit ruby focused, it comes with a number of great plugins all bundled together, so Vim noobs like me can figure things out. I’ve since forked Janus into my github account , which I use to keep my vim config in sync across my various computers. I’ve added a few more python and PHP specific plugins, as that is what I spend most of my time working with.
Vim essentials
I started off learning vim using vimtutor
. It covers most of the essentials, such as vim’s modes, movement commands and how to make changes to text. The most helpful things I found to try and master at the beginning were modes, and movement. Getting into and out of the various modes is critical to getting work done. Learning the various movement commands, helps you more efficiently get around in your files, and is a big part of vim’s power. Knowing the movement commands, also plays nicely with most other commands, making them more powerful as well. The next topic, I spent time learning was buffers, windows and registers. These features really exposed the power vim has, and got me hooked on using vim. Having more than one clipboard, and split windows, are pretty powerful features, and ones I found lacking in textmate. Of course the most important and useful command of them all is :help
. This lets you peruse the extensive built-in help, which has been more helpful than any other editor’s help.
Navigating your code
Getting around a big code base is really important to me, as I work on a few fairly large code bases. I routinely use Ack.vim to quickly grep through code. Command-T is also really helpful here as well. I also use vim’s ctags support as well. Once you’ve generated a tags
file with exuberant tags you can use CTRL-]
to navigate to function definitions, and CTRL-T
to go back to where you were. Vim also has fantastic searching, and /
, ?
, #
and *
are your friends.
Useful plugins
Janus includes a pile of plugin, most of which I don’t think I’ve used. There are a few I use everyday, all day though. I pretty much always have NERDTree open. It allows you to easily explore a project, and open files in split windows or tabs. I also use command-t all day. I loved the equivalent command in TextMate, and being able to use it in vim is awesome. I also find ZoomWin pretty handy. There are a few more great plugins I use, but those stand out to me.
Challenges remaining
Since I’ve only just started using vim, there are a few things I did quite easily with TextMate, but are a bit more challenging in vim – at least how I’m doing things. Hopefully, I’m doing them wrong and there is an easier way.
- Creating new files. Currently I use
:!touch /path/to/file.ext
to create new files. It feels kind of clunky and I hope there is a nice way to do this. - Renaming files. Currently I use
:!mv
to do this, again it feels a bit clunky. - Remembering all the commands. Vim has a mountain of commands to remember, and it can be extremely daunting to remember them all.
Overall, I’ve found the transition to vim pretty reasonable. Starting off with a solid base of plugins, really made the move much easier. I’m glad I gave myself some time to learn how to use vim before I committed to it. Having that extra time reduced my frustration, as I moved from a tool I had used for 5 years, to something brand new. A month later, I feel pretty comfortable with vim, and have only opened another editor to do esoteric things like re-format minified javascript. And my goal of only having to use one editor all the time no matter where I was worked out. Thanks to the magic of github, I can get vim configured on any computer I use in about 3 minutes, which is really nice, and not really possible with most other tools.
Mark
to create a new file :
:w /path/to/file.ext
franck on 5/14/11
For instantly editing a new blank file I like:
:e path/to/file
Jamie Mill on 5/14/11
FuzzyFinder is a very nice plugin that has directory switch, files finder very nice, and buffer and tag finder that works with TagList it’s quite nice
Bogdan on 5/14/11
You can use NerdTree to create files. Just navigate into the directory and press “m” for menu and “a” for add. Then enter a filename.
Reen on 5/15/11
Have you ever used Coda? I use Coda all day, every day and was curious if you ever looked at
it.
Thanks
Lance on 5/15/11
Congrats for using Vim!
Hope your next post will be “Switching to Linux — the first month” ;-)
LJD on 5/15/11
Thanks for another great article. I didn’t know about Janus & will definitely check out your fork.
For syncing configs (git, vim, etc) I use dropbox:
http://kevin.vanzonneveld.net/techblog/article/sync_vim_accross_workplaces/
works instantly :)
Kevin van Zonneveld on 5/16/11
franck, Jamie, Bogdan: I knew there had to be a better way to do that.
Reen: Awesome, I’ll be using that quite often. :)
Lance: I did briefly, but it has the same problems as TextMate for me. It doesn’t work on the various computers I have to work with. But coda is a great editor.
Kevin: I started off using Dropbox for my vimrc, but I found installing all the plugins to be a pain. Using Janus solved that for me.
mark story on 5/16/11
Hi Mark,
I am almost in the same situation as you. I usually have to work on remote servers, all running Debian.
So, does this Janus also works in Linux?
Nice article, by the way!
Renan Gonçalves on 5/17/11
Hi Mark,
I am a vim user for 2 years i guess. Still cant memorise the basic commands. To make your life easy goto
http://github.com/akitaonrails/vimfiles
this all the textmate like features u want to use.
t will help u alot … try this surely u wont be disappointed :)
Rajib on 5/20/11
:!mv in fact seems to be the canonical way to rename a file (in plain command-line mode. The built-in netrw browser (:Explore) has R for this, NERDTree probably some similar)
Just in case – do you know this wonderful compilation:
http://www.rayninfo.co.uk/vimtips.html
And many, many thanks for all your CakePHP work! Wish you a lot of fun with the Vim – you certainly deserve it ;-)
Stefan on 5/27/11
P.S. / Remembering commands:
while aforementioned Best of Vim Tips is full of fun, but rather LARGE, imho this VIM QUICK REFERENCE CARD is a nice compilation of basic commands:
http://tnerual.eriogerg.free.fr/vimqrc.html
Stefan on 5/27/11
I don’t know if it’s cheating or not, but I guess I lean on profile settings in .bashrc, .vimrc, and so forth pretty heavily. Well, just today I discovered that Eclipse’s Remote System Monitor group of views are actually amazingly easy to deal with – at least, for me. I was able to shell into both my dev and my production boxes with absolutely 0 muss / fuss / bother, and open terminals on both. Silly as it may sound to pop open something like Vi in an IDE like Eclipse, the ability to tinker with config settings, scripts and the metric ton of stuff that’s not checked out into my workspace? Made of win.
PS. CakePHP 2.0 Stable – codename: Made of Win. And, I follow this blog like a puppy. That is all.
satyrwilder on 6/3/11
Hey Mark,
Are you using Fugitive for working with Git? It’s a little hard to get used to buts it’s fantastic!
Inside of a file that is under git source control, type :Gstatus and it will bring up a split window with the output of the git status command. The magic starts when you move down to a file in the git status. You can type – (hyphen) and it will interactively add that file to the staging area (or unstage if it’s already staged).
Then you can do :Gcommit to write a commit message in a split window.
You can also do :Gdiff and it will create a vertical split window of the file showing you the diff. Which you can then edit in real time and have both panes change so as you add to the file the diff is showing you the additions.
I highly recommend it (it comes with Janus I believe). I highly recommend any plugin written by Tim Pope.
Brandon Cordell on 6/15/11
One more thing.
When you want to search in the file for a string you can do a
:/string_to_search
It annoyingly highlights all instances of that string, but you can just hit Esc to get rid of the highlights. You have to type
:nohl.
Brandon Cordell on 6/15/11
Brandon Cordell: I am using fugitive, its pretty fantastic as are most of Tim Pope’s plugins.
mark story on 6/21/11
Hey Mark,
I do allot of terminal work myself, have only tried vim in passing but seems like a few enthusiast’s based on all the comments.
Generally use emacs or jed as its called on some Linux platforms, most platforms have a version of it, even mac not that I’ve tried it yet.
I have just moved over to the mac world but use VM’s extensively like yourself. Would love to hear some other useful tools you use in both the mac and linux world. I use putty many times a day still, have you found a good replacement for the mac side i.e. login profile storing ?
Regards,Brett
Brett Wilton on 9/6/11
Hey. I have a lot of advice!
Firstly, use pathogen for plugins. It makes them simple, compact, and easy. A lot of vim plugins are on github in pathogen-compatible form (clone, and you’re done. It’s really that simple).
https://github.com/tpope/vim-pathogen
video on installing pathogen and another plugin:
http://www.youtube.com/watch?v=ptsjhRTb19s
tpope, as other people have mentioned, also makes a shitload of awesome vim plugins on github, check them out as well.
Secondly, these tutorial videos are AWESOME. Simply second to none.
http://www.derekwyatt.org/vim/vim-tutorial-videos/
Thirdly, (a bit subjective) ALWAYS make sure you know what all the instructions in your .vimrc do. It makes you much more knowledgeable of vim. I have constructed mine myself and thoroughly commented everything. I don’t think using another person’s distribution is a good idea, unless you know you understand everything it’s doing.
Fourthly, syncing with dropbox IS easy: make a folder in it called ‘vim’ or whatever, and place your .vimrc and .vim folders in it. Then just symlink those two things to ~. Done.
Fifthly, this is much more my personal opinion, I don’t think it’s useful to use plugins which try to get vim to ‘emulate’ other things. It’s modus operandi is really quite alien to almost everything else (any other editor, or OS), and this modus operandi is the reason it is fast. Converting it to other methods of operation just makes you not as fast as you could be doing it natively in vim.
By example, I don’t agree with MacVim helping out with shortcuts for the mac (apart from mayyybe global copy and paste…) [but also MacVim is vim’s main distribution on the mac, so can’t be helped to an extent], I don’t agree with a plugin trying to emulate Textmate (although there are a few, including in the video I linked, that do snippets), and also I much prefer to extend vim’s functionality, rather than modify it.
Last tip: always work with one vim instance. you can do this by having an alias to ‘ —remote-silent’ to start editing. You can pass that as many files as you want.
Ivo on 9/14/11
Thanks for all the tips Ivo. I’m thinking of giving Pathogen a try. I agree with knowing what all the various parts of of your vim config files do. I found Janus to be great for a beginner as you can get started easily, and dig into the details as you learn more.
mark story on 9/17/11
Hey Mark, have you tried SublimeText?
http://www.sublimetext.com/danfreak on 11/4/11