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
  • http://www.justinwhall.com Justin W Hall

    So which is it Jeffrey Vim or Sublime Text 2? Or are do you use both? I’m not really one to jump around…

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

      These days, I use ST2, with Vim (Vintage) mode turned on.

      • John M

        Hey please what colorscheme you use for your vim essentials tutorial? I want a textmate/sublime-like twilight theme but what i got is ugly.. I just want the twilight theme so a link would be fine. Thanks

  • http://www.1monthloanuk.co.uk/ Jim Carry

    Vim is difficult for me, is it if because i don’t use it regularly, when you use one thing on regular basis sure you like it rate it best than others.. But thing is that what about others when you don’t know anything about those then how could you rate them.

  • Jesus Bejarano

    Sublime Text 2 FTW

  • Joshua

    I dont get why “I can’t edit files on my server” is ever an issue? Why are we telling people how to edit files on their server directly? Thats horrible practice…

    If you’re working on config files, etc… then thats fine – but you’re probably ssh’d in anyways and have vim local on the server.

    If you’re working on site files, why in the world are you editing on the server?

    • http://twitter.com/jholyhead James

      Bad developers need text editors too.

    • http://www.webdogs.be Ed

      development server means something to you? ;)

      • Renato

        Uh, yeah: you ssh in the server and edit the files in vim (though you shouldn’t do that anyway). Or run the webserver on your local development machine.

        Or mount the remote filesystem with ssh, or nfs… if you so inclined.

    • donh

      Faster, more efficient&flexible development cycle?

      Same reason I don’t like sewing on a button while wearing work gloves?

  • jack

    give some good resources for newbies.even experts.to play with vim
    1 http://naleid.com/blog/2010/10/04/vim-movement-shortcuts-wallpaper/ ,a very nice vim wallpaper,you can see it and learn vim everyday.
    2 http://www.openvim.com/ ,an very good online interactive vim turorial.
    3 http://vim-adventures.com/ a real vim game,go and play once a week or a day.
    4 http://code.google.com/p/macvim/,see the two very good free ebooks about vim on the link area.

  • http://vivaotux.blogspot.com Sergio Luiz Araujo Silva

    I love Steve Losh article entitled “Come home to vim”. The article tells how the author switched from texmate for vim, pretty good! Como home to vim.

  • http://mailostudios.com Paul

    I think this article came on a little bit too strong. Yes Vim can be fast to the people who know how to utilize it but that’s the same for every editor.

    I personally use PhpStorm and yes I do have Vim along with Sublime Text 2 as well installed on my computer but I don’t see myself moving permanently to Vim just because there is just so much more that PhpStorm, and other IDEs too, does WITHOUT having to install a multitude of plugins like code highlighting and hinting for multiple languages in the same document and much much more.

    Also, there is a reason the mouse has stuck around – it’s insanely efficient. If there is a typo in the middle of a long paragraph I don’t even have to think to get to it my mouse is there in a second and it’s fixed. With a trackball I literally don’t even have to move my hand – I know, lazy but it works!

    Lastly, it’s just a matter of preference. The thing most people seem to forget is that just because something is more complicated and harder to learn doesn’t mean it does the job any better.

    • David

      Paul, my guess is that you don’t do development on a laptop. If you did, you wouldn’t be raving about your mouse, but the reason why Vim is so pleasant for me is particularly because it’s efficient to work with text when I don’t have a mouse. I work outside fairly often.

  • Mike K

    It took me a few hours to learn all of the basics with the builtin vimtutor and over the years learned more and more about vim. There will always be those that prefer other editors or IDE’s but to say that the mouse is faster is just plain wrong. The mouse requires you to take your hand off of the home keys and you lose the speed battle right there. By the time you start to reach for that mouse I’ll already be right on the precise insertion point to start editing. That’s why those that put the time into learning vim find that it just about blows all the others away speed wise. There is only one disadvantage to vim and that is getting over the initial shock of learning something that seems querky at first. My main motivation for learning it was due to the fact that it is on virtually every system you’ll run into.

    There is nothing wrong with prefering another editor but if you spend a lot of time coding and editing files then you owe it to your self to give vim a month of working with it. If you still feel that way at the end of the month then I’ll be shocked.

  • Mike from Shreveport

    “I’m a Designer, Dude”

    A Vim frontend with a LaTeX backend makes an incredibly powerful combination for designers. LaTex gives you absolute control over typsetting, while Vim gives the user the most powerful text editing possible. There are plugins to facilitate this, and once set up can be a really fabulous combination. You ca compile to Tex from within Vim. Search “Vim-LaTex Suite”.

  • Jesus Bejarano

    Just a little “secret” to Vim users go to https://github.com/spf13/spf13-vim your life will be easier i promise.

    • umun

      I love u Jesus. This is nirvana. I hope it is not difficult to add our own plugins using Vundle.

    • Wayne Walker

      Much easier I think. once I finally removers numbers.vim plugin spf13 looks great.

      • http://www.facebook.com/jesus.bejarano.948 Jesus Bejarano

        Hahah we think alike , i remove it too, well i remove the whole thing now i use janus. :)

      • dima

        I would not recomend spf13. I used it, but it makes your editor very non-standard, and when we did pair-programming (through ssh, with tmux and vim) I had problems with the other guy, as he expected a more vanilla vim.

        About the numbers.vim: after I uninstalled spf13, I got back that plugin. It helps me very much, I don’t have to count or aproximate how much lines I want to jump or delete.

      • dima

        but I would advise you to take a look at that package, and choose the plugins you like. There is too much packed in there.

  • Wayne Walker

    Thank you! I was looking at this article to use in discussions with colleagues I want to use vim in tmux to remote pair program with.

    I’ve used vi, then vim since ’89. And I didn’t know about ci” Wow, the things we miss….

  • http://www.facebook.com/ian.longshore Ian Longshore

    I had no difficulty learning to use vim. After about a year of using an IDE (I just started learning to program this past year), I found myself performing a large number of complicated keystrokes to get simple things done. Then I switched to vim last month (and I got a vim commands plugin for Intellij) and I found that every little thing that I thought ought to be a feature in a text editor happened to be right there in vim. There’s essentially a button for pretty much every single action involving moving the cursor, deleting text, or copypasting text. I wouldn’t say that it makes my programming more efficient. Rather, it just gets rid of a few common annoyances.

  • kyu

    If you don’t like vim, then just don’t use it. No one forces you to use vim and I believe you can do a pretty good job without vim. However, after I learned and used vim for almost a year, I can’t even imagine how I am gonna write my code without it. Using vim not only greatly fasten your code writing, but also it helps you to learn unix command and perl language too coz they are so closely related. I love vim and want to say thank you to the authors of great great vim plugins!

  • AjayKumar

    Jeffrey, simply superb presentation!