
Vim, you complete me - Croaky
http://robots.thoughtbot.com/post/27041742805/vim-you-complete-me
======
cletus
Vim reminds me of an example from Bret Victor's excellent talk _Inventing on
Principle_ [1] (which you should watch from beginning to end if you've somehow
been hiding under a rock and have missed it).

Bret mentions Larry Tesla (starting at about 38:10) who made it his personal
mission to eliminate modes from software.

This is the problem I've always had with Vim and I suspect I'm not alone in
this. I find the concepts of modes jarring, even antiquated. Everyone who has
used vi(m) has copied and pasted text in while in command mode and done who
knows what.

Emacs is better in this regard but I find Emacs's need to consecutive key
presses (or a key press followed by a command) to be longwinded.

The advantage of either is they're easy to use over ssh+screen (or tmux) for
resuming sessions.

That all being said, give me a functional IDE any day. IDEs understand the
language syntax. Vim can do a reasonable job of this. Emacs (with elisp) seems
to do a better job (or so it appears; I'm no expert) but IDEs (my personal
favourite being IntelliJ) just make everything easier. Things as simple as
left-clicking on a method and going to its definition.

For statically typed languages (eg Java/C#), IDEs (quite rightly) rule
supreme. Static code analysis, auto-completion, etc are just so much better
than text-based editors.

Dynamic languages are more of a mixed bag and its certainly the norm for, say,
Python and Ruby programmers to use one of these.

Still, give me an IDE any day.

One objection seems to be that people don't like using the mouse. I tend to
think the speed differences over not using the mouse are largely illusory.

Anyway, I can use vim but I've never felt comfortable in it and I don't think
I ever will and modes are the primary reason.

EDIT: I realize there are plugins and workarounds for many of these things but
that's kinda the point: I don't want to spend hours/days/weeks/years messing
with my config to get it "just right".

Also, instead of archaic commands to, say, find matching opening/closing
braces (which tend to involve an imperfect understanding of the language),
IntelliJ just highlights matching braces/parentheses, where a variable is used
and so on.

[1[: <http://www.youtube.com/watch?v=PUv66718DII>

~~~
jes5199
The way that most Vim users use modes is like using "StickyKeys" on your
Shift/Control/Option keys. You smack "i" or "a" to go into insert mode just
for the duration that you need it, and then you smack Escape the moment that
you stop typing, even if it's just pausing to think.

Also, if you use a GUI version of Vim, then it knows about "paste" and doesn't
make the mistake of interpreting your paste buffer as keystrokes.

~~~
dave1010uk
I think this is the key to vim. It's a revelation or a turning point in how
you use it. You change to insert mode to insert text; you don't change to
normal mode (to do text operations) as you're already in normal model.

------
Rudism
It all started out innocently enough. You experimented with it once or twice
in your first year of college, but Nano and Pico were easier—closer to what
you had already been using during high school on the Windows machines and
Macs. But as time went on and you got more experience under your belt in the
college-level computer science courses, you started to notice something: All
of the really great programmers—the kind who churned out 4 line solutions for
an assignment that took you 10 pages of code to complete; the kind who
produced ridiculously over-featured class projects in a day while you
struggled with just the basics for weeks—none of them used Nano or Pico.

Staying late one night to finish an assignment that was due at midnight, you
happened to catch a glimpse over one of the quiet uber-programmer's shoulders.
Your eyes twinkled from the glow of rows upon rows of monitors in the darkened
computer lab as you witnessed in awe the impossible patterns of code and text
manipulation that flashed across the screen.

"How did you do that?" you asked, incredulous.

The pithy, monosyllabic answer uttered in response changed your life forever:
"Vim."

At first you were frustrated a lot, and far less productive. Your browser
history was essentially a full index to the online Vim documentation; your
Nano and Pico-using friends thought you were insane; your Emacs using friends
begged you to change your mind; you paid actual money for a laminated copy of
a Vim cheat sheet for easy reference. Even after weeks of training, you still
kept reaching for your mouse out of habit, then stopped with the realization
that you'll have to hit the web yet again to learn the proper way to perform
some mundane task that you never even had to think about before.

But as time went on, you struggled less and less. You aren't sure when it
happened, but Vim stopped being a hindrance. Instead, it become something
greater than you had anticipated. It wasn't a mere text editor with keyboard
shortcuts anymore—it had become an extension of your body. Nay, an extension
of your very essence as a programmer.

Editing source code alone now seemed an insufficient usage of Vim. You
installed it on all of your machines at home and used it to write everything
from emails to English papers. You installed a portable version along with a
fine-tuned personalized .vimrc file onto a flash drive so that you could have
Vim with you everywhere you went, keeping you company, comforting you, making
you feel like you had a little piece of home in your pocket no matter where
you were.

Vim entered every part of your online life. Unhappy with the meager offerings
of ViewSourceWith, you quickly graduated to Vimperator, and then again to
Pentadactyl. You used to just surf the web. Now you are the web. When you
decided to write an iPhone application, the first thing you did was change
XCode's default editor to MacVim. When you got a job working with .NET code,
you immediately purchased a copy of ViEmu for Visual Studio (not satisfied
with the offerings of its free cousin, VsVim).

Late one night, as you slaved away over your keyboard at your cubicle, working
diligently to complete a project that was due the next morning, you laughed to
yourself because you knew no ordinary programmer could complete the task at
hand before the deadline. You recorded macros, you moved entire blocks of code
with the flick of a finger, you filled dozens of registers, and you rewrote
and refactored entire components without even glancing at your mouse. That's
when you noticed the reflection in your monitor. A wide-eyed coworker looking
over your shoulder. You paused briefly, to let him know that you were aware of
his presence.

"How did you do that?" he asked, his voice filled with awe.

You smile, and prepare to utter the single word that changed your life. The
word that, should your colleague choose to pursue it, will lead him down the
same rabbit hole to a universe filled with infinite combinations of infinite
possibilities to produce a form of hyper-efficiency previously attainable only
in his wildest of dreams. He reminds you of yourself, standing in that
darkened computer lab all those years ago, and you feel a tinge of excitement
for him as you form the word.

"Vim."

:wq

~~~
cocoflunchy
I've never seen anyone using vim... maybe that's why I haven't had the guts to
switch yet.

~~~
solutionyogi
In that case, let me point to my SO answer where I share a videos of a Vim guy
in action.

[http://stackoverflow.com/questions/1088387/what-specific-
pro...](http://stackoverflow.com/questions/1088387/what-specific-productivity-
gains-do-vim-emacs-provide-over-gui-text-editors/1088802#1088802)

~~~
sunraa
Having toyed with Vim in the past I was never convinced enough to switch. I
guess I've never truly seen it 'in action'. I'll have to watch these videos.
Thanks for the link.

------
solutionyogi
I have been using Vim for over 3 years and I didn't know about the whole line
completion.

I think the best thing about Vim is that it will always keep surprising you.
If only we could find a life partner like that, there won't be any divorces.

~~~
jes5199
I've been using Vim for over 14 years and never used whole line completion. It
seems vaguely familiar like I might have seen it in the docs, but I've never
thought "hey, I'm gonna look up the keystroke for whole line completion!"

~~~
johncoltrane
Whole line completion is very useful when you write very repetitive languages.

In CSS, <C-x><C-l> is a gift of the gods.

------
calinet6
I understand Vim. Really, I do. I even know how to use it for the most part.

But I guess I just don't _get_ it. It's too obtuse. I don't feel connected to
my editing while using it, I feel... connected to Vim. Which, I think, might
explain why others feel so connected to Vim too. They get attached to it
because it's an investment, and as we know from various psych studies, we get
attached to things we invest in.

This isn't a bad thing, just wanted to throw my 2¢ out there. Vim's a cool
language for text editing, but it's not the only one.

~~~
solutionyogi
I completely understand where you are coming from.

For me and others, we actually feel connected to our text instead of Vim. Let
me give you an example, let's say I have following sentence.

"Why, oh WHY, do those #?@! nutheads use vi?"

my cursor is on the letter 'h' of 'nutheads'.

Let's say I decide to change the whole word to 'crazy people'.

Here's how you would do it in conventional editor (using EditPlus as an
example).

Ctrl + <\- (to jump to n)

Ctrl + Shift + -> (to select the whole world)

Shift + <\- (to remove the space which was selected. )

Type in "crazy people"

Here's how you would do it in Vim.

ciw - (change inner word), it gets rid of the whole 'nutheads' word and puts
me in INSERT mode.

type in "crazy people"

As you can see, EditPlus forces to you to navigate the text using conventional
method. It doesn't have a concept of a 'word'.

Compare this to Vim. I told Vim what I exactly wanted to do ('change inner
word') and it let me achieve that without any fuss.

As I wrote in my other comment, Vim lets me 'talk' and 'interact' with my text
at a semantic level. Vim is like a translator which completely disappears when
I am working with my text.

The example sentence was borrowed from another excellent article on Vim:

<http://www.viemu.com/a-why-vi-vim.html>

~~~
calinet6
Excellent comparison, thanks.

It's important to note that many modern text editors do have concepts of
"words" and "lines" and such that can be used in similar ways. Granted, not
near the extent of Vim, but they're still useful.

In sublime for example, I can Ctrl+Shift arrow to select words before and
after. This even works with multiple selection (multiple caret positions).
It's pretty cool.

Again, I understand that Vim is more of a language to describe editing text
and is very efficient, I'm just saying you can get close with modern editors,
and personally I find their visual language to work better for me.

~~~
solutionyogi
As z92 mentioned in reply, you missed my point about the fact that EditPlus or
Sublime will force you to move to the beginning of the word before you can
select it. Try the above exercise in Sublime and then in Vim so that you can
see the difference clearly. May be that will kick in that bulb in your head
and you will see Vim in a whole different light. Trust me, it took me a long
time before Vim 'clicked' for me.

~~~
calinet6
As the other reply mentioned, it's Ctrl+D, and there are many other ways to
accomplish the same things that Vim can do in general. Maybe one is slightly
better or more efficient, but they're really not that different.

Not to get into a holy war, but that's is one of the things I don't really
like about Vim—the community is pretty religious and Vim "can do no wrong" in
a sense. The process of conversion is just an epiphany and if you haven't
realized that, then you must just not have used it enough, because it's
factually better. Not really true. I'll leave it at that.

~~~
solutionyogi
I am sorry if you get the impression that we are trying to suggest that Vim
can do no wrong.

Your original comment was exactly how I felt when I was learning Vim. I also
thought that Vim is obtuse and it gets in my way. And now after using Vim for
over 3 years, I now know why Vim is the way it is and I was sharing my
epiphany.

By all means, use the editor which makes you most productive (you are already
ahead of 70% folks who don't even care to find better editor). But at the same
time, if you think that Vim is crazy, at least listen to the other side of an
argument with an open mind.

PS: I also replied to comment by 'recursive' on the Ctrl + D shortcut.

~~~
FuzzyDunlop
I think you just embodied the entire sentiment the GP was criticising: the
whole concept that _Vim is not an editor; it's a state of mind_.

I compel you and anyone else who is quite dogmatic about their choice of
editor to try explaining it in such an objective, non-patronising way, so that
the layman can think, "oh, it sounds like it's worth learning then."

I'm not a Vim user per-se, but I'd find more value in something like this,
possibly with a more specific follow up:

Vim works a bit differently than other editors. It cares more about
manipulating existing text than creating new text, and so it tries its best to
let you make changes without just deleting and re-typing from scratch, or
using your mouse to point and click and drag and highlight.

It has a steep learning curve so it's initially hard to adapt not just to this
change in perspective, but also to the commands and shortcuts that allow you
to be more efficient and productive.

Such is the investment of time and effort required to do be good in it, you
might consider grokking Vim a commitment as big as grokking your programming
language of choice. However, you will in return acquire a life-long knowledge
of working in Vim, and using it will become second-nature and infinitely
preferable to manipulating text by hand.

As a developer, knowledge of Vim is valuable because of two things:

1\. Portable configuration: what you learn, and how you personalise your
editor, is transferrable to other machines, as it's just text. No modern
editor has adequately replicated such basic functionality.

2\. Ubiquity: you can't load Sublime Text, Textmate, Eclipse, {$gui_editor} on
the VPS you routinely SSH into. You will, however, have access to Vim, or its
predecessor Vi. You can thus have a somewhat familiar environment when working
on remote servers, without any faff.

~~~
calinet6
This is a sublime comment. Thank you for writing it.

------
pdeuchler
This may just be me, but I feel that a lot of the productivity that Vim
supposedly creates is a result of programmers spending lots of time learning
one tool very well, as opposed to something inherent within Vim that
automatically makes you more productive.

That's not to say Vim doesn't have an excellent ecosystem, and has tried and
true ergonomic benefits, however I feel that if someone spent the same amount
of time learning, say TextMate (just an example, may not be the best), they
would be just as productive.

~~~
super_mario
Absolutely not true. The best description for VIM is "programming your text".
In VIM you have a set of commands that you use to manipulate text. Generally
commands looks like nOm where n is number of times to repeat the whole thing,
O is operator to apply, m is motion command/selection. So for example 3dw
applies 3 times the d (delete) operator to motion command w move one word
forward, i.e. delete next 3 words. The nice thing is if you learn lots of
motion commands you instantly learn lots of ways to manipulate text objects
based on those motions. Want to change inner if block in your code? Just type
ci{ (change inner { which deletes everything inside the {} block the cursor is
in and places you in insert mode. Etc.

In other editor you have keyboard shortcuts and there are only so many you can
have. In VIM there are over 1500 commands (not shortcuts). People who say "vi
key bindings" or "vi shortcuts" don't get vim.

~~~
mononcqc
My favorite form of this is when using regular expressions.

You have 'v' for visual mode, where you move the cursor around and can select
stuff.

You have 'd' to delete things.

If I press 'v' then move around, then press 'd', I'll delete the selection.

If I press 'vf,' it means 'select until you are on a comma'. If I press 'df,'
it means 'delete until you are on a comma'.

The problem with these two modes is that they're restricted to one line.

Now if I do 'v/,$', it means 'select until the first match of the regular
expression ',$' (comma on end of line). If that comma is 5 lines below, it'll
find it.

What's fun is that with this sublanguage, I can say 'dv/,$' and it will delete
where the selection of the next comma at the end of a line, or more generally,
<Command>v/<Regex> will do the command until a given regex. If I replace 'd'
with 'c', it deletes and puts me in insert mode ('c' is change), and so on.

Even nicer? what if I'm writing Erlang (I usually am), and I want to delete,
say 3 functions. I could delete one by getting to the beginning of the
function and delete until '\\.\n' as a regex (functions are terminated by a
full stop). So the command becomes 'dv/\\.\n' for a single function.

Rather than calling the same command 3 times, I can do it once, then press '.'
twice to repeat the previous ones.

Or I can use the fact that vim has this sublanguage and instead call
'3dv/\\.\n', which will delete until the next end of a function (full stop +
line break) 3 times.

Its command set is fully composable and at some point you find your sweet spot
in there.

~~~
hetman
That is an awesome tip! One question: is there any reason why you do 'dv/,$'
rather than just 'd/,$'?

~~~
mononcqc
They both work absolutely fine. I tend to use d/<regex>, but the dv/<regex>
example highlights the sublanguage and composition a bit more :)

------
pbiggar
I used vim for about 10 years before I finally gave up, and it was completion
that did it for me. It was just so ludicrously hard to customize vim (writing
vimscript - although the python integration wasn't much better) that it hurt.
I was held back by not being able to customize it, and the fact that I
couldn't get any better completion than ctags was insane.

My startup Circle is written in Clojure, so I was pretty much forced to learn
Emacs, and the world is such a nicer place. I really wish I had learned Emacs
5 years ago - with the time I spent mastering and then trying to customize
vim, I could have mastered and learned to properly customize emacs.

------
riannucci
Also, SuperTab is all of the win: <https://github.com/ervandew/supertab/>

It'll let you use <Tab> for all the completion types, and you can tell it the
fallback order for various thing (i.e. try omni, then <C-N>, etc.). It's even
slightly context aware, so it can guess a good first completion method for
you.

All with <Tab> :)

------
exDM69
Nice overview of vim's completion features, but...

This article is very incomplete, there are various completion modes. I also
don't recommend mapping complete to tab (or even using SuperTab or other
completion plugins). Vim has a total of 13 different completion modes (see
:help ins-completion), all of which are useful. There's complete on local and
global keywords, complete for complete lines or filenames.

In particular, this article calls Vim 7's omni complete (^X^O) "syntax aware
complete" which it is not. It's a language specific completion, which can
complete stuff like members of structs or functions. You need your language
specific plugins to be installed. Vim ships with a decent plugin for C and
C-like languages, which works if you have a ctags database generated (:help
'tags').

If you want syntax completion, you can map it to user-defined completion
(^X^U) like this: set completefunc=syntaxcomplete#Complete

It's not particularly useful as such, because syntax complete completes
keywords like "for" and "while" which we all have in muscle memory.

------
johnchristopher
Using the article completion method it turns out that I can no longer use
<tab> to insert a <tab> since it displays a list of word to be completed.

It might be due to my vim configuration but I doubt it (though I am not a vim
script expert by any means).

Here is a function I found on the web a long time ago and that seems to
prevent that problem:

    
    
      inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
    
      function MyTabOrComplete()
        let col = col('.')-1
        if !col || getline('.')[col-1] !~ '\k'
          return "\<tab>"
        else
          return "\<C-N>"
        endif
      endfunction
    

No idea how it really works, I never investigated.

Credits/source: [http://www.slideshare.net/andreizm/vim-for-php-
programmers-p...](http://www.slideshare.net/andreizm/vim-for-php-programmers-
pdf) slide 44

edit: formating and credits

------
baggers
Though this doesn't help with the holy wars, I do find it just fantastic that
there are two editors that so many find, with an acceptable amount of playing,
can be the near perfect tool for their craft. I played with vim first but
never quite got a flow going...oddly enough I hit it off almost immediately
with emacs, it was still damn confusing but I made much more progress much
faster. I'm almost disappointed I didn't fall for Vim as it is always on any
server I have to use and emacs muscle memory has only compounded my problem
with Vim shortcuts! For those not fancying diving into vim or emacs are there
any more traditional IDE's with a way to script new behaviours and have them
feel native?

------
jes5199
There's something weird about the ^P/^N menu - I always have trouble telling
which possible completion is selected in the list, and I often end up picking
the wrong one.

~~~
solutionyogi
May be it is your colorscheme.

I took snapshot from my current editing session:

Selecting the last item:

<http://i.imgur.com/dEkws.png>

Selecting the second last item:

<http://i.imgur.com/D6Icl.png>

My vimrc is here: <https://github.com/SolutionYogi/VimSetup>

~~~
jes5199
yeah, I should tweak it somehow. This is what the (otherwise amazing) inkpot
theme looks like: <http://imgur.com/TaUym> \- can you tell that the dark, bold
entry is selected?

~~~
solutionyogi
I don't know which entry is selected (because I don't know the color scheme)
but those two items have very distinct colors and I would definitely be able
to differentiate between them.

I think you should experiment with some other color scheme or try to tweak
your existing scheme.

------
sirdavidoff
Moving to vim from TextMate, I found that I missed TextMate's autocompletion.

In Vim you have to specify whether the word you're looking for is above or
below the cusror (using C-P or C-N). IIRC, TextMate just looks for the closest
matching word, no matter where it is.

I wrote a little plugin to do make it exactly that:

<https://github.com/sirdavidoff/vim-nearest-complete>

Disclaimer: totally rough and not (yet) very customisable

------
JangoSteve
> For example, in HTML vim should know that you can’t nest a div inside an
> a...

In HTML5, you can. See <http://html5doctor.com/block-level-links-in-html-5/>

~~~
johncoltrane
That.

And isn't it the job of the programmer to know those things?

------
wiradikusuma
i'm a java IDE user (eclipse, then intellj).

in intellij, you can ctrl+w to select word, ctrl+w again to select statement,
ctrl+w again to select function, etc.

you can also refactor replace all, shown if foo.gif actually exist in img src,
ctrl+click to css, shown if a variable (in code/js/css) is unused, hinted if a
line can be simplified, etc.

can vim do that?

if it can not, what's the compelling reason for people like me to use it? (i
honestly interested, but wondering if it's worth the effort)

~~~
ohhmaagawd
I use Intellij (and the derivative editors RubyMine and AppCode) as well.

IMO the main advantage of vim is it's instant. No waiting for the IDE to load.
IJ takes quite a while to load and you have to have your project set up.

Another major advantage of vim is it's available everywhere. SSH to your
production server and edit just like you do your code.

But I have to say: I much prefer coding in the Jetbrains editors. They offer a
UX that can't be matched by vim. They are just smarter, esp for statically
typed language. But even dynamic - they are damn good. And you can use VIM key
bindings if you like.

------
mun2mun
Also checkout neocomplcache, <https://github.com/Shougo/neocomplcache>

------
ChuckMcM
We never saw poetry written about TECO.

------
va_coder
I didn't know this one: ^X ^L

------
gubatron
"Fuck VIM" -Richard Stallman

