

Ask HN: Power of VIM? - hajrice

Right now, I use Notepad++. I've been thinking of switching to vim. I'd like to know ... why? what's the power of vim? how can it increase your productivity?
======
grayrest
A few specific examples (| is cursor position):

* You have a function call: `|foo("blah", blah)` and want `bar()`. You type `c%bar()`. The `c` command means 'replace' while `%` searches forward for a matching character and jumps to the closing.

* You realize (after the fact) that you have a few more calls to foo. You type `/\<foo` and enter to jump to the next word in the file starting with foo and hit `.` to repeat the last edit. Then `n` to search for the next match and `.` again to repeat, etc. Since the vim command syntax is really expressive, repeat becomes a very powerful tool if you're doing it right.

* You have `my_dict['ab|cd']` and want `my_dict['efg']`. You type `ci'efg`. That's replace (c) inner (i) single-quoted string (') with efg. If you then wanted to change the single quotes to double quotes and had the surround.vim plugin, you type `cs'"`, which is replace (c) surrounding (s) single-quotes (') with double-quotes (").

* You have `fooTransformer(blah)` and want `barTransformer(blah)`, you type `ctTbar`, which is replace (c) 'till character (t) T with bar.

I've been deliberately using the replace command for these examples, but what
makes the vim command syntax neat is that the command and the motion parts are
orthogonal. So you could replace the `c` in any of the above examples with `d`
to delete or with `y` to copy (yank) or with g% to rot13 or whatever.

It may seem like relatively small gains, but the most important thing is that
I stay in the flow of the code. If I think "replace call" I type `c%`, which
is only slightly slower and far faster than trying to ctrl+shift+arrow my way
through the codebase.

The downside of Vim is that the learning curve is very, very long and is
initially steep. Unless you're coding for a couple hours a day, it's honestly
not worth it.

One tip that everybody eventually learns but is almost never metioned in
beginner tutorials: Whenever you stop typing, go back to normal mode (use
ctrl-[ or remap insert mode ctrl-j to Esc for more efficiency). This will
eventually become automatic and will help you to avoid mode errors where you
think you're in normal mode but you're actually in insert/replace mode.

~~~
crazydiamond
I loved your my_dict tip: ci' - new to me. Thanks.

Here's my favorite: <http://rayninfo.co.uk/vimtips.html>

------
yan
I use vim over other editors because I feel vim is a good tool. I know it's a
good tool because it gets out of my way and lets me interact with text without
having to trick an editor into doing it, which is how I felt with editors like
Notepad++ and others like it.

It took me a while to get to this point, but I feel the investment was worth
it. Just take a week and force yourself to use nothing but vim (and try
learning as many features as you can) and see if it jives with how you think.
If it doesn't, try emacs.

edit: Best way to see the power of vim is to watch someone edit text who's
proficient with it; some people are so good with it you'd be convinced they
mmap()'ed the file to their head and are just interacting with it in real
time.

------
MWinther
For me, one of the reasons of getting into basic vim usage was that it was the
only editor I could count on always being available on the machines I was
administrating. I learned just enough to be able to edit files with vi when
necessary and did the heavy lifting in emacs.

Just a week or so ago, I decided to try to see if I could switch over to vi
for all my editing needs. I know people who really know vi are wicked fast at
doing stuff in it, none of the additional functionality in emacs is really
something that I'm using, and none of the GUI-based editors I've used have
really done anything to convince me they're worth the extra hassle. Plus, I
know it's available on all platforms I could conceivably need that sort of
text editing, so I know my skills will be usable wherever the file might be.

------
nfnaaron
It's easy to tell you why: powerful and precise text manipulation through
concise commands. It's difficult to make you value that until you've tried it.

Vim will increase your productivity by allowing you to manipulate large or
small pieces of text at will, in ways you've probably not thought of, while
your hands rarely leave their position of hovering over the home row. The
arrow keys work, but you'll rarely use them. You'll be fast, not from fast
typing but from _less_ typing.

Once you've become reasonably proficient with vim, the difference between
arrow key-based editors and vim begins to feel like the difference between
chisels on stone and telekinesis.

It's easy to become minimally proficient. After you've installed gvim, run it
and run these two commands:

[ESC]:help

[ESC]:help tutor

You should know about the first command, but the second is more important for
you right now. It shows you how to start the interactive vim tutorial on your
system, which will teach you just enough to use vim better than you can use
Notepad++. Follow the tutorial, it won't take long and you don't have to do it
all at once.

Now use vim whenever you edit a text file. You'll be a little slower than
Notepad at first (but not much). You'll quickly gain speed.

The vim screencasts mentioned elsewhere in the comments are good for people
learning vim, but I don't think they're a great advertisement for vim. The
best thing for you is to run the tutorial.

Note: everything said here goes for emacs as well. It's a personal choice, and
most people are either a vim person or an emacs person. I've never liked the
chord-like commands of emacs, but emacs has more integration with the world
outside of text editing and compiling than vim. Whichever type of person you
turn out to be, you should be using one of these instead of Notepad.

Note note: I like vim so much that I've installed a firefox addon that lets me
quickly edit web page text fields (like this one) with vim.
<https://addons.mozilla.org/en-US/firefox/addon/4125>

------
lukeqsee
Why not Emacs? Just kidding.

vimtutor will answer a lot of your questions.

The kernel of the matter is the ability to do everything from the keyboard.
You never have to use the mouse. That allows things to be much faster. That is
a gross oversimplification, but I hope it helps.

------
bediger
Probably just a few things contribute to most of the "productivity" you can
get from vim:

1\. Commands to move around the screen and file under edit: with at most 2
keystrokes you can (a) move to next word (b) move to previous word (c) move to
start of line (d) move to end of line (e) move to start of file (f) move to
end of file (g) move 1 character in any direction (h) move to the end of next
word (i) move to end of previous word (j) move to the next word like the one
under the cursor (k) move to the previous word like the one under the cursor.
Other commands exist to make moving around really efficient: you rarely take
your hands off the keyboard to do mousing.

2\. Use of regular expressions for searching for text, and as a way of
distinguishing edits. You can do things like change all tabs to 4 spaces with
a single command, or change the tabs at the beginning of the line to 4 spaces.
This is an astoundingly powerful idea, rarely exploited however.

3\. Vim, improving on vi, has the "visual" modes, where you can use movement
keys (see item 1) to choose a hunk of a file, then apply edits or change
commands to that block.

4\. Vim isn't really modal like all the propaganda has you believe. Sure, 'i'
or 'a' or 'I' or 'O' will put you in what you can naively interpret as
"literal typing mode". But you should really think of those as commands,
followed by text, as you can do 5Ax<esc> and append 5 'x' characters to the
end of the line. If you think about what most people call "modes" correctly,
you can pull off a lot of interesting and fast edits.

5\. It's fast and has very few built-in limits (line length, file size, window
size etc etc).

------
icey
Someone steal this idea: A site with screencasts of people writing software in
the editor of their choice. Let people browse videos by editor, programming
language, whatever else.

~~~
cscotta
There is a great collection of Vim screencasts at: <http://vimcasts.org/>

Peeepcode has a "Meet Emacs" screencast available for about $9 as well here:
<https://peepcode.com/products/meet-emacs>

It's not quite the site you describe, but I've learned quite a bit watching
Vimcasts.

~~~
akmassey
I'll second the support for vimcasts.org.

Also, PeepCode released "Smash Into VIM" yesterday:
<http://peepcode.com/products/smash-into-vim-i>

------
claytron
Three reasons for me.

1) The power of the editor. Lot's of great resources to learn more about it on
the web or in vim itself. I learn something almost every time I read an
article about it or watch a screencast. The learning curve is steep at the
beginning, but totally worth it. I bookmark a lot of them on delicious:

<http://delicious.com/claytron/vim>

2) Portability. I use the same configs on FreeBSD, Arch Linux, Debian, Windows
and OS X. I'm not tethered to an OS anymore for my fancy editor anymore (read
TextMate). Not only is it portable, but it works mostly the same from the
command line as it does in the GUI version. Having a full fledged editor on a
remote machine is priceless :)

I made the switch about 6 months ago after switching to Linux for my dev
environment. The only other editor I would consider using is emacs, for the
same reasons.

3) The crazy world of vim. It's not just for writing code, I use vim
everywhere possible now. Command line is bound to vi bindings, Vimperator in
Firefox, It's all text to edit the web and external editor in Thunderbird to
write emails. In fact, I'm writing this in vim right now :)

------
dejan_dimic
If You are coming from the Windows world and use Notepad++ you are definitely
on the right track to find a good text editor. I know since I have make that
same path long time ago.

Now on all my systems that are mostly Linux (Ubuntu) and Windows I use Vim
(vim & GVim).

I like to have powerful editor in all situations on all machines that I work
and vim is that first.

The greatest feature is that hands are on keyboard all the time and as You
learn the vim features You get amazed all the time and get more productive in
every iteration.

The learning curve is easy and the most surprising at first is switching vim
modes. That is adopted very fast and all that follows is fun and enjoinment.

Naturally all depends on Your affinity and if You spend lot of time in text
editor dealing with different formats of text (HTML, xml, CSS, js, C#, Ruby,
Php, C++, java, ...) You should invest some time learn to have real power on
Your fingertips.

------
crazydiamond
I wish vim would provide a _kill-ring_ like emacs. I was recently writing an
editor for an app of mine on the terminal. To enhance the keyboard usability -
I read up on and implemented (among others) the kill-ring, it was easy to do,
and really makes work easier than having to use registers. (kill-ring is for
copying and yanking, multiple yanks go into the ring, and the values can be
cycled through).

------
mikeleeorg
I think it ultimately depends on your personal working style. Some advantages
to vim are:

\+ it's simple UI (all text-based)

\+ it's lightweight

\+ it is modal (which can be easier if you're a touch typist)

\+ you never have to use the mouse (just like what lukeqsee said)

\+ lots of plugins exist to enhance the functionality

Hope this helps!

~~~
waffenklang
\+ it's much more dynamic with integration of compiler than any other editor
(I know) and supports even integration plugins for gdb

\+ it will help you prevent mistypings during other actions (thanks to insert
mode) and sometimes I think it even helps to write better code.

------
bho
Here is a good posting on StackOverflow regarding Vim:
[http://stackoverflow.com/questions/1218390/what-is-your-
most...](http://stackoverflow.com/questions/1218390/what-is-your-most-
productive-shortcut-with-vim/1220118#1220118)

I started last week and am trying to learn everything i can.

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

<http://blog.ngedit.com/2005/06/03/the-vi-input-model/>

------
theonetruebob
I forced myself to learn vim because I wanted more power than nano would give
over ssh, but this is what got me to replace my gui editor with gvim:
<http://vimeo.com/8569257>

------
sirwitti
for me it's about speed. you can do almost every task you need as a programmer
way faster with vim, than with a conventional editor. if you have some
programming experience you can change its behaviour to exactly the way you
like it. <http://vim.wikia.com/wiki/Best_Vim_Tips> if you really like doing
things with the keyboard, vim will be the right thing for you...

