
Coming Home to Vim - PopaL
http://stevelosh.com/blog/2010/09/coming-home-to-vim/?
======
genbattle
I took the dive into Vim about a year ago. I was at the stage where I'd become
proficient with some command-line tools in Linux, but I didn't yet have an
editor I could use fluently from the command line. I tried out both Vim and
Emacs, and found Vim to be slightly easier to grok, plus my pinkie got kind of
sore from holding down the Ctrl key in Emacs.

I changed my default editor at work to be Vim, and started doing all my dev
work at home through Vim. I started off just using the arrow keys to move and
just using insert mode to edit text the normal way. Each day I tried to add
one new command to my repertoire; I learned about how to structure vim
commands (c-change i-in w-word, etc.) and move using hjkl and the higher order
movement commands like w and b. Now I can maneuver my way around vim quite
confidently, and although when I started off I was much slower in Vim than
other editors, I now find that Vim is just as fast or faster for most tasks,
particularly where I can make use of Macros.

At the moment I still have to get my head around markers and a few other
concepts, but I've definitely become proficient enough for it to be worth the
effort and time invested so far.

My tips for anyone learning to use vim for everyday development would be some
common tab commands: :tabnew <path> to open a file in a new tab, :tab sball to
show all currently open buffers in separate tabs, gt and gT to jump to the
next/previous tabs.

~~~
sbochins
Yea, tabs are a very useful feature in vim that many people don't seem to use.
I know people that use the panes. This isn't really useful for me though. I
use tmux as my window manager for my terminal, so I have not use for panes in
vim. I just have a bunch of vim processes running and use tmux for the window
management. The great thing about this is my development environment
completely mirrors my production environment. I have found that one of the
best productivity gains you can get is having one mental model for everything.
Unfortunately I'm still coding in PHP (don't think PHP fits into this idea).

~~~
Smudge
I use tmux too, but I prefer the way vim handles panes. When I'm in mental-vim
mode, it's easier for me to not have to jump out to thinking in tmux terms
when editing several files.

~~~
dedward
attach/dtach/dvtm perhaps then......

------
zaptheimpaler
Wow, the bit about seeing vim commands as sentences composed of nouns, verbs
and adjectives blew my mind. I thought about learning vim, but I didn't know
about this, so vim commands seemed like some arcane language that I would have
to gradually get proficient at over months.. this might make the transition a
lot easier.

~~~
bcrescimanno
Learning to see the commands as a language is helpful; but, it doesn't really
reach its full power until you start to see files in terms of the various
groupings that Vim affords you (either the out of box things or custom text
objects). If you stick with Vim, you'll start seeing things like whether or
not you want a word or a WORD, or around (a) or inside (i) an object.
Moreover, start to pick up on when you're hitting the same key multiple times
or repeating a command. There's almost always a faster way to do something
than repeating a command N times.

I'll be totally honest, it takes time and a real commitment to using Vim as
your only editor. But, over time, you'll start to think in this text objects
and, combined with the "commands as a language" concept--that's when Vim will
really start to show it's power.

~~~
johncoltrane
I agree on everything.

You didn't mention the fact that all of this becomes addicting rather quickly:
going to a more "normal" editor or textarea can be extremelly frustrating some
times.

~~~
possibilistic
Incredibly frustrating. I have trouble when I have to use other PCs or
devices. I can no longer use the "arrow keys" and get momentarily confused
when hjkl are showing up in the textarea instead of giving me movement. And I
can't tell you how many times I hit escape in LibreOffice/Calc/etc.

This is one reason why I don't use online editors like Google Docs. They don't
have great vim keybindings. Even extensions like Vrome and Vimperator fall
just a little short. And for apps that do have a subset of the bindings--they
are almost worse than having no bindings at all; evince has hjkl, but no gg/G,
etc. It drives me mad.

I've configured AwesomeWM to be vim-like, but how I wish there was window
toolkit-level support for vim bindings! In fact, I wish I could run everything
from vim.

~~~
alttab
I've IM'd :wq to my wife more times than I can count.

~~~
pwang
Hopefully more than you've typed ":q!" :-)

~~~
alttab
If you make a habit of typing :q!, you're going to have a bad time.

------
borplk
I'm a hardcore nerd and I spend many hours with a text editor during the day.
Yet I find vim beyond my nerd level. I just can't be bothered with fiddling
with config files and installing little bundles and packages for every
functionality.

On top of that the whole "language of editing" and combining
noun,verb,adjective commands, etc... doesn't really appeal to me because I'm
too visual when I'm editing code. I can't stop to think about the right
semantics about what I want to do, I just do it visually.

~~~
brown9-2
I think that a lot of these "Intro to Vim"-type posts do Vim beginners a
disservice by recommending a whole bunch of plugins right off the bad. Instead
of just learning the Vim basics now the reader needs to also learn how to use
all those recommended plugins.

You can get awfully far with just the built-in application and maybe something
like CommandT to help navigate projects, especially if using a GUI editor like
MacVim to make tab navigation easiest.

~~~
johncoltrane
As much as I respect Steve Losh, I must admit you are right: this very post
put me in a plugin/remapping frenzy when I switched from TextMate. After a few
weeks, my Vim was a mess and… it wasn't Vim anymore. Eventually I decided to
go back to square one and learn Vim properly but I certainly lost a couple of
months chasing fantasies.

------
tolos
I'm skeptical that Ack is "far, far better than grep." Different? Ok. Better?
Maybe, based on what you're doing. Far, far better? Probably not. Omitting
correct results because a file extension isn't white-listed sounds like a
pain.

[http://superuser.com/questions/39384/best-grep-like-
tool/342...](http://superuser.com/questions/39384/best-grep-like-
tool/342803#342803)

~~~
petdance
Where did you see ack as "far, far better than grep". My Ctrl+F finds nada.

The reason I took "betterthangrep.com" as a domain name, besides it being
catchy, is that I want people to think beyond stock grep as a tool, to know
that they have options. The page <http://betterthangrep.com/more-tools/> is
just a listing of other tools that may be better than grep, depending on the
use case.

~~~
tolos

      Ack
      
      If you’re a programmer and you don’t know about Ack, you need to start using it now. It’s far, far better than grep.

------
mattkirman
Original discussion from a couple of years ago can be found here
<http://news.ycombinator.com/item?id=1710702>.

~~~
janogonzalez
this keeps coming home once a year :P

------
losvedir
Sigh, I keep seeing this article, and ones like it, and keep thinking maybe I
should go back to vim. I'm happy with Sublime, though I like the idea of vim.

I've used vim a great deal in the past and it really is exceptional for
editing a given file. The thing that really tipped me to ST2, though, was its
management of multiple files in a project. The sidebar and Goto Anything are
indispensable. I know vim has command-t, but I just haven't been able to
browse a family of related folders as easily. How do others do it?

Also, I just can't get used to the line-by-line scrolling of vim and emacs vs.
the pixel scrolling of Sublime, or TextMate, or even TextEdit.

~~~
johncoltrane
CtrlP(1) is a recent alternative to Command-T: you can use it to quickly jump
to another buffer, a nearby file, a recently used file… all this with a very
consistent interface and a neat feature: you can configure it to look up and
up for a .git or .svn or other VCS artefacts and start from there. This makes
the whole "open a file in the current project" business an almost seamless
experience.

Also what's the point of displaying a third of the height of a line?

(1) <https://github.com/kien/ctrlp.vim/>

~~~
bcrescimanno
Nice tip on the Ctrl-P link; but I'm curious, is there anywhere that sums up
why Ctrl-P would be preferred over Command-T? Aside from being written in pure
Vimscript, I haven't seen anything touting any specific advantages or
disadvantages in a head-to-head.

~~~
johncoltrane
Just for you:

    
    
                                                 | Command-T | CtrlP
        -----------------------------------------+-----------+--------------------
         files                                   | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         buffers                                 | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         tags                                    | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         jumps                                   | OK        |                    
        -----------------------------------------+-----------+--------------------
         lines (vimgrep)                         |           | OK                 
        -----------------------------------------+-----------+--------------------
         MRU files                               |           | OK                 
        -----------------------------------------+-----------+--------------------
         mixed                                   |           | OK (new, untested)
        -----------------------------------------+-----------+--------------------
         open in tab                             | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         open in vsplit                          | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         open in hsplit                          | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         open multiple items                     |           | OK                 
        -----------------------------------------+-----------+--------------------
         matches with filenames                  | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         matches with filepaths                  | OK        | OK                 
        -----------------------------------------+-----------+--------------------
         execute command on opened file          |           | OK                 
        -----------------------------------------+-----------+--------------------
         create new file and parent directories  |           | OK                 
        -----------------------------------------+-----------+--------------------
         project root finder based on VCS        |           | OK                 
        -----------------------------------------+-----------+--------------------
    

I'd say that both are quite close in terms of features. CtrlP's strong points
for me are:

* no dependencies

* project root finder

* overall UX

The "lines" feature (fuzzy incremental search across buffers ) is also _very_
nice:

~~~
bcrescimanno
John Coltrane wins the points--way more than I expected (a link to a quick
summary would have done fine)--thanks for the detailed look!

~~~
johncoltrane
You are welcome.

------
HarrietTubgirl
I've come and gone with various vim config changes, but this is the one non-
standard one I've stuck with:

au! BufRead,BufNewFile * lcd %:p:h

This makes it so that when you open a buffer, you cd to the current directory
(only for that window), so you can quickly open files in that directory.

[% is the current file relative to pwd, :p converts to a full path, :h takes
off a path component, lcd does a cd but only for the current window]

Another tip is that when your internet connection sucks enough for SSH lag
(tethered, free wifi, whatever), you can edit a file locally and have vim do
the SCP back when you write:

:e scp://you@somewhere/path

Boom!

~~~
tylerhobbs
A nice alternative is to do:

    
    
      " Allow easy navigation to relative files
      cmap %/ %:p:h/
    

This basically replaces everything before the slash with the directory of the
file you're editing. That way, you don't have to necessarily cd, but can
easily open files near the one you're currently editing. You can just do ":e
%/foo.txt" to open foo.txt in the same directory.

------
chimeracoder
Slightly tangential, but the author mentions remapping Caps_Lock, as I do
(I've mapped it to Escape, as Esc used to be where Tab is on modern keyboards
anyway). The moment I first did this, I realized how amazing vim really is,
and why people always say that you can navigate the entire file without moving
your hands from the home row.

However, both methods I know for doing this only work inside an X server -
does anybody know a good way to remap keys without X?

~~~
s00pcan
I used to have it mapped to escape but once I started using tmux I mapped caps
lock to control and never looked back. Much more versatile than escape and
ctrl+[ will do the same thing (although it's proving hard to break the habit
of pressing escape instead).

~~~
spudlyo
Unmap your escape key, that will force the habit. I did this when I moved my
control and meta keys to the left thumb of my kinesis keyboard, and it helped
train me not to hit the old keys.

~~~
s00pcan
I've tried this in the past but it made both escape and ctrl+[ no longer
function. What worked for you?

~~~
spudlyo
Under OSX I used a tool called KeyRemap4MacBook which adds an item to the
control panel that lets you reconfigure keys. I just tested it, you can can
disable the escape key, but Ctrl-[ still works like you'd expect.

------
barbs
I'm a bit torn. I love the controls in vim, the way you navigate and
manipulate text is a brilliant system. It makes it more efficient and more
"fun".

However, I really don't like the configuration system for vim. Reading the
article above, I lost interest when he started talking about his .vimrc file
and the plugins he used. It seems arcane to have to have these cryptic
settings, whose functions aren't immediately obvious, and write them to a
file. I understand that part of the VIM philosophy is that it's almost like a
language, or that it's like programming your text, but configuration is just
something that you (ideally) set once, and then forget about. Even if I do
learn what "nnoremap <leader>ft Vatzf", if I need to set up my environment
again, I'll likely forget what it is and why I needed it in the first place.
And even if I configure VIM to have the things I want (for example, NERDtree
for project navigation), it'll never look or feel as intuitive as having a
graphical interface.

So it seems when people talk about VIM, it seems that they're really talking
about two things: the control scheme (keybindings) and the editor itself (the
environment).

Being an android developer, I use eclipse. I use the "Vrapper" plugin, which
gives me vim keybindings in the eclipse editor. I love it. It gives me the vim
navigation that I know and love, but the environment and tools provided by
Eclipse. I think this is how it should be - the environment of the editor is
best handled separately, and although you can add a ton of plugins and
configure the crap out of VIM to turn it into an IDE, it'll never really be a
proper IDE.

This is why I'm still looking for an ideal lightweight text editor/IDE. My
ideal for linux would be Geany, but with Vim keybindings. I discovered Vico
yesterday, which looks interesting, but is OSX only at the moment. Might be
what I'm looking for, but we'll see.

~~~
johncoltrane
Try Sublime Text 2 for a lightweight editor with Vi keybindings. It's not Vim
but it's quite powerful in its own right and is cross-platform.

With some experience and the right mindset, Vim's language becomes second
nature and a mapping like yours is very easy to understand.

The thing is that too many people, me included at the beginning, follow the
"learn -> customize" path in the wrong order: "customize -> learn"; often
because of articles like this. This lead to a non-productive mix of plugin-
addiction and mappings-dependance that's rather obviously counter-productive.

The ideal path would be to first learn how to use plain Vim then use this
knowledge to customize it. This path leads to a short .vimrc and a lightweight
.vim directory while the other leads to a miles-long arcane .vimrc and a
bloated .vim directory.

------
Derbasti
I started off with Textmate, then Emacs, then Vim, then back to Textmate, then
Vim (for real that time), then Emacs (for real, that time).

I am tempted by Sublime Text and Vim, but can't live without a few Emacs
features these day. But sometimes I miss the fluidity of Vim.

That said, I found the most important influence on my productivity is _fun_. I
am most productive when I enjoy what I am doing. And this is very directly
influenced by the way I do the clickety-clack thing with my keyboard.

In fact, I sincerely think that Vim is _the_ most efficient text editor out
there. Nothing else comes close. The thing is, me personally, I am having more
fun elsewhere, for reasons that have little to do with text editing
performance.

Mind you, this is not critique against Vim. But I would like to discuss text
editing productivity in terms of fun instead of keypress efficiency. Whenever
anyone argues about the relative merits of EditorX against EditorY in terms of
key presses I feel like he is missing the point.

What do you think about this idea/argument?

~~~
elrzn
I really like Vim as a concept, but the implementation is somewhat laking and
not so easy to extend.

At the moment I'm using Emacs with EVIL (Vim layer) and loving it. You should
check it out :)

~~~
Derbasti
I did and I could not cope with it. My brain can either do Emacs or Vim, but
not both. Whenever I used Evil, I would fall back entirely into Vim mode and
more or less ignore all the Emacs goodies and miss my favorite Vim plugins.
Mixing Emacs and Vim did not go well with me. However, maybe I should try it
again now that I am comfortable with Emacs.

------
pash
This blog post recently helped persuade me to switch to Vim (from TextMate).
The two things that most helped me _learn_ Vim, beyond the very basics, were
Drew Neil's excellent Vimcasts [0] and Steve's own _Learn Vimscript the Hard
Way_ [1] (a work in progress). Learn the basic movement commands and text
objects, then spend ten minutes every day watching a Vimcast or doing a
chapter of _LVHW_ and you'll quickly be past the steep part of the learning
curve.

0\. <http://vimcasts.org/episodes/archive>

1\. <http://learnvimscriptthehardway.stevelosh.com/>

~~~
bcrescimanno
In addition to the vimcasts, I also found Derek Wyatt's video series very
helpful (as well as entertaining).

[http://ontwik.com/tools/vim-from-novice-to-professional-
by-d...](http://ontwik.com/tools/vim-from-novice-to-professional-by-derek-
wyatt-p1/)

~~~
justauser
Excellent. I've been a long time user of Vim and never saw this until the blog
post.

------
dedward
It goes without saying..... check out vimgolf if you haven't - whether novice
or expert, competing or just reading, you learn new stuff.

Don't become too plugin dependent too early, but a quick browse through some
other's dotfile repositories (yadr is worth looking at, especially if you are
on a mac - not necessarily to use, but definitely to see what's possible).
Things like EasyMotion really make you think. As do things like persistent
undo files. (gundo and other stuff)

At some point you should be buildilng up your own set of dotfiles from
scratch.... not just relying on someone elses (some day some bug hits you and
you have no idea where to start otherwise)

------
Andrew-Dufresne
After using Vim for couple of years, I recently made a switch to Emacs.
Sometimes I regret it. I definitely miss Vim modal design and keybindings.
Compare Vim's J (join lines) with Emacs go to the lower line and press ^ to
join it with the upper one.

To copy a line in Vim you just have to press 'yy' but there is no copy line
command in Emacs out of the box. What you can do is C-k, C-y, i.e cut a line
into clipboard and paste it back to have copy line effect.

But trying and learning different tools is obviously useful. Emacs introduced
me to ido-mode and org-mode. Now that I know of the possibilities, I can
search for and use similar plugins in Vim.

~~~
jbp
"No copy line command in Emacs" Did you try "Alt/Meta-w" ?

~~~
BCM43
You have to select the text first for that to work. The quickest way I can
think of is Ctrl+a, Ctrl+k, Ctrl+y.

~~~
Derbasti
Or you just roll some elisp to do the job.

------
norswap
> "If switching to a different editor can increase my efficiency by even 10%
> it would save a good chunk of my time and let me get back to making cool
> things."

> "I don’t buy the “you’re thinking 90% of the time and only typing 10% of the
> time, so your editor doesn’t really matter” argument. Even if the premise is
> true, the conclusion is wrong."

Interestingly to me, people never (or rarely) attempt to improve their thought
process, which would probably result in a much higher increase in productivity
than editor proficiency.

------
z92
> nnoremap ; : > I don’t remap : back to ; because it seems to break a bunch
> of plugins.

That sounds like another good trick. But then how do you jump to your next
f,F,t? I find myself frequently typeing "f=" to find "=" and then hitting ";"
to jump through all the "=" in that line and reach the one I want.

~~~
pyre
When people overwrite things that are basic like that they usually don't have
an alternative. They overwrite them, because it doesn't fit their common usage
pattern.

But, for example, I use ',' as my <Leader>. So that I can still use ',', I
also map ',,' back to ',' functionality:

    
    
      let mapleader = ","
      let maplocalleader = ","
      nnoremap <leader>, :normal ,<CR>:<CR>

------
comatose_kid
" If switching to a different editor can increase my efficiency by even 10% it
would save a good chunk of my time and let me get back to making cool things."

Instead of taking us on a long biographical journey of how you found the One
True Editor (this week), why not familiarize yourself with Amdahl's Law?

~~~
stevelosh
Where can I get clones of myself willing to concurrently enter text so that
Amdahl's law about parallelization performance somehow becomes even the
slightest bit relevant to text editing?

~~~
comatose_kid
Okay, fine - law of diminishing returns, the point still stands (although I
deserved that for being a smart-ass).

------
teaneedz
Even though I really enjoy pecking away in BBEdit, I find Vim to be so
wickedly fast. Manipulating text in Vim is nicely handled without having to
stretch the fingers very far. By the time I go to the trackpad in another IDE,
I could have accomplished so much more within Vim.

------
fromhet
Is there anyone on HN not using textmate and sublime no Mac OSX?

~~~
bradleyland
Yes, there are plenty of people using Vim or Emacs as they're primary editor.
You don't always hear from them though, because they've already lived through
several rounds of editor wars.

~~~
bradleyland
I'm really embarrassed that "their" ended up "they're". I'm not sure if I
typed it out of muscle memory, or if I mistyped it and Lion auto-corrected to
"they're".

This is why I never stoop to pedantry. I know the difference, I swear!

------
jasondavies
Great tip for using Perl/Python-compatible regex syntax:

    
    
      nnoremap / /\v
      vnoremap / /\v
    

This will save me a _lot_ of time. Thanks, Steve!

------
Lapsa
One thing I can't understand - why people remap leader to comma? How they use
fFtT without it?

~~~
kisielk
[fFtT], still works even with comma mapped to leader.

------
patrickod
Does anyone know what the author is using to display carriage returns at the
end of each line?

~~~
Olreich
in ~/.vimrc :

    
    
        set list
        set listchars=tab:▸\ ,eol:¬
    

it's in the getting started section.

~~~
patrickod
Thanks! Don't know how I missed that

------
geoffc
mid eighties till 1992 on Qedit, Emacs till 2002 then VIM to the present, no
desire to switch for the next decade of coding :-)

