Top 10 Pitfalls When Switching to Vim

Top 10 Pitfalls When Switching to Vim

Admit it: every time you see a person using Vim, you consider the possibility that they know something you don’t. Why else would they be using an editor that, in your mind, is dated, open-source junk? Think what you wish, but there’s a reason why top developers swear by Vim.

Republished Tutorial

Every few weeks, we revisit some of our reader's favorite posts from throughout the history of the site. This tutorial was first published in February 2011.

Until you’ve spent at least a month working every day with the editor, you’ll undoubtedly hate it! This is specifically why the majority of newcomers will play around with Vim for a day, become disgusted, and never touch it again. What’s unfortunate is that, if these developers could get beyond the pitfalls, they’d be introduced to incredible speed and flexibility.


1. There’s Too Many Modes

It’s true: Vim is not your standard code editor (it’s better). Transitioning from, say, TextMate to Vim is going to be an entirely different process than switching from TextMate to Espresso. Always keep that in mind when you find yourself tearing our your hair because Vim seemingly refuses to enter text when you type.

Though there are multiple modes in Vim, we’ll focus on the three most important. But before we continue, note that each key serves a different function, dependent upon which mode you’re currently in. Even more confusing — at first — a capital letter triggers a different action than a lowercase.

In command mode, pressing the lowercase “i” will trigger “Insert Mode.” However, an uppercase “I” will move the cursor to the beginning of the line. This might sound confusing, but it provides you will incredible power!

  • Command: By default, Vim should rest in command mode. Think of this mode as the “getting around” mode. While, in a traditional editor, you might be accustomed to using the mouse or the arrow keys to traverse your document, Vim’s command mode makes the process quicker and “mouse-less.”
  • Insert: Pressing the lowercase “i” in command mode will switch you into “Insert Mode.” Newcomers to Vim will find this mode to be familiar. As a result, though, they often remain in this mode far longer than they should (I know I did). As a rule of thumb, insert mode should purely be used for the sole purpose of inserting text. When finished, immediately return to command mode.
  • Visual: Think of visual mode as “selection” mode. Need to select the next five lines and delete them? With a normal code editor, you could use the mouse to visually select five lines, and then press the backspace key. With Vim, on the other hand, you’d press capital V to switch to Visual mode, and then type 5j to select five lines down. Finally, you’d press d, for delete.

I know this sounds incredibly confusing at first. You might think to yourself, “All that work just to delete five lines?” The truth is, though, this method is significantly faster.


2. Ancient Editor

Why would you turn your nose up at over three decades of development?

You might hear your friends say, “Isn’t Vim an ancient code editor?” Well, you could say that; it’s been around for over thirty years. Though honestly, why would you turn your nose up at over three decades of development? That’s longer than I’ve been alive! Better yet, even to this day, Vim is under active development. The most recent release, 7.3, was made available in August, 2010.

Secondly, it’s important to keep in mind that Vim is not Vi. If your only experience is with the latter, take some time to download the latest release and toy around with the new features. You’ll be pleasantly surprised!


3. I Love TextMate Snippets

If Vim can’t natively do it, you can bet that there’s a plugin available somewhere!

You’ll quickly find that, if Vim can’t perform a particular task, then it’s likely that a plugin has developed to provide that functionality. For instance, consider TextMate’s excellent snippets feature. While Vim doesn’t support this natively, you can download the snipMate plugin, which should make the experience virtually identical to what you’re used to.

Learn More About Switching to Vim From TextMate


4. I Can’t Use the Arrow Keys

The less movement, the better.

Firstly, this isn’t true. It might have been the case with Vi, but you’re free to use how Vim in the way that feels most comfortable to you. So use the arrow keys to your heart’s content — though keep in mind that there’s a reason why most Vim users don’t.

The h,j,k,l keys mapping to left, down, up, and right, respectively, serve two purposes:

  • No Choice: Back in the day, machines didn’t have those helpful arrow keys. As such, they had little choice but to choose the best alternative.
  • Less Movement: If your hands generally rest along the second row of the keyboard, it makes little sense to repeatedly move your hand to the lower-right portion of the keyboard every time you want to move the cursor. The less movement, the better. With this arrangement, you can traverse your documents without moving an inch.

When all is said and done, you are the person using the editor. If, at first, you feel more comfortable using the arrow keys, then by all means do!


5. I’m a Designer, Dude

That’s okay! Vim is not for everybody. As a person who at least attempts to do design work from time to time, I can fully attest that Vim may not be the best fit for designers.

Developers are not designers; it’s only natural that this fact will be reflected in their choice of editors.

If you find that the bulk of your days are spent working with HTML and CSS, then maybe Vim is not for you. Now, that’s not to say that you shouldn’t give it a shot; but it’s certainly understandable, should you decide to stick with a more designer-friendly editor, such as Coda.


6. Vim Offers Nothing My Current Editor Doesn’t Already Do

Plain and simple, that’s rubbish. Certainly, every editor does have its strong points, but you’ll find that Vim is incredibly powerful, and, more importantly, flexible. There are hundreds upon hundreds of plugins available (for free) that will provide support for virtually any kind of functionality that you require.

Many newcomers often cite the built-in “Change Inner” command as a huge selling point. It certainly was for me! Let’s say that you have the following piece of code:

var joe = 'plumber';

Assuming that the cursor is at the beginning of that line, and you wish to change the value “plumber” to “black,” traditionally, you might use the arrow keys or the mouse to select and change the text. With Vim, the process is hugely simplified. Simply type: ci'. This stands for “Change Inner Quotes,” or, find the next set of single quotes, and change the value inside.

Kick-Ass Plugins

  • snipMate: Allows you to, for instance, type
    + tab, and have a full div element expanded. It’s tremendously helpful.
  • Surround: Wrap portions of text with parens, tags, braces, etc.
  • NerdTree: Explore your filesystem and to open files and directories. It presents the filesystem to you in the form of a tree which you manipulate with the keyboard and/or mouse. It also allows you to perform simple filesystem operations.
  • TComment: Easily and quickly comment certain lines of your code.
  • Sparkup: Similar to ZenCoding, but provide more support for applying values to elements as well, such as: ul > li { My list item text. }.

7. My Vimrc File is Blank

This was an initial gripe that I had with Vim, as well. When first launching, say, MacVim, you’re thrown into the wolf-pack! No code highlighting, no formatting, no smart indenting… no nothing! Particularly if you’re using a custom Vim editor, there should at least be a base vimrc file to get you started. It can be an intimidating experience trying to figure out how to apply your custom preferences.

For those unfamiliar with a vimrc file, it’s essentially a file that allows you to specify your editor preferences.

Use this as a starter (click the Expand button below):

" .vimrc File
" Maintained by: Jeffrey Way
" jeffrey@jeffrey-way.com
" http://net.tutsplus.com
"

"Forget compatibility with Vi. Who cares.
set nocompatible

"Enable filetypes
filetype on
filetype plugin on
filetype indent on
syntax on

"Write the old file out when switching between files.
set autowrite

"Display current cursor position in lower right corner.
set ruler

"Want a different map leader than \
"set mapleader = ",";

"Ever notice a slight lag after typing the leader key + command? This lowers
"the timeout.
set timeoutlen=500

"Switch between buffers without saving
set hidden

"Set the color scheme. Change this to your preference. 
"Here's 100 to choose from: http://www.vim.org/scripts/script.php?script_id=625
colorscheme twilight

"Set font type and size. Depends on the resolution. Larger screens, prefer h20
set guifont=Menlo:h14

"Tab stuff
set tabstop=3
set shiftwidth=3
set softtabstop=3
set expandtab

"Show command in bottom right portion of the screen
set showcmd

"Show lines numbers
set number

"Prefer relative line numbering?
"set relativenumber"

"Indent stuff
set smartindent
set autoindent

"Always show the status line
set laststatus=2

"Prefer a slightly higher line height
set linespace=3

"Better line wrapping 
set wrap
set textwidth=79
set formatoptions=qrn1

"Set incremental searching"
set incsearch

"Highlight searching
set hlsearch

" case insensitive search
set ignorecase
set smartcase

"Hide MacVim toolbar by default
set go-=T

"Hard-wrap paragraphs of text
nnoremap <leader>q gqip

"Enable code folding
set foldenable

"Hide mouse when typing
set mousehide

"Shortcut to fold tags with leader (usually \) + ft
nnoremap <leader>ft Vatzf

" Create dictionary for custom expansions
set dictionary+=/Users/jeff_way/.vim/dict.txt

"Opens a vertical split and switches over (\v)
nnoremap <leader>v <C-w>v<C-w>l

"Split windows below the current window.
set splitbelow              

" session settings
set sessionoptions=resize,winpos,winsize,buffers,tabpages,folds,curdir,help

"Set up an HTML5 template for all new .html files
"autocmd BufNewFile * silent! 0r $VIMHOME/templates/%:e.tpl

"Load the current buffer in Firefox - Mac specific.
abbrev ff :! open -a firefox.app %:p<cr>

"Map a change directory to the desktop - Mac specific
nmap <leader>d :cd ~/Desktop<cr>:e.<cr>

"Shortcut for editing  vimrc file in a new tab
nmap <leader>ev :tabedit $MYVIMRC<cr>

"Change zen coding plugin expansion key to shift + e
let g:user_zen_expandabbr_key = '<C-e>'

"Faster shortcut for commenting. Requires T-Comment plugin
map <leader>c <c-_><c-_>

"Saves time; maps the spacebar to colon
nmap <space> :

"Automatically change current directory to that of the file in the buffer
autocmd BufEnter * cd %:p:h

"Map code completion to , + tab
imap <leader><tab> <C-x><C-o>

" More useful command-line completion
set wildmenu

"Auto-completion menu
set wildmode=list:longest

"http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
  \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

"Map escape key to jj -- much faster
imap jj <esc>

"Delete all buffers (via Derek Wyatt)
nmap <silent> ,da :exec "1," . bufnr('$') . "bd"<cr>

"Bubble single lines (kicks butt)
"http://vimcasts.org/episodes/bubbling-text/
nmap <C-Up> ddkP
nmap <C-Down> ddp

"Bubble multiple lines
vmap <C-Up> xkP`[V`]
vmap <C-Down> xp`[V`]

" Source the vimrc file after saving it. This way, you don't have to reload Vim to see the changes.
if has("autocmd")
 augroup myvimrchooks
  au!
  autocmd bufwritepost .vimrc source ~/.vimrc
 augroup END
endif

" easier window navigation
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l

"------------------------"
"NERDTREE PLUGIN SETTINGS
"------------------------"
"Shortcut for NERDTreeToggle
nmap <leader>nt :NERDTreeToggle <CR>

"Show hidden files in NerdTree
let NERDTreeShowHidden=1

"autopen NERDTree and focus cursor in new document
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p

"Helpeful abbreviations
iab lorem Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
iab llorem Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

"Spelling corrects. Just for example. Add yours below.
iab teh the
iab Teh The

" Get to home dir easier
" <leader>hm is easier to type than :cd ~
nmap <leader>hm :cd ~/ <CR>

" Alphabetically sort CSS properties in file with :SortCSS
:command! SortCSS :g#\({\n\)\@<=#.,/}/sort

" Shortcut to opening a virtual split to right of current pane
" Makes more sense than opening to the left
nmap <leader>bv :bel vsp

" Saves file when Vim window loses focus
au FocusLost * :wa

" Backups
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
set backup " enable backup

" No more stretching for navigating files
"noremap h ;
"noremap j h
"noremap k gj
"noremap l gk
"noremap ; l

set showmatch " show matching brackets

" print empty <a> tag
map! ;h <a href=""></a><ESC>5hi

8. I Don’t Want to Use the Terminal

Me neither — at least not more than I have too — there are a variety of dedicated Vim editors which provide a more Windows/Mac GUI-like experience.

These editors will provide support for the sorts of keystrokes that are ingrained into your body, such as “Command + F” to search, or “Command + W” to close the current window.


Remember how, in school, sometimes, the student sitting next to you was able to explain and help you understand some difficult concept more than the teacher? The reason is because, once you’re mastered a craft, it’s difficult to recall what personally gave you the most trouble. From September to October, I embarked on a four-week challenge, which I call “Venturing into Vim.” After hearing countless extremely talented developers praise this seemingly decade-old code editor, I decided that it was worth a month of my time to figure out why so many people consider Vim to be the best editor on the planet.


10. I Can’t Edit Files on My Server

Of course you can, though, admittedly, it’s not quite as user-friendly as, say, Coda’s remote server feature. Speaking of Panic, if you’re a Transmit user, you might consider installing the Transmit FTP plugin.

“This script allows you to upload the current file via Transmit directly from Vim. For it to work, you need to be working on a file that’s tied to a Transmit connection, and this connection must have “DockSend” enabled.”

With this plugin, when editing a file that has a Transmit connection (open file via Transmit), you only need to press Control + U to push those updates back to your remote server. It’s a cinch!

Truthfully, though, you should try to adopt a better build/deployment process. This way, rather than using FTP, you can simply git push.


Sure – there are a handful of reasons not to use Vim. It has a steep learning curve, and requires a complete rethinking of how a code editor should function. That said, there are hundreds of reason why you should use Vim. The only question is: why aren’t you?

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • saquib

    Good post as always, you are amazing Jeff

  • //adrusi.com/ Adrusi

    I’ve tried to learn vim over and over and never been able to, there’s too high of a learning curve and right before I hit the peak I give in to frustration

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Yeah – the learning curve really is insane. It’s a solid month of every-day usage.

      The first week is the worst. :)

      • Alexander

        The first week is the worst? :s

        I’m trying to get in to vim for 3 months now, and still I don’t get it.

        Give me a good IDE that works also, and you don’t have to learn all that much. So what I got here is; I can now give my time to learn sweet frameworks, or more code languages!

        Yes sure, VIM is lightweight and the most IDE’S ain’t, but these days computers are fast and they can handle it.

        Thus my quick comment tip is; If you can’t learn VIM DON’T learn it, give your time to your programming knowledge!

      • http://designslicer.com Kien

        If you think Vim’s learning curve is insane you need to check out Emacs.

        I have to agree with Alexander, though. If you feel overwhelmed then don’t force yourself learning it. Personally, I got into Vim and Emacs because I feel very underwhelmed and unchallenged as a Front-End developer.

      • http://www.code-pal.com Sumeet Chawla

        During the first week, the worst part is using commands and getting some result which you did not want. I normally use to delete whole lines by mistake :(

    • //adrusi.com/ Adrusi

      I wonder how long it takes to make up the time lost while learning VIM. In the beginning you’re completely lost and go googling for a day to grab the basic of which you remember maybe 10% of. Then you feel the need to make it work like you want it to and spend another day or two looking for all the plugins and colorschemes. Then for another 1 or 2 months you’re significantly slower than in your old editor. Once you’re used to it, you might be 5% faster. so you lose maybe 30-50 hours in the first month or two and then it takes you 5-10 months to make it up (I just guesstimated the numbers though)

      • Ivan

        If your guesstimation’s right, you’ll save a few good years in your lifetime

      • http://roadha.us haliphax

        Believe me, the speed increase will far exceed 5%.

  • http://kevincantu.org Kevin Cantu

    At the terminal in Linux, at least, you can also use FTP directly like this:

    $ gvim ftp://server//path/to/file

  • http://www.wordimpressed.com Devin Walker

    Hmm, I’m conformable not switching and sticking with my current IDE.

  • https://github.com/jelera/ Jose Elera

    I’ve switched from Textmate to Vim about a year ago. Now I’m fairly proficient (by no means, advanced or an expert) but I move and edit way faster than using Textmate (which I was quite fast and I knew my way with the keybindings).

    I recon the switch can be “traumatic” and a change of mentality and habits have to be done. To lesser these, FIRST: fire up from the command line `vimtutor` (without the `), then read these to books Learning the Vi/Vim Editor from O’Reilly and Hacking Vim 7.2 from Packt. For screencasts, you can watch Jeffrey Way’s Venturing with Vim, Peepcode’s Smash into Vim, and Derek Wyatt’s peculiar but highly recommended screencasts.

    I’m 99% positive you’ll be rewarding with an experience and power of such tool.

    You can look at my dotfiles github repo, just click on my name. There is a section about Vim for Web Developers, I tried so many configs (lots of try and error) and I came up with my ideal web development environment. It can help you start, grab some ideas.

  • Matt Thornton

    I ditched the two IDE’s (Eclipse and Netbeans) I’d been switching between for 2+ years when the Venturing into Vim series came out. For the most part I didn’t miss them, that is until I left my old company and code base that I’d authored a good part of and jumped head-first into a massive Java project at my new company.

    I ended up writing my first bash script to give me quick access to files based on file name (with optional wildcards), location in the project, and search strings inside files. It has definitely helped, though I still feel…slow and lost, some of which can be attributed to a PHP->Java switch I suppose.

    If there is one thing I haven’t found Vim capable of doing yet is linking through a huge inheritance/extension and method chain. With a huge Java project that I’m not super-familiar with, this extends that, and this method belongs to that, it is nice sometimes to open up an IDE and hyperlink through objects and methods to get to the “right” file and place in a file to make the needed changes. I can usually find those other classes and whatnot with another search, but if things are 4, 5, or 6 deep, Vim and search just feels slow.

    • http://psquid.net/ PSquid

      As long as vim has support for the language you’re using (it does for pretty much all the common ones, so I’d guess Java is supported), you can use the command gd (think _g_oto _d_efinition) to move to where the class/function/whatever under the cursor was originally defined.

      • Matt Thornton

        Thanks PSquid! That seems to work, for the most part, when the definition is within a file. Still not sure how to get it to work between files, perhaps loading them all in…

        In any case, that is a great help.

    • http://whileyouweregone.co.uk/ Rich Cheng

      Not 100% sure exactly if this is what you’re asking for, but have you tried using Vim’s ctags support?

  • Nguyen Truong

    Hi Jeffrey,
    I am a beginner and I am using Notepad++ for editing stuff. I really want to switch to Vim, but I can’t find any plugin that provides neat lines for connecting the opening and closing tags. What would you suggest, Jeffrey?

    • andy

      what do you mean, “connecting the opening and closing tags”?

      • http://souravchakraborty.co.nr Sourav Chakraborty

        He means that when I type something like notepad++ will automatically insert its matching closing tag .

        Notepad++ is what I am used to, and I’m not in a mood to switch!

    • http://roadha.us haliphax

      I believe he is talking about the “hints” for collapsible regions in Notepad++. You shoud look into “folding”.

  • http://izhukov.ru Aleksey Zhukov

    nmap hm :cd ~/
    Useless.

    Simple try :cd

  • http://brianswebdesign.com Brian Temecula

    I used to use Vim when I had my own webserver. It’s OK, but I didn’t love it like you do. I’m mostly satisfied with my Notepad++.

    • Nykeri

      yup i’ve tried twice and was learning it somewhat but notepad++ does it for me too

  • http://butenas.com Ignas

    I’ve tried to switch to VIM twice… Both times – failed… Every time came back to TextMate. But I’m ready to give a third shot and will try to use it for my development. I’m using it to modify files in the server and some small development tasks on the linux machine, but need to lear a lot. Maybe some plugins you’ve mentioned here will help :) What is the best about vim – very lightweight, fast, powerful and you will have it on all the platforms (which is not true with TextMate :) ). So thanks for article and will try again :)

    • Fefo

      Try ‘vimtutor’ on the command line. It’s a sort of built-in tutorial from the vim developers

  • http://michaelhenriksen.dk Michael Henriksen

    If you’re planning on doing Ruby/Rails stuff in Vim, you should have a look at this: https://github.com/carlhuda/janus – Adds additional functionality to Vim which makes it even more cool.

  • Jay El Ehm

    What about emacs?

  • http://www.petarzivkovic.com Petar Zivkovic

    Personally, I’ll pass on Vim for now, probably for the long run also.

    I used to use vi back in college (late 90′s) but am not missing it, especially compared to a modern IDE. At the moment I’m using Komodo IDE and for the most part I love it. There are serious performance and quality benefits to be had from using a full featured, quality IDE over other text editors.

    Sure, a lot of simple code and typo corrections can be taken care of with ease, but when you use a good IDE, you have access to all sorts of options, modules and “code intelligence” features that are missing from other editors… which will in turn reduce the number of code/typo errors you have in the first place.

    I have to admit, dishing out $200-300 for an IDE might seem like a painful thing to do at first but it pays dividends (it will probably pay off within the first week or two of usage if you do a lot of programming).

    Good post in either case, detailed and covers a lot of details. :-)

    • andy

      Vi is a terrible editor, I can understand not missing it. VIM is completely different. If you’re doing Java or .NET development (ick) then other editors that autocomplete package names and give code hints for function calls have their merits. For anything else though there is no substitute for Vim. It is depressing and frankly disturbing that you spent $300 for a TEXT EDITOR when the most powerful one is free and open source. There are dozens of plugins like linters for any language in Vim. I used to think I was efficient in Notepad++, but after getting used to VIM I know I will never move to another editor.

  • George

    Nice!

    There are a few pretty good implementations of vim for IDEs such as jVi for netbeans, and IdeaVIM for jetbrains products, phpstorm, webstorm….even though IdeaVim is a little buggy from time to time… So i use macvim for small projects and PHPStorm for large projects. Made all the settings in phpstorm to copy macvim e.g. snippets, colorscheme etc… Replicated the Kelly vim colorscheme to phpstorm. And in the next month or so phpstorm 2.0 is being released, it’s great.

  • http://marines.jogger.pl marines

    You mapped space to colon in given config file. How do you write spaces then? :D

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      It’s a nmap — which only affects normal mode. Within insert mode, a space is still a space.

      • http://marines.jogger.pl marines

        ah, thanks for the explanaton :)

  • http://andrewburgess.ca Andrew Burgess

    Great article, Jeffrey! Couldn’t agree more on your points.

    One thing though: there’s another “pitfall” that I’ve had trouble with since switching to Vim full-time (which I did last summer). That’s using Vim commands in other editors! Sounds stupid, I know, but once you learn to quickly copy/paste/move around and more, the “traditional” way of doing it seems so slow. Plus, it becomes a muscle-memory thing, too; so I’ve often typed h,j,k,l or colon-w while working in, say, Google Docs.

    Also, I recently came across this vimrc/vim plugins “starter kit”; I haven’t tried it at all, but if you’re new to Vim, this should give you a bunch of the functionality that you’d expect, but that doesn’t come with Vim: https://github.com/carlhuda/janus. (Now that I think about it, it’s probably smarter to learn bare Vim, and build on it when you know what you’re adding, but . . . )

  • http://www.somnia-themes.com Timon

    Wow, I only tried this editor for a week and I already gave up. Just because I could’nt see how it would be faster later on, because everything was so hard to do! Mhm perhaps I give it another shot later. But if I want to do something fast, which I can’t in Vim atm (it just frustrates me), I rather use a different editor.

    Oh and facebook keeps refreshing this page it seems, already been like that for a week or so. Could that be fixed? It’s kinda annoying looking at your tab refreshing itself a 1000 times :-(.

    Great article Jeff!

  • http://ushcompu.com.ar ushcompu

    Nice post :D
    Tutorial:
    vimtutor
    gvimtutor

  • http://www.wdonline.com/ Jeremy McPeak

    I’d have to say the first (and only) pitfall of using Vim is… using Vim ;) I kid, I kid!

  • Eastern Block

    “Admit it: every time you see a person using Vim, you consider the possibility that they know something you don’t.”

    So true. In college I took a course on procedural languages and we used Ada as our catalyst (an archaic language that looks extremely similar to PL/SQL). All of our programs had to be submitted through our server which ran VIM, so I was thrown into that fire head first. My professor was one of the smartest people I’ve ever known and he was a VIM phenom. I learned an extreme amount of Unix and VIM commands just by watching him in class and it quickly began my editor of choice for the rest of my college career. Unfortunately in the real world I have been made lazy by the Intellisense, organization, and server connectivity of Visual Studio ’10… thus is life.

    Great article Jeff.

  • Andrew

    Great article, but full of errors.

    “Even more confusing — at first — a capital letter triggers a different action than a lowercase.”

    And then you get them mixed up through the rest of the article! Don’t use 5J to try and move down five lines; use 5j. The movement keys are h, j, k, l; not H, J, K, L. In the example code, you can’t use ci” because the variable uses single quotes; you will have to use ci’ instead.

    Please clean it up.

    • Andrew

      Great, that’s much better. Now a newbie following along and trying Vim for the first time won’t get frustrated. =)

      FYI, there’s also a really excellent tutorial that comes bundled with Vim called the Vim Tutor. Hit up :h vimtutor for more more information – I was up and running in a couple of hours and comfortable within days, thanks mostly to vimtutor. (Of course, over a year later, I’m still learning new tips and tricks…)

  • http://designslicer.com Kien

    filetype on
    filetype plugin on
    filetype indent on

    This can be shortened to just filetype plugin indent on

    “With Vim, on the other hand, you’d press capital V to switch to Visual mode, and then type 5J to select five lines down. Finally, you’d press d, for delete.”

    5J (capital J) will just join the next five lines then return to normal mode.

  • http://mikethecoder.com mcrittenden

    Just a note that #6 is incorrect – to select the text inside of single quotes, you would type ci’ (not ci”).

  • bill

    Vim is overrated.

  • wafto

    Use NANO.

    • nuku

      Use PICO.
      Use ed.
      Use your command line’s built-in line editor.
      Use tiny tiny magnets to switch bits on your hard drive directly.

  • doogal

    Real programmers use butterflies.

  • http://cslai.coolsilon.com Jeffrey04

    I picked up vim by using cream, then after going through vimtutor, then took me about a week to get familiarize with it. The only problem with getting too used to it is that… sometimes I entered some vim commands while browing the internet (trying to close a tab using :q)

    • andy

      look into the pentadactyl plugin for firefox. It turns firefox into vim, gives you things like gt, d to close a tab, :h for help, etc. It’s lovely.

    • http://log.gnusosa.net gnusosa

      look into vimperator.
      Best thing ever since the creation of beanut butter and chocolate cupcakes.
      Specially, if you use Firefox 4

  • Harro

    That vimrc file gives error if you don’t have the NERDTree plugin installed..

  • http://webtastique.net Daniel

    I think with all radical changes, it’s not so much the learning curve than the practice. I use Coda for development, and I know I would be at least twice as fast with VIM, but I’m so swamped that I can’t afford that initial month of practice.

    I think if you’re used to the usual bunch of editors, and you only use them about an hour a day, it doesn’t really make sense to start using VIM, it will take you ages to get the hang of it. If you spend most of your days in a text editor like I do, maybe you can make the jump in a week, but the amount of work you do will significantly decrease, and then gradually build up again and it will only become second nature in a month or something similar.

    Nice post though, I’ll try and make the switch in the Summer months :)

  • http://cardeo.ca matt

    I picked up vim a couple of years ago. I’m more of a designer so it was a bit confusing at first, but with practice it’s all I use now. I’d definitely recommend giving it a good chance. I prefer to use Terminal too. I rely on the below pdf cheat sheet for when I get stuck

    http://www2.cs.uidaho.edu/~rinker/ed03.pdf

  • Mike L

    I’ve been using Vim for years, and honestly I find emacs far more scary. Discuss?

  • http://www.airwolfe.com Alex

    Hi Jeffery,

    Its funny, at my old job many developers used either VIM or Emacs. I’ll admit, it was tempting to switch to either, I ended up trying VIM.

    However, after using it for a while and watching other teammates use it, I realized things weren’t really getting done faster with VIM. They were definitely not faster at inserting code, finding files, etc, and either was I.

    For individuals choosing an editor it can be a very personal choice and many factors are involved. For me, Speed & Productivity are the most important reasons which is why I choose not to use VIM. I’m far faster and more productive with Coda. In fact, I can honestly say the fastest most productive programmers I have run into do not use VIM or Emacs (not to say there aren’t some incredibly awesome ninjas using both).

    Many of the arguments I have seen for using VIM or Emacs revolve around the fact that if you can use your mouse less your faster, this is not true. The mouse is a tool that is far far superior for certain tasks and it would be insane to think that it wouldn’t be better in many cases. The mouse is also an extension of your hand where as keyboard shortcuts/commands are not. I can perform a variety of different tasks with the mouse unconsciously, doing the same with a keyboard would require serious thought & practice.

    The point I’m making is that choosing and editor is different for every person and features don’t necessarily = productivity (even if they are the same/similar). If your happier and more natural in one Editor that may be the way to go. You might find that your brain power is better spent solving programming problems :)

    Anyway, just some food for thought, really interested in hearing some other opinions. Thanks for another great article Jeffery!

    • Armando E. Lopez Jr.

      Awesome comment, it opened my eyes with regards to choosing an editor. Greatest comment I’ve read this year.

      • http://www.airwolfe.com Alex

        Thanks, glad it helped.

    • Mark

      @Alex: Couldn’t agree more!

    • yenic

      Not to raise a dead thread but.. as long as you’ve used VIM for a few years, and Coda for a few years.. your opinion holds merit. If not, seriously, head back to the drawing board because many of us can use VIM effectively and other editors. There’s really no point to proposing these ideas unless you’ve learned both well. No offense but it’s just misinformed otherwise.

    • donh

      > using VIM or Emacs revolve around the fact that if you can use your mouse less your faster, this is not true.

      Not even close to accurate, both in that the mouse is, in fact slower, and in that avoiding the mouse is a very minor part of the argument for vim. If you have all of vim’s motion commands dead-nuts under control, and are up to speed with visual mode, there’s no way a mouse comes even close providing that kind of speed. I’ve been in many kinds of intense production environments, and quite often noticed more than orders of magnitude differences between vim and non-vim users doing similar tasks, and any number of metric attempts have been done to test this question out. Switching physical context on input devices is inherently a bigger time-waste than I suspect you have had exposure to.

      If your full time job is mostly typing input, I might understand the vim doesn’t have that strong an incentive going for it, but if your job is mostly stealing, altering, and re-using, vim is a very fast payback investment.

  • http://elbertf.com ElbertF

    There is another reason to use hjkl over arrow keys: motions (and macros). E.g. 3j will move your cursor down three lines.

  • http://jeromyanglim.blogspot.com Jeromy Anglim

    With regards to video tutorials, check out those by Derek Wyatt (http://www.derekwyatt.org/). They teach technical details. But perhaps more importantly they highlight the potential power of Vim, which is important when you are making the decision of whether to invest an extended period of time in learning Vim.

  • penguiniator

    The hard part of learning Vim is that most often its underlying concepts are inadequately explained.

    First, it is a modal editor, meaning that it has one mode for editing and command functions and one mode for typing text. There are other modes, but those two are the most important.

    Second, its command language consists of noun-like and verb-like commands, such as dw for delete word, or dap for delete a paragraph. It even has adjectives, which are numbers telling Vim how many times to perform the following action. 3dw for delete word three times, or d3w for delete three words, which are functionally identical.

    Its command language follows a consistent syntax that makes it easy to predict how to combine newly learned commands with previously learned ones. The ways these commands can be combined are almost as flexible as human languages are. They can be used in ways that are closer to how you think; you don’t have to change the way you think to conform to the command language.

    Vim is best combined with touch typing. Its commands can all be touch typed, which is why it is so fast once you know the commands. You never need to move your hands from the touch typing position or your eyes from the text to issue commands. The way you physically interact with your computer’s hardware: the keyboard in particular, is greatly simplified by Vim’s modal interface, because the hands never leave the home row whether typing text or issuing commands. You never need to move your hand from the keyboard to the mouse and back to the typing position. This makes it unnecessary to divert your eyes from the text to be sure of what you are doing. You can concentrate more deeply on your work this way.

    Having to move your hand from the keyboard to the mouse and back is not too different from handwriting a letter and switching from one pen to another during composition. Its distracting. Vim’s modal interface and touch typed commands eliminate this distraction.

    :wq

  • hcabbos

    Jeffrey, line 23 of the vimrc file, shouldn’t that be “let” not “set”? I’m a newbie and couldn’t figure out why changing the leader wasn’t working. Using “let” did the trick. And should the end semicolon be there? All the examples I’ve seen omit it and it works fine for me without it.

    Anyways, great article. Just want I needed as I started really evaluating MacVim this week.

  • http://twitter.com/charlesroper Charles Roper

    As a follow up to this article I’d definitely recommend the following article by Yehuda Katz if you’re interested in learning Vim:

    http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/

  • Diogo

    This vim config works on vim(windows)?

  • Bob

    Vim is crap compared to Emac’s. I am a lot more proficient with Emac’s than I was with Vim.

    • Andy

      I have seen two very, very talented programmers who loved emacs switch to VIM and not look back. If you switch back to vim and learn the power of insert vs edit mode, which no other editor in the world offers (except vi of course), you will see the error of your ways. Don’t get me wrong, emacs is also a great editor and if you are proficient in it and have it perfectly customized for your needs then you will be fine to continue to use it. But saying that VIM is “crap” is a sad, trolling statement that means you didn’t become proficient in VIM and are dismissing it for lack of time using it.

  • Jason

    I’ve tried vim twice already and have had little to no success with it. I currently alternate between Notepad++ and Komodo. Watching other people use Vim I’m tempted to try it again, but my main problem was getting plug-ins to work. In particular Sparkup, but once I have the time and can get a handle on the plug-in aspect of the editor I will give it another shot.

    • Mike Funk

      You have Sparkup functionality in Komodo?

      I couldn’t get sparkup working either so I just used a better alternative: https://github.com/mattn/zencoding-vim. Works great for me to quickly set up html structure.

  • kuldeep

    hi jeff,
    The only problem i have with vim is that i like to use multiple tab open in my file editor. if i want to use in vim i have to close my file go back and open new file. i know there is tab option in gvim, but i didn’t like gvim that much. i just want to know if there are any other option? How you code in vim for multiple file?

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Vim supports tabs.

    • AjayKumar

      Vim supports viewport.

  • http://ilikekillnerds.com Dwayne

    Vim is overrated sorry. It’s for nerds who live in their parents basements, weight over 100kg and are over the age of 30. Seriously though, it’s a nerd editor and nothing else. It does not give you any advantage of any other editor.

    If you’re thinking of using Vim especially for PHP development, consider something like phpEd instead which in my opinion is way better than Vim, not to mention E Text Editor or Sublime Text Editor for everything else.

    The very fact Vim has an extremely high and complicated learning curve is not worth the effort and time other than to be able to say in an elitist tone, “Oh, I only use Vim to develop my websites and applications. I see you still use TextMate, haha, you silly noob.”

    • http://souravchakraborty.co.nr Sourav Chakraborty

      Well said, Dwayne. One should use what gets the job done for oneself. It may be vim, it maybe and IDE, it may be whatever. I really hate the snobbish attitude of vim lovers. Vim may be good, or the best for YOU, that does not mean it will be best for me, does it?

      • mwc

        When a person puts a significant amount of time into mastering a skill, they sometimes develop a raw nerve to perceived slights against that skill. Elitists will exist for any editor (even notepad, honestly), but their bigotry has no correlation to the quality of the editor. Ignore them.

        Dwayne, you sound very sensitive.

        vim is like physics. The theoretical power of vim is immense. It’s up to the user to unlock that power. And, like learning physics, it isn’t easy until it is.

        vim’s design clicks with me, so I use it.

    • zorg

      Dwayne, I see where yr confused. Let me help.

      1. Yr an idiot. Try to understand that.
      2. I work out all the time, have a six figure income,
      and use Vim everyday. The only way I conform to
      yr pitiful stereotype is that I’m over thirty.
      I did use Vim when I was under thirty, by the way.
      I only lived in my parent’s basement while I was in
      high school and I’ve never been fat.
      3. People from every country, every age group, every
      ethnicity use Vim. Y cannot see beyond yr own back
      yard. Too bad.
      4. I’m writing this comment in Vim because I have
      QuickCursor installed, letting me edit any text
      field in Vim (or whatever).
      5. Again, yr an idiot. I’m only denigrating y for
      that. Once y understand and try to expand yr
      perspective to see that others are different,
      I’ll not denigrate y further. Who cares if y
      use Vim or emacs or joe or turd-edit. This is just a
      place to help people understand and try Vim.

      • Prabhakar Bhat

        I see “y” I should not use Vim.

  • Joshua Olson

    I’m using your .vimrc file together with vimpager and needed to move the

    autopen NERDTree and focus cursor in new document
    autocmd VimEnter * NERDTree
    autocmd VimEnter * wincmd p

    Into ~/.vim/after/plugin/NERD_tree.vim in order for it to work with vimpager.

  • Jarvis Butler

    Vim is ugly. I needs teh UI candeh (^_^) which is why Sublime is my editor of choice. It gives me wood

  • Vlad Suciu

    From my point of view Sublime Text 2 with Vintage mode enabled is the best combo :).

  • jbcarey

    Well, I’m a designer that works with CSS/jquery/html all day and I must say, I use Zencoding + DW5…. i don’t know, most comfortable in that editor as it does everything i need it for….

  • http://roadha.us haliphax

    For those of you having difficulty installing plugins, you should check out the “pathogen” system – http://www.vim.org/scripts/script.php?script_id=2332

    • http://www.bitzero.it Francesco

      I 100% quote haliphax for pathogen. It’s the first plugin I install as it makes managing the others a charm.

  • http://spf13.com Steve Francia

    New to vim?

    Checkout spf13-vim, a distribution of vim plugins and resources for Vim, GVim and MacVim.

    It is a completely cross platform distribution that stays true to the feel of vim while providing modern features like a plugin management system, autocomplete, tags and tons more.

    Learn more at http://vim.spf13.com

  • elclanrs

    I’m not sure about the whole “you work faster if you use VIM”. I’m a Notepad++ lover. Whenever I’m in my linux desktop I always miss it, and VIM doesn’t do it for me, neither does wine, although it works, it has some annoying glitches. I’d say VIM is fine if you like it. By the end of the day you use whatever you feel more comfortable with, and for me, that’s Notepad++.

  • Nykeri

    Sorry but no, the learning curve is too extreme for me, I’ve tried twice and i don’t see the point or need for me to invest. Maybe if Vim’s UI was pleasant to look at i may have tried to use it more. For me that’s two important strikes against it. Sorry but i’ll stick to my notepad++ it works for me

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      How long did you stick with it each time?

      • beej

        I bet not long at all

    • Matt Korsmo

      You find NotePad++’s interface pleasant to look at? I guess to each their own.

      Switch to Sublime Text 2 and turn on Vintage Mode, go back though this article and pick up one or two (or more) tips. You will have a truly beautiful editor with most of the advantages of Vim and all the benefits of TextMate.