HN2new | past | comments | ask | show | jobs | submitlogin
Ask HN: What's the best way to get started with Vi(m)
49 points by sh1mmer on April 27, 2010 | hide | past | favorite | 41 comments
The title says it all. It's one of the things I've been meaning to do, but never quite did. Any suggestions? I'm a TextMate power user currently.


I think with something like Vim it's best to get a grasp on the very basics (saving/opening documents, moving into and out of insert mode, navigating with hjkl) and then add one of two things at a time as you get comfortable with those. If you try to do everything at once you just end up getting overwhelmed.

I didn't really start to like Vim until I started playing around with my .vimrc file. There were too many minor irritants and things I wanted changed. An Ask HN on the subject came in very handy: https://hackernews.hn/item?id=856051

Mine (along with a few other minor customizations) is at http://github.com/samdk/vimconf/blob/master/dotvimrc if you'd like to take a look.

Some other good resources: http://dotfiles.org/.vimrc http://www.vi-improved.org/vimrc.php


In addition to all the excellent suggestions here, I will also suggest reading the free book "A Byte of Vim" (http://www.swaroopch.com/notes/Vim_en:Table_of_Contents).

This is how the book introduces itself:

"A Byte of Vim" is a book which aims to help you to learn how to use the Vim editor (version 7), even if all you know is how to use the computer keyboard.

The first part of this book is meant for new users who want to understand what Vim is and learn how to use it.

The second part of this book is for people who already know how to use Vim and want to learn about features that make Vim so powerful, such as windows and tabs, personal information management, making it a programmer's editor, how to extend Vim with your own plugins, and more.


Byte of Vim is one of the Best technical writings for newbies and pros alike. I had a wonderful time reading it and the way I use vim after that has changed a lots!


Type `vimtutor` on your command line and hit enter.


Then spend a week doing as much as possible from within vim. You will start to get the basic hang of it. Then as you want to do other things, assume vim can do them for you and try and figure out how. #vim on freenode is good for this, although much of the help comes in the form of :he X. This means, read the documentation, the topic keyword is x. You literally type that into the editor command line :) The vim documentation is very good -- in fact just reading a few things extra every time you use vim is a good idea.

A final note: I have been using vim for my main editor for years now, and still learn new stuff all the time. Playing with new scripts, finding new bits of workflow, and getting really fast at it all take time. This is natural. I try and pick a couple new things a week an use them. Sometimes I will then forget about them for weeks, months or years because I think they are useless, but "rediscover" them only to use them all the time. Its actually quite fun.


That's the best tip of all. Ask yourself this question: "Can I walk through all the vimtutor examples without thinking too much?" If you can't, there is probably stuff in there you should learn. Make sure you know what an operator is, and what insert mode does. Listen to vimtutor when it tells you to learn by doing, not by trying to memorize everything in the tutorial. I learned by doing vimtutor over and over again until I could complete it without referring to help. If I forgot commands, I'd start over completely at the beginning and progress as far as I could until I had to start over to review. Do this a dozen times or so and soon you'll have basic facility.

Also, use vim for everything, not just code. Use it for email, writing projects, file management, and explore what else it can do for you.


Thats how I started.

Following this I also made it a point to read at least a little vim documentation (:h) every day. Its very detailed and helpful.

There is also the Vim book[1] by Steve Oualline which is also available free as a PDF.

Reading Vim tips[2] was also something that I found useful.

[1] http://www.vim.org/docs.php

[2] http://vim.wikia.com/wiki/Best_Vim_Tips


in addition, this is a pretty good guide. http://www.ibm.com/developerworks/edu/l-dw-linuxvi-i.html


Check out vimcasts.org. The guy who makes them even occasionally refers to how to do things in vim that he likes in TextMate.


To become a vim power user, you will really need to understand how and why vim works the way it does and how you should think about editing while using vim. Once you have gone through some of the great tutorials on basic vim usage take a look at these:

Stay out of insert mode: http://cloudhead.io/2010/04/24/staying-the-hell-out-of-inser...

Good explanation of how vim commands are actually formulated (Stack Overflow answer): http://stackoverflow.com/questions/1218390/what-is-your-most...


This is the cheat sheet that I used to get started: http://home.uchicago.edu/~gan/file/vim.pdf

Learn the basics first:

1. Basic movement (h l k j)

2. Insertion mode (i), deletion (x), selections/visual Mode (v), copying/yank (y), pasting/put (p), and exit insertion mode (esc)

Once you learn those the rest is pretty easy to pick up.

I should warn you though, once you get used to the key commands it's hard to go back to another editor.


I've always thought that the f and t motions along with I and A to switch to insert mode, and . (repeat) should be included in the basic motions and text objects should be the next step.

They're relatively simple to remember and you can string them together to accomplish a lot more than the character-wise to word-wise motion progression I've seen in most vim intros.


Assuming you're on Mac you'll need to set up a decent .vimrc to enable syntax highlighting, indentation and some other bits. Vim is a different beast depending on how it's set up.

The built in tutorial is a decent place to start. I think that's the only thing I did apart from editing code. It takes a while to get over the hump but it's worth it.

I also suggest remapping your CAPS LOCK key to ESC. PCKeyboard Hack is free and simple to set up for that purpose. I've never liked the role of ESC in vi. It's too far away from the home keys.

If you learn to love the efficiency, I'd suggest looking at Komodo Edit or another editor that has vim key mappings. I prefer Komodo because it's vim plus code completion (I'm not aware of a vim solution for that) and a bunch of other bits that will save time.


Not sure what features komodo has for completion, but between the built in omni-completion in vim 7, it's pretty powerful which will complete on symbols in all loaded files and in things like header files. That's activated by Control-X Control-O. Control-P or Control-N in insert mode.

There are various plugins available to make it smarter for C++ and other languages (so it only searches in appropriate namespaces and the like).


IMO the only thing you can do is to start writing real code and force yourself to use it. Honestly, the vim help stuff was almost useless to me at first because I would forget it as soon as I learned it, since I didn't understand the vi mindset.

You will notice a big drop in productivity at first, but hopefully you should notice yourself getting faster in a week or so.


I'm surprised no one has mentioned Derek Wyatt's excellent series of videos.

See his blog page with links to his videos: http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-novice...

Or go to his Vimeo page where they all sit: http://vimeo.com/user1690209


This was my best answer to the question, written 4 years ago, hope it helps:

http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial...

I also prepare this write up answering "Why vi?":

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

They've been on the HN front page a few times, too.


I found that being a touch-typist helped, since the concept of vim is to have your hands on the home row using letter keys rather than arrows or mice. (I happened to learn Dvorak but I'm sure Qwerty would have a similar impact on getting the most out of vim). Plus it's a transferable and generally recommended skill for programmers.


I switch between vim and textmate. My favorite textmate/vim feature is column select - in vim, its ctrl+v (http://sethmason.com/2007/09/27/vim-tip-select-column.html) in textmate it's option+click.

Also, fwiw, Macvim may help retain vim usage.


Use the Vimperator firefox plugin, so you can exercise your Vim muscles while you browse the internet.


I just started using it do code everything I do. Found other coders I know through IRC that know how to use it, and we traded tips. Over time I found my self becoming more and more efficient with it. vimtutor, as mentioned in other comments also works really well.


As a long time vim user, I have to ask: what's the appeal?I use it because I already knew vi, and I knew vi because it was the one editor I could be confident of finding on any UNIX box.

I'm curious: what's the motivation for learning it from scratch?


As opposed to doing what? Using a GUI editor? Using emacs?

vim is just as likely to be on any linux/os x box today as vi was to be on any UNIX box when you were learning vi, and it's still very powerful today.


The way I learn to use my tools is I start customizing them, thereby understanding how they work, how others use them and how I can utilize them. Look for .vimrc's of other hackers. I learn't many things just from the dotfiles.


I learned Vim inside and out because it was the only Linux console editor at the time that did syntax highlighting, and it kind of stuck.

Also, working in 80x50 with only the editor open for a couple of months kind of gets you into the mode :)


Attach this to a visible surface near your desk: http://r00tsecurity.org/db/cheat-sheets/SOFTWARE/Vi/vi-vim-c...



I started by learning ed from "The Unix Programming Environment", and then vi. By tackling vim directly, you may get swamped in the details.


Start with hjkl and see where it takes you. :)


You can borrow my vim cheat sheet tomorrow.


Type this into your terminal: emacs


On a more serious note, do please feel free to give any and all helpful advice on how to get started with emacs. I'm okay with vim, I've been using it more and less for about 2 years, but emacs has always seemed more esoteric and I never did quite get the hang of it.


Get a friend that uses it well and will be nearby (physically) for a few months. I didn't learn until I spent a summer with Slava (coffeemug) at my side willing to answer questions.

Find ways to do as much as you can of what you normally do with your computer in emacs. If you use IRC a lot, use erc. If you use email a lot, try out gnus or rmail. Don't try to replace your web browser with w3m, that's just stupid and you'll hate it.

Also, find a mode you really like. This will keep you using emacs whether you like it or not, until you really do like it. For me, it was gdb-mode. For most, it's one of the inferior repl modes (slime for lisp or clojure or whatever, ruby, python).

I've heard good things about http://github.com/technomancy/emacs-starter-kit, but I've never tried it.


Thanks for the very helpful answer, it's just what I wanted. :)

I do use IRC a lot, and I'll start using erc per your suggestion. One question, is there any way to get spell-checking on it? I'm hoping the solution is as straight-forward as x-chat's (this screenshot demonstrates it fairly well: http://i42.tinypic.com/rw2ljr.jpg though, I don't require fancy multi-language spell-checking, just an English spell-checker will do for me)

I wish I had a friend who used emacs! On that note -- anyone in this HN crowd who uses emacs from Milwaukee? I'm willing to gift copious amounts of chocolate (or whatever else you prefer) in exchange for even short periods of guidance. :)


As for spelling I believe enabling flyspell-mode will do the job, i.e. M-x flyspell-mode


you'll get better results with beer ;-)


That's how I learned too


Get like 2 or 3 different cheat sheets and keep them available whenever using Emacs. Steal someone else's ~/.emacs[1]. Make sure you use those Emacs key bindings in your shell. Bonus points if you're on OS X, which has Emacs bindings for all native text widgets.

[1] Here's mine: http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs :)


This got long, but hopefully there is some good knowledge in here for you.

Steve Yegge wrote some great starter posts on Emacs. He essentially inspired me to get out and learn it. He provides some good starting defaults that you should use. You can Google for these.

If you start Emacs and type C-h t, you'll get the tutorial, which is a helpful starting point. C-h in general is your friend and an entree into several kinds of help, like what keystroke bindings are currently active, what a built-in function does, what a keystroke does, etc.

The Emacs Wiki is a great place to go and just click around for a while. On the front page is a section for the Emacs Newbie. The Nifty Tricks page alone could consume several weeks of learning.

http://www.emacswiki.org http://www.emacswiki.org/emacs/EmacsNewbie http://www.emacswiki.org/emacs/EmacsNiftyTricks

What really sold me on Emacs was M-x shell. I love having a terminal with functionally infinite history, with completions for any text I enter (not just files and programs, read about Hippie expand), where I can munge the output of a shell command in place or just search through it.

M-x shell in combination with server-mode essentially replaced screen for me. server-mode allows you to run Emacs as a long-running server process that you can attach to with emacsclient. So your Emacs process might have uptime measured in months, and you just keep attaching to it from home or at work.

I like ido-mode with fuzzy matching, which functions something like an awesome bar for your editing tabs (or "buffers" in Emacs lingo).

Eventually, you may plateau in your knowledge and you might want to read the manual. It is written in small, digestible bits. You can skip around but it might help to read the first chapters first. It took me about a year to get to the point where it made sense to start eating the elephant.

http://www.gnu.org/software/emacs/manual/emacs.html

Last, you might want to investigate Emacs Lisp programming. Writing little programs in the native language of your text editor will make you drunk with power.

Happy hacking!


Do people ever get into serious arguments about using one or the other? At work we jokingly take jabs at the other camp, but that's more making fun of the fact that it's been such a hyped up feud.


I've seen it. It usually is the result of being trolled. The "troll" user of software A starts poking at the user of software B in a way that on the surface looks like an editor joke, but is actually about hte person. Something like "this code looks like it was written in X" or "how can an X user have completed bug #11". After a while it can get under the skin, but if the target is not paying enough attention, or is you know, working, the result can be a full on editor war.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: