A "tutorial" taken from an IRC log.
NOTE: This was hastily and sleepily ported from the original one, so expect errors, I will clean it up later.
The reason this tutorial was created: basically I was tired of explaining vim usage on irc, and found myself doing it repeatedly, at the same time, I was too lazy to sit down and write my own "real" vim tutorial (I ignored the fact that I spent 10x the time explain stuff to people on line than it would have taking me to write a tutorial). So after one conversation explaining a large chunk of vim usage, I pulled it out of the logs, and published it (cropped and modified of course) here.
This assumes you have vim installed and ready to go!
To go thru this tutorial please open up a STANDARD xterm and with the command "xterm -fg white -bg black -fn fixed" and then run "export TERM=ansi; vim". If you get stuck, my name is "robertmeta" (I play Socrates) and can be found on irc.libera.chat in #vim (among other chans). If you happen to use windows, you will want to run this tutorial using plain old gvim (not Easy Gvim or ReadOnly Gvim), just about the entire tutorial should work for ya :). The only reason I don't recommend gvim for linux for this tutorial is because #1) Not everyone has it. #2) It can tempt people to use vim incorrectly during the tutorial, better to just use good old console vim.
The Start (starting vim, general info)
- Socrates: ewww, it is not vim
- Socrates: therefore it is bad bad bad
- Glaucon: ehh
- Glaucon: vim
- Glaucon: no
- Socrates: you know nothing
- Socrates: :)
- Glaucon: never liked vim
- Socrates: why not?
- Socrates: it is so fast for editing
- Glaucon: well, it is better than emacs to me
- Glaucon: I agree its good
- Socrates: did you use it properly? or as a half assed text editor (ie: not using modes)
- Glaucon: just not my style
- Glaucon: well, I admit it never got too into it
- Glaucon: so, i didn't use the other modes
- Socrates: ahh, that is the core reason you probably don't like it.
- Glaucon: what other modes are there?
- Socrates: ahh
- Socrates: you didn't even explore a little :)
- Socrates: want a quick little intro ?
- Glaucon: sure
- Socrates: type "vim" at console
- Socrates: and tell me what version you got?
- Socrates: :q to exit
- Socrates: once you see the version
- Glaucon: hold on
- Glaucon: hmmm
- Glaucon: how do I get the version?
- Glaucon: in vim
- Socrates: it should show when you go in
- Socrates: right in front :)
- Glaucon: got a little splash screen
- Glaucon: version 5.8.3
- Glaucon: ok
- Socrates: that is fine, but you should get 6.0 at some point
- Socrates: go into vim
- Socrates: first thing to know
- Glaucon: ok, in it
- Socrates: is there are "3" modes
- Socrates: you are in "normal" mode now
- Glaucon: right
- Socrates: hit the i key to enter "insert mode"
- Socrates: and type some junk, just to work with
- Glaucon: yea, this much i've covered
- Glaucon: ok
- Socrates: then hit esc to get back to "normal mode"
- Socrates: just type
- Socrates: k when I can continue in the chan
- Glaucon: k
Real Basics (Well, mostly)
- Socrates: one of the mantras in vim is "stay as close to the home row as possible"...
- Glaucon: home row?
- Socrates: asdfghjkl; -- your "home row" keys
- Glaucon: ahh
- Socrates: where you place your hands
- Socrates: now, you arlready know you can move around in "insert" or "normal" mode with arrows
AutoComplete
Selecting Stuff, Cutting and Pasting...
Sorry if the next little bit is unclear, I will try to edit it when I get a chance Important thing I forgot to tell Glaucon is that you can use "V" (shift-v) to select LINES in visual mode, you hit just plain v to select CHARS instead, and you can grow or shrink visual mode just by using movement keys once you hit v (or V). Once in visual mode, there are some interesting things to note, first of all, when you go into visual mode, there are two "marks" set '< and '>, when you hit : (to go into normal mode, covered later), it will put in those "marks" as the default item to "act on". Also, you can hop to the upperleft corner, and the lowerright corner (the marks) by hitting o while in visual mode. Also, you can indent the visual "blocks" by hitting < and > while in visual mode, and remember that you can do it repeatedly by doing 3> to indent three times, 2< to un-indent 2 times
Sidenote: Ok, I can't stay focused...
Sidenote: Back to objects again, sorry (Line Yanks and Deletes are here)
Thanks to sjbrown in #PHP on libera.chat for this... "Marks Rule" -- You mark a part of something you are editing, so you can jump back to it quickly, and use it in binds and yanks and other such stuff. You mark and area with m(key to bind mark to) in normal mode. You can jump to that by doing `(key you binded the mark to) -- for example, putting the cursor over a part of a word and hitting "mj" would attach a mark there with the name "j", to jump to that mark, you would use "`j"
Searching Stuff
Thanks to sjbrown again, for this extention of marks, you can actually use yank with marks as well, you can do y`(key you binded the mark to) -- cool huh?
Sidenote: to commands
Something I forgot to mention in this section (don't ask me how) is :e, you use :e to OPEN file, :e (file), you can also be specific and mention multiple files, sorry about skipping this important features!
Sidenote: Shit I should have told you before!
Objects again, you poor bastard!
Undo/Redo (and a common problem with it)
Sidenote: Shit I should have told you before #2!
Regular Expression and search/replace
Running external commands and semi-related stuff
Another couple cool things you can do is :r !command (such as :r ls) to insert the output from a command into the current file. Along those lines, you can also pass a command into vim with "cat file.txt | vim -" the floating dash at the end means, "read from stdin". No need to test the second half of this little comment now, try it after you finish the tutorial
Recording Macros
In closing, there is one VERY import thing I totally forgot to tell "Glaucon" and that is about using vims help system, and can not believe I left it out, but just type :h command (or part of command) to search the help for that command, and learn to use it often, and you will learn the power of vim more quickly. Vim has hundreds of features that I did not mention, I only showed "Glaucon" the stuff I use most often, and the stuff I find most useful. My personal way of working with vim is with Multiple Buffer, in gvim, on linux 2.4.x. Please do not think after you have finished this little page you know all the tricks of vim, you don't, but you got a damn good start :)
Thanks for reading!
The first addition to my little tutorial
Splitting (using little windows) in vim
Using Buffers and stuff
The first addition by someone else
Folding in vim (by rik)
Editor's note: Reloading your .vimrc file can sometimes cause unforseen problems. It's safer to quit vim and restart it.
Common Questions/Answers and Randomness