

Vim: from n00b to meh - tsironakos
http://dtsironis.net/posts/how-to-vim/

======
gamegoblin
I got pretty proficient at vim using basically the defaults (I added tabs to
spaces and tab width to 4 spaces, and auto/smart indent in the .vimrc). These
are the keys I use regularly. If you can memorize these, you can use vim
proficiently:

    
    
      h/j/k/l (movement keys)
      i (insert mode)
      esc (leave current mode/go to default state)
      u (undo)
      >> / << (indent, unindent)
      dd (delete line)
      yy (copy line)
      p (paste)
      v (visual mode, used to highlight stuff)
      gg (go to beginning of file)
      G (go to end of file)
      r (replace the char under the cursor with the next char entered)
      % (jump to next paren/bracket, or if on a paren/bracket, jump to matching paren/bracket)
      w (go to next word)
      dw (delete word)
      cw (change word (deletes the word then goes into insert mode))
      A (append (goes to the end of the line and into insert mode)
      0 (go to beginning of line)
      $ (go to end of line)
      /some_word (searches for some_word, hit n to jump to the next occurrence)
      ?some_word (searches for some_word, in reverse direction)
      

Common commands:

    
    
      :%s/regex/replacement/g (replace regex matches with replacement)
      :q (quit)
      :q! (quit without saving)
      :w (save)
      :wq (save then quit)
      :x (save then quit)
      :set blah (turns on setting blah)
      :set noblah (turns off setting blah)
    

Most vim commands you can stick a number N before to execute N times.

e.g. 5d deletes 5 lines. 5y copies 5 lines. 5> indents 5 lines. 5j jumps down
5 lines. Some common command combinations:

    
    
      %v%> (jump to next bracket, go into visual mode, jump to next bracket (highlighting everything in between), then indent it all)
    
      ggdG (jump to top, then delete everything to the end of file, (clears a file))
    
      ddp (deletes a line of text and then pastes it (below where it currently it), thus this transposes two lines)
    

You can see how you quickly develop strings of commands you rattle off by
chaining basic commands together.

EDIT (joke):

Q. How do you algorithmically generate a cryptographically strong random
string?

A. Put a newbie in front of vim.

~~~
dmix
I have a scenario that I need help with in VIM: switching between 2-3 files
while working on them simultaneously.

For ex: working on an HMTL+CSS+JS documents all at once. Assuming smaller
screen where I can't have a vsplit screen.

How to I jump between them quickly? Buffers/tabs?

I love VIM but I haven't found a good tab/file switching solution. In Textmate
tabbing was straight-forward. VIM doesn't seem well suited for tabs
(especially with things like NERDTree and control-p).

~~~
pilgrim689
I don't have any plugins for this stuff. I just do:

    
    
        nnoremap <Leader>b :buffers<CR>:buffer<Space>
        nnoremap <Leader>n :bn<CR>
        nnoremap <Leader>p :bp<CR>
    

My <Leader> is space. So "space+b" opens up my buffers, I type a few letters
that match a file and Tab to autocomplete it, then press enter to open it. I
also use ctrl+shift+6 to quickly switch between the 2 most recent buffers.

So I'd give that a shot. If that doesn't work for you, try just ":tabe <file>"
for your three files, then ctrl+pageup, ctrl+pagedown (or gt, gT) to quickly
switch between them.

~~~
dmix
Thanks this is working for me.

I just switched b/p (since I use p w/ ctrl-p as a fuzzy finder to list all
files).

------
bgar
I use Vim but I don't understand why people try to force themselves to use it.
If you are comfortable with another editor, then go ahead, keep using it.
Everyones treats Vim as if it's some hallowed apex of programming ability, and
that eventually you have to be weaned from your inferior Sublime or Textmate
usage. Sure, Vim is awesome, but the idea that you _must_ sooner or later
learn it is wrong. Unless of course you really are interested in Vim for what
it offers and not just for its reputation.

~~~
NovaS1X
I got interested in Vim for both what it offered, and its' reputation. It took
a while to get used to but now I can't live without Vim controls; it's just so
efficient.

It's gotten to the point where I use a tiling window manager on my Linux
distro with all controls Vim style. I have a Firefox add-on to give it Vim
controls [1], and I use Vim for basic word processing. I can control almost
every part of my OS, excluding Skype, purely through my keyboard with
virtually no mouse involvement.

It's all very addicting once you get used to it.

1: [http://5digits.org/pentadactyl/](http://5digits.org/pentadactyl/)

~~~
kazagistar
I really want to see some measurements of the efficiency of vim. Because we
[know]([http://www.asktog.com/TOI/toi06KeyboardVMouse1.html](http://www.asktog.com/TOI/toi06KeyboardVMouse1.html))
that people's perception of time taken when using keyboard shortcuts is
skewed: using keyboard shortcuts makes you perceive your actions as faster,
even in those cases where they are not. Thus, I hear a lot of people say good
things about vim, but it is difficult to merely take their word for it, since
it might very well be that they think they are faster then they are.

~~~
WizzleKake
Vim and using the keyboard isn't about speed. It's about precision.

Also: many text editing actions can go from conscious (using a mouse) to
subconscious (using the keyboard + muscle memory).

------
paozac
In the last 15 years I remember having used as my main editor: TextPad, Vim,
KEdit, Textmate, Vim (again), Sublime Text. I consider myself a decent vim
user, but went back to non-modal editors, they feel more comfortable to me. My
muscle memory works best with "synchronous" keyboard shortcuts (ctrl-alt-
shift-whatever) rather than "fluent" vim-style commands like ciw, ct" etc,
that require a mental context switch.

It's important being able to use vim, because sooner or later you'll edit some
files on a remote server, but I don't understand the enthusiasm of so many
people for it. Vimscript is horrible BTW.

~~~
clarry
There are other editors out there. I edit files on remote servers regularly,
but I've _never_ used vim for that.

------
DigitalJack
I highly don't recommend using a starter kit, and particularly Janus. Janus
started out ok but quickly morphed into an amalgamated mess of crap.

The only thing I recommend is Pathogen which keeps addons modular. From there
only add things to the baseline as needed.

~~~
bgar
I agree so much with this. When someone new to Vim touches it they should
start out with a blank slate.

~~~
ethanazir
and then you start bind and learning key patterns that are sub-optimal

------
ethanazir
this title suggests , meh, that you lost interest in vim but the article seems
to state otherwise...

------
autoreverse
Try the Vimium plugin for Chrome for a bit of fun.

[https://chrome.google.com/webstore/detail/vimium/dbepggeogba...](https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb?hl=en)

------
akurilin
Read Practical Vim published by the Pragmatic Bookshelf. You'll go from n00b
to "pretty good". Takes a long time to work your way through the text, as it's
both thick and very dense, but every single page will empower you further.

------
rDr4g0n
I wonder what the author didn't like about sublime text's vintage (vim) mode?
I have not used vim, but i have been using vintage mode for about a month now
and really love it. I grab my mouse occassionally, but mostly stay out of
insert mode and navigate with movement keys. Plus I still have my sublime text
environment that I've built up for the past 2 years.

I don't think I could've made it this far by diving in head first. Like it or
not, I have to get work done, and when I couldn't get a motion to work right
or didnt know the best way to do something, I could fall back on sublimes
regular tools.

~~~
tsironakos
When I tried the vintage mode in Sublime Text, I already had some knowledge
about vim and its behavior. I find that the vintage mode was restricting me,
which exactly the opposite of what it's supposed to do.

> I don't think I could've made it this far by diving in head first.

That's exactly my point! Take it easy and don't go hardcore from the first
day. You'll get annoyed right away and you'll go back to Sublime Text in 10
mins.

------
wmalik
I wouldn't recommend using a vim distribution. They have some good features
but they also tend to add bloat to your vim and make it slow. They also impose
a certain workflow which might not be suitable for everyone. I have been using
vim full time for more than an year now, I started with an empty vimrc. Now I
have about 200 lines, and I added all of them on a need basis. Text editor is
the most important piece of software in my workflow (or probably any
developer's workflow), so I want it to behave exactly like I want.

------
jdkanani
I would suggest not to use anyone's configuration, add config/plugin as per
your need. And yes, don't forget to take a look at
learnvimscriptthehardway.stevelosh.com

------
johncoltrane
First mistake: starting with someone else's config.

Second mistake: using a distribution.

Third mistake: forking a distribution, itself built by amateurs, after only
three months and advertizing it on the net.

Seriously, when did parents stop teaching the value of patience (among other
values) to their kids?

 _You_ are the one in charge of _your_ config, people, not some random guy on
the internet.

------
Tomis02
So many people talk about learning vim, vim philosophy, getting proficient at
vim, changing your workflow so that you can use vim better. You what this
sounds like? A cult.

Vim is a (surprise surprise) text editor, not a way of life. It's perfectly ok
not knowing how to use vim and being put off by how awkward it feels. It's
perfectly ok to use notepad++ or sublime text or whatever else you are
comfortable with.

To my knowledge nobody gets paid to use vim instead of some other editor;
money comes from lines of code. It does not matter that you use vim, it does
not make you a smarter person or better programmer (I should know, I often use
vim at my work place).

On the same note, it does not matter how cool you think you are when you
manage to persuade git to do some complicated thing in a two liner command
which could be achieved in svn or hg in two words, you are just being silly.
Being proficient at vim/git when your job doesn't require it is like being
able to rotate your left and right eyes simultaneuosly - one clockwise, the
other counterclockwise. It's very funny/interesting, but utterly useless.
Forcing yourself to learn vim for vim's sake or because you read on the
internet how cool vim is and how 3l1t3 vim makes you is one of the things
you'd be better off avoiding. Again, I should know.

Seriously, don't drink the Kool-Aid.

~~~
Walkman
You probably don't understand well enough how big a difference these tools can
make in your efficiency. Of course number one priority is to know the
technology, nobody argues that.

~~~
Tomis02
In my experience, when working with anything but very small projects vim is a
liability. Vim's main feature (speed of editing) is of marginal use when you
only write about 10 LOC per day (as I would say is still the case 40 years
after The Mythical Man Month was published, at least on average). The time
when you're not writing code (which is most of the time) is used switching
back and forth between files, going to declaration/definition,
debugging,(auto)refactoring, changing between project configurations and so
on. All this is very difficult to do with vim since it comes naked out of the
box and you need to use all sorts of crutches to make is resemble a modern
IDE. And when you switch another machine all you usually get is another
barebones vim.

For instance, when working on a C++ code base, vim will never come close to
the ease of use of Visual C++. It might be better at "delete 2 lines starting
at line #256", but that's about it. This can be improved by plugins that most
of the time will not do exactly what you'd like them to do, so you will have
to "adjust your workflow" to work around that.

My original point was about using tools because it's cool or because the
internet said so, and there's load of stories where people buy into how good
vim is and then after a few months they still don't 'get it' so they are told
they're doing it wrong (or just not smart enough). Ditto for git, lisp and
other silver bullets.

If you ask me, if efficiency were important people would be using hg instead
of git most of the time because most of the things you can do in git you can
do easier/simpler in hg - at least for the most usual cases. After a short
intro to hg people will keep using it happily ever after, whereas the git user
will keep coming back to StackOverflow questions to find out how to hard reset
to head after rebasing from origin and rewinding. Speaking of SO, this quote
matches my thoughts exactly:

"It seems to me, that people using Mercurial are not so easily impressed. This
is reflected in how each system do what Linus described as "the coolest merge
EVER!". In Git you can merge with an unrelated repository by doing: git fetch
<project-to-union-merge> GIT_INDEX_FILE=.git/tmp-index git-read-tree
FETCH_HEAD GIT_INDEX_FILE=.git/tmp-index git-checkout-cache -a -u git-update-
cache --add -- (GIT_INDEX_FILE=.git/tmp-index git-ls-files) cp .git/FETCH_HEAD
.git/MERGE_HEAD git commit

Those commands look quite arcane to my eye. In Mercurial we do: hg pull
--force <project-to-union-merge> hg merge hg commit"

I would like to read your insights related to efficiency.

~~~
tommorris
Part of speed of editing for me is low RAM usage. When I'm doing web
development, I tend to have a few browsers open (at least Firefox and Chrome),
running web servers and databases, or the same in a Vagrant-managed VM.

When you've got a browser or two and a Linux VM running, finding the extra
500Mb for an IDE can be rather taxing. I've tried IntelliJ, Eclipse and
NetBeans. Always end up coming back to MacVim, saving a few hundred megs of
RAM and not really getting any significant hit in productivity.

I was trying out PyCharm the other day (IntelliJ's Python IDE) and it was
unable to keep up with my fingers. The text was lagging a I was typing it in.
What was I getting from the IDE? Debugging? I know my way around pdb, haven't
got time to work out how the IDE fucks that up. File navigation? I've got
Ctrl-P. Changing between project configuration? Meh. Got Vagrant for that kind
of thing anyway. That leaves autocomplete (can take it or leave it. Not
bothered.) and refactoring (mostly I use Python and Ruby at work, so mostly
it's a shit show anyway IDE or not).

Even on Scala projects, I've gone in thinking "IDEs are the answer" and ending
up back in Vim after a few hours of flailing around trying to get the IDE to
talk to the compiler.

Agreed on Mercurial though. I like Git, I like Mercurial. Both have upsides
and downsides. More important is that we are finally moving away from
centralised VCS.

~~~
Tomis02
I understand where you're coming from and I concede that you might be more
efficient with your current setup, but I disagree about the debugger. Pdb, gdb
and any other command-line based *db-s are what people first started using a
few thousand years before entering the stone age. I've used gdb extensively
and I can tell you there's no substitute for a good IDE where you can see the
code, variable values, stacks, threads and watches, all at the same time; it
makes life so much easier. It can be done in the old fashion way but there's
nothing to gain from it.

On the other hand I haven't seen any good free Python IDE-s (like Visual C++
is for C++) and you are sometimes forced to use pdb for the lack of a better
option (Python Tools for VS are decent but took me a lot of time to setup
properly and I didn't like the workflow). That said, the lack of good tools
doesn't mean the old ones are good, only that the language lacks good tools,
mostly because people get used to the stone age tools. And sadly that is the
case for a lot of programming languages.

~~~
tommorris
Well, JetBrains have now made PyCharm3 Community Edition, which is free and
open source, and they are charging for the premium edition with support for
web frameworks like Django, Flask and Pyramid.

The RAM thing still bites. When I get a new laptop in a year or so, I'm going
to go all out on RAM. :)

------
vinceguidry
I don't understand the hoopla about editors. It takes me eight hours to write
a half page of code. That half-page is well-understood, bug-free, and
accomplishes the mission. The more I learn, the less I write. I don't want
tools to help me write faster. I want tools to help me understand what it is I
am writing.

~~~
aerique
While I agree with most of your points it does matter to me that I can do the
few editing actions I do quickly otherwise it breaks my concentration of
focussing on the code.

I also need to be able to navigate the code quickly but that might be part if
your "tools to help me understand" remark.

~~~
vinceguidry
> I also need to be able to navigate the code quickly but that might be part
> if your "tools to help me understand" remark.

It often takes me 20-30 minutes to edit a single line of code. Understanding
why I need to change the program, what the effects of making that change are,
determining which line of the code to edit, figuring out whether I need to
edit or refactor, spending time in a REPL to test the proposed changes...

I just use the mouse.

~~~
aerique
For me, part of getting that understanding is navigating the code and I do not
always have room for another window on my screens.

It seems we have different approaches to working on code, or perhaps we just
use different language. The main languages I currently work in are: Common
Lisp, Python, JavaScript and C++.

------
bayesianhorse
I've been a Vimp too... I knew about vim for years, sometimes trying the
switch, but it never stuck.

By now, it did stick. What finally convinced me the most is that a lot of
really smart people not only use it but have developed a fierce loyalty to
this text editor.

------
rsamvit
One of the best resources I used to build up my vim customizations was
probably this video
[http://www.youtube.com/watch?v=xZuy4gBghho](http://www.youtube.com/watch?v=xZuy4gBghho).
It's got a lot of good stuff in it

------
TheLegace
I want to learn Vim, but I cannot even dream to remember even the most
primitive commands.

~~~
adambard
There is definitely a basic set of commands to remember, but the real power of
vim is that it forms a succinct and consistent text-editing language where
complex operations can very often be synthesized from what you already know
about it.

For example, there are a set of commands that move the cursor in different
ways (beginning of line, end of line, first line, last line, line #x, next
word, previous word, etc. (that's ^/$/gg/G/g#/w/b) ), and a set of commands
that performs actions (copy, cut mostly (y/d)). The real magic is how the two
sets interact.

I don't have to memorize the sequence of keys to delete a word; I know the key
to cut (d), and the key to move a word forward (w). I press d, then w, and the
word is gone! It's a whole world of editing possibilities.

My secret shame: since I use GUI vims almost exclusively, I've never developed
the muscle memory for hjkl movement; I use the arrow keys. When I started out,
I knew i, esc, and that, and I figured out the rest as I needed it.

~~~
leephillips
I think the real joy of vim is in the next level, when you start depending
less on movement commands in favor of text objects.

~~~
ethanazir
or you try to finish your HN comment with :w

~~~
leephillips
Yeah, vim follows you everywhere. I'm forced to edit someone's Word document
and I have to erase the vim commands that I embedded in the text. Etc.

------
EricDeb
Is it a big switch from ST2 with vim bindings to straight vi?

~~~
pekk
Yes. Why use vi over vim?

~~~
EricDeb
sorry.. I meant vim not vi.

------
wildermuthn
I've been using Vim for a few weeks now, and the biggest time saver is not
having to use FTP or Mac Finder. I can do everything from the terminal now.

~~~
contingencies
If this is a serious comment then please be advised everyone else stopped
using FTP 10 years ago. For the love of god, at least use _sftp_ , but
preferably check out
[http://www.scribd.com/doc/120792448/CI](http://www.scribd.com/doc/120792448/CI)
which is the way things are going (use _git_ before deployment, CI handles the
after). If you are just getting in to terminal stuff, then try Viscosity,
SourceTree, iTerm, _brew_ and _opendiff_ on OSX. Once comfy, do consider
moving to a desktop running a source-oriented distribution of Linux instead...
despite the setup hassle, it's far superior and will force you to pick up
loads of useful knowledge in a slow and manageable way. Hell, we even have
Steam these days!

~~~
wildermuthn
Everyone stopped using FTP 10 years ago? Pretty general statement, one I know
to be untrue because most of my non-profit clients still use FTP.

But I take your point, and on my own projects, I stick with git, grunt, and
rsync. Not a fan of SourceTree, and now that I know Vim, I can use git diff to
good effect.

------
helloTree
... and one should always remap ESC. For me this was a big improvement (from
an ergonomic viewpoint). My suggestion:

imap jf <ESC>

------
shandip
I don't understand this nostalgia with shell editors, just move on and use
something like sublime text.

