10 ms·
Learn Vim Progressively
- insraq 15y agoGreat post. I like the way author splits the big problem into smaller ones and reduce the learning curve by different stages. When I recommend vim to my friends, they are usually frightened by the OReilly's thick vi/vim book and most people cannot "survive" in vim before they give up.
- beaumartinez 15y agoNice tutorial—better than many. However, these kind of tutorials always fail to mention the number one way to learn Vim: vimtutor and :h usr_02.txt Those two (and successive pages in the user manual) will teach you practically everything about Vim—and they're included right in Vim.
- hasenj 15y agovimtutor is actually slow and boring
- gbog 15y agoIndeed, the article is certainly too short to be slow or boring. It reads in 2 minutes, and you learn near to nothing about Vim, not even search and replace or <c-y>.
- joelthelion 15y agoIt takes less than 30 minutes, and teaches you a lot of useful things, with practice, that actually makes you memorize the things. If spending 30 minutes learning vim is "slow and boring" to you, then I sincerely doubt vim is for you.
- hasenj 15y agoI use vim everyday as my main editor. This guide is much more interesting: http://www.viemu.com/a-why-vi-vim.html http://www.viemu.com/a-why-vi-vim.html
- rfrey 15y agoFrom the article: "Fortunately vim comes with some very good tools and an excellent documentation. Run vimtutor until you are familiar with most basic commands. Also, you should read carefully this page: :help usr_02.txt."
- beaumartinez 15y agoSince I wrote that comment he changed his article to include that (unattributed, of course): https://github.com/yogsototh/Scratch/commit/6555b7d94cee124a12cb7632b80a3a784f07ebf6#L0R334 https://github.com/yogsototh/Scratch/commit/6555b7d94cee124a...
- ma2rten 15y agoDon't do what this guy says! Or at least don't stay in phase 1 for longer than a day. I've had used vim for a few years as a pico replacement, whenever I was on a remote computer on ssh. I picked up some really bad habit, like staying in insert mode all the time and using the arrow, home and end keys. I actually had to deactivate the arrow keys in my vimrc. I would recommend going thought the tutorial, that comes with vim (vimtutor command) and after that reading those articles: http://www.moolenaar.net/habits.html http://www.moolenaar.net/habits.html http://www.viemu.com/a-why-vi-vim.html http://www.viemu.com/a-why-vi-vim.html
- jng 15y agoThanks for recommending my article. I'd also recommend this other one: http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial...
- initself 15y agoI'm in the minority camp that doesn't think arrow keys are a big deal, but I suppose I need to qualify that and say "not a big deal if you are on a Thinkpad" and you have an solid reach of curled fingers in your right hand. There's are efficiency gaps in between 1) keeping fingers on jkl; 2) manipulating the arrow keys with fingertips, primarily using the pinky for quick movements 3) lifting the hand to use the arrow keys and they do add up over time, but I'm not sure how detrimental they are. Sometimes, the arrow keys provide a nice mental break, where you can step back from the doc and examine what's happened so far with the arrow keys or page up/down.
- jff 15y agoWhen you use the arrow keys to move the cursor around: a nice mental break. When you use the mouse to move the cursor around: an utterly evil, productivity-destroying action, because you take your hands off the home row (oh wait...) Hacker News, don't ever change ;-)
- ranza 15y agoLove the small videos that illustrates whats going on! Nice one!
- tudorizer 15y agoDoes anyone fancy a game of vim golf? :) (after finishing the last phase, of course).
- WilhelmJ 15y agoWhen I learned to use vim years ago, one interesting observation was that the biggest thing to learn in vim is efficient navigation. i.e. if you know how to get to a particular logically defined place in the file, you will always be able to carry out copy-paste-delete to and from that place to where to cursor is. One would be surprised how easy thing become once you know the basic navigation rules due to marvelous mix-n-match nature of vim operations.
- jpadilla 15y agoThis is great! For a couple of years I've had this love/hate relationship with vim. I'm going to actually going to give a try with this
- HenryFonda 15y agoI am on a strange website
- sixtofour 15y agoI'm curious, what sort of background do you have, and what expectations do you have, that leads you to see this as a strange web site? And what specifically is strange about this web site, or about this thread?
- dschobel 15y agoDamn, I've been using vim for almost a decade and didn't realize that /<term> worked as a movement so you can do things like y2/foo and yank to the second occurrence of “foo” (to use the example from the tutorial). That's why I scan every beginner vim tutorial that comes across hn. I always learn something
- billybob 15y agoTook me years to learn that one, too. It may be favorite Vim trick now. Basically everything that can make your cursor jump can be used as a motion with a command - moving to a mark, undoing/redoing jumps with Ctrl+o and Ctrl+i, and hopping to a matching brace with % are more examples. Wrote a short intro myself about such revelations: http://nathanmlong.com/vanquish/ http://nathanmlong.com/vanquish/
- saraid216 15y agoI gave up pretending that I'm a Vim beginner a year or two ago, but I also continue to skim through and learn from "beginner" tutorials that show up in my stream. People always pick a different set of "basic" commands, and from this one, I learned about "t<letter>", which I hadn't known before.
- Ideka 15y agoFunny. I found out about that early, merely experimenting. I rarely use it nowadays tough. I used to use it for stuff like "delete up to the next dot" and the like. But that was until I learned about f and t. :)
- Estragon 15y agoSame thing works in emacs. Incremental search sets the mark at point of initiation, so you get the same effect with C-s foo C-s C-w.
- jrockway 15y agoExcept, let's be honest, Emacs' way makes a lot more sense. Someone who has used Emacs for ten minutes can easily figure this out because Emacs tries to help the user. The naive way of copying to the end of a search term is C-SPC C-s term ENT C-w. But, after you've hit ENT to end the search, Emacs does something amazing. It prints "Mark saved where search started." So now the next time you run this command, you know you won't need to set the mark. Because it told you! (Eventually, you'll learn to expect this behavior because pretty much every interactive motion command does this and prints "Mark set.")
- Bo102010 15y agoWhat I would love (and suppose I should make) is a CodeAcademy sequence for vi.
- pestaa 15y agoNicely illustrated tutorial, well done. One thing to note though: Y and yy are not shortcuts to 0y$ -- the latter does not yank the line ending. I use it to insert one line into another, but find splitting and joining lines to be cumbersome.
- yogsototh 15y agoThanks, I corrected this.
- mathias_10gen 15y agoThe defualt mapping of Y is arguably broken since it doesn't follow the normal vi conventions. I have these lines in my .vimrc to "fix" it: "make shift Y behave like shift-[cd] (copy to end of line) nnoremap Y y$
- graywh 15y agoY being a synonym for yy is from vi. What you mean to say is that it doesn't fit the pattern D/dd and C/cc present.
- d0m 15y agoActually "cw" doesn't change the current word.. it changes where the cursor is to the end of the word. Something I tend to use a lot is: (| is the cursor) ciw (Really change the current word. "Fo|o Bar" -> "| Bar" ci" (Change in between ": "Test 12|34" -> "|" da" (Delete in between " AND the "": a"Test 12|34"b -> ab Also, plugins are extremely important. For instance, one of my favorite makes the "w" smarter for day to day programming word. (I mapped it to ,w) For example: "pac|kageManager" ci,w "|Manager" "pac|kage_manager" ci,w "|_manager"
- d0m 15y agoOh, and the surround plugin is so useful.. something I tend to do a lot is: viws' : viw "highlight the current word" and s' surrounds it with ''. *Soooooo* useful. You can also do yiws' but I like to see what will be surrounded as something there're spaces or other characters which doesn't *count* in "w".
- yogsototh 15y agoOf course, you're right, I fixed that. And many people asked for a text_object section. I'll certainly add it.
- d0m 15y agoThanks for the guide. If I might suggest another small gem that beginners would appreciate, is a way to copy text with a mark. I.e. ma go to the end y`. It may be easier than vwwwwwwww y or something similar.
- mattsacks 15y agoEven better - "ay$ or, yank from cursor til end of line into register a. Paste with "ap
- beaumartinez 15y agoExactly—use text objects. :h text-objects To be consistent with dw you can use caw which will delete until the next word, not just the current word.
- Tycho 15y agois ESC really the only way to get back out of insertion mode? that feels like CTS waiting to happen
- tudorizer 15y agoI have jj mapped to exit from insert mode and save the file. This trick was found in a long SO thread, plus I never had the need to type something with a double j ;)
- yogsototh 15y agoI have the even faster jk mapped to ESC. And if you want to type jk in your text you just have to - type j - wait 1 second - type k.
- billybob 15y agoVery nice! For those wondering how to do this, you can try it out with :imap jk <esc> (imap means "use this mapping when I'm in insert mode".) If you like it, add everything but the : to your .vimrc
- masterj 15y agoI find kj easier to type, since it's an outward muscle movement. Warning: If you do this you will wind up typing those characters by memory nearly everywhere.kj
- billturner 15y agoI know lots of folks remap the Caps Lock to key as ESC, since it's easier to hit than ESC.
- dredmorbius 15y agoBut my CapsLock is already mapped to Control ....
- dcosson 15y agoDoes anyone know why the decision was made to make hjkl the vi navigation buttons? I've always felt like jkl; would be faster since your fingers are already there
- qxb 15y agoAs I understand it, vi's author, Bill Joy, used a terminal that placed arrow symbols on hjkl because it did not have dedicated arrow keys. Wikipedia backs up this story: http://en.wikipedia.org/wiki/HJKL_keys#HJKL_keys http://en.wikipedia.org/wiki/HJKL_keys#HJKL_keys
- shocks 15y agoEveryone uses vim in their own way, you should learn how to use vim for the style that suits how you work. Only learn what you need to learn, you can't learn everything. No one knows all of vim; if you say that you do, you are a liar.
- sidconn 15y agoAnybody explain 'edition mode' 'insertion mode' ? New terms?
- beaumartinez 15y ago"Edition mode" is what the author calls "command-line mode".
- thristian 15y agoI'm not sure where those terms come from. "insertion mode" is described by the Vim documentation as "insert mode", because what you type on the keyboard is inserted into the document. "edition mode" might be a typo or English-as-a-second-language mistake for "editing mode" because that's what you do in that mode; Vim's documentation just calls it "normal mode".
- antonp 15y agoThis post on SO has some nice bits in it : http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about http://stackoverflow.com/questions/726894/what-are-the-dark-... "imap jj <esc>" being my favourite.
- thristian 15y agoHere's a Vim trick I only figured out fairly recently. Everybody knows that % jumps between a bracket, brace or parenthesis and its matched pair, but what happens if you hit % while the cursor isn't on such a character? Turns out, it searches forward until it finds such a character, then jumps to its matched pair. So for example, let's say you had a nested function invocation that was getting long and unwieldy and you wanted to break it out onto its own line: foo = makeFoo( globalConfig.getParam( "FooSize", int, default="37", ) ) If you put the cursor on the 'g' at the beginning of 'globalConfig' and press "d%", it will cut the function name and all the parameters in one action.
- tudorizer 15y agoHat tip to you, sir.
- mnazim 15y agoIt can also be used with y and c(y%, c% etc.)
- agscala 15y agoThat is a neat trick. Even though it's one more character, the expected way to do this would be: "dt("
- tmhedberg 15y agoThat would delete just the function name (`globalConfig.getParam`), not the argument list as well. `d%` would grab the function name _and_ its argument list.
- mathias_10gen 15y agoci( is another nifty trick that will do the same but will work anywhere between the two ('s not just at the beginning of globalConfig. See ":help text-objects" for more details on one of the more powerful feature of vim.
- 15y ago
- kmm 15y agoI've been using Vim for about three years but I've never been very handy at it. I'm now wondering that that might be because I touch type with only four fingers and whether it's possible to relearn my typing methods.
- crazydiamond 15y agoThis is an _amazing_ collection once you've gone past the beginner's stage: http://www.rayninfo.co.uk/vimtips.html http://www.rayninfo.co.uk/vimtips.html For some great plugins, check http://stevelosh.com/blog/2010/09/coming-home-to-vim/ http://stevelosh.com/blog/2010/09/coming-home-to-vim/
- JshWright 15y ago"A last word about notation: instead of writing Ctrl-λ, I’ll write <C-λ>." Does anybody else's keyboard have a λ key?
- morbofry 15y agoWell, when you use Emacs, every key is a λ key...
- jrockway 15y agoWhen you use haskell-mode in Emacs, \ renders as λ. (And only when you're using it as a lambda. '\n' still renders as '\n', not 'λn'.)
- avinashv 15y agoI assume the λ is just a placeholder for any character.
- yogsototh 15y agoIn vim I used digraph. <C-k>l* You can have the complete list with :dig
- crux 15y agoOne thing I would love to see—and which I can only assume exists—is a guide like this, tailored to writing prose rather than code. This article maintains certain assumptions that are held by nearly every other guide, like 'You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press <Esc> to go to normal mode.' Which is true and useful for coding, but slightly less so for prose—not entirely less so, and it's still a good idea to get in the habit of busting out of insert mode when you've finished whatever thought you're writing down, but the lines between thinking, composing and editing are blurrier than in prose. Nevertheless vi controls can be pretty semantic, and lend themselves pretty effectively to working with words, clauses, sentences, and paragraphs. On the other hand, using search for mid-paragraph navigation is an order of magnitude less efficient in prose, when you're so much more likely to have symbols and words doing totally different things in many places in your text.
- keithpeter 15y agohttp://www.associatedcontent.com/article/765005/the_vim_text_editor_how_and_why_to_pg2.html?cat=15 http://www.associatedcontent.com/article/765005/the_vim_text... Some suggestions for .vimrc to change movement behaviour and line wrapping. I'm not a vimer by the way, still using Gedit.
- keithpeter 15y agoHere is a 13 page guide specifically aimed at writers using Vim or Gvim. Explains how the movement commands change with soft wrapping of lines and so on. http://therandymon.com/woodnotes/vim-for-writers/vimforwriters.html http://therandymon.com/woodnotes/vim-for-writers/vimforwrite...
- sixtofour 15y agoThank you keithpeter and keithpeter for those two links. A minor thing that's useful if you stay in insert mode for long periods: You can click the mouse anywhere while in Insert mode, and your cursor/insertion point will move to where you click. This works in Gvim, and also in vim, but I suppose vim depends on how your terminal is set up. I've done nothing special to my terminal or my vim.
- 15y ago
- katieben 15y agoI'd love to see this in emacs.
- falcolas 15y agoAgreed. I'm fairly proficient in VIM, and I'd love to extend my knowledge of emacs as well - but there's few tutorials that don't start with "change these 15 settings and install these 5 plugins, then use it like this..."
- Arcanum-XIII 15y agoI've tried the evil mode : emacs now behave like vim in text edit mode, with nearly less complication than installing a plugin for vim. Can be found here : http://gitorious.org/evil/pages/Home http://gitorious.org/evil/pages/Home
- dupe123 15y agoeven better, use viper mode in emacs.. you get all the keybindings of vim and you don't have to write vimscript to customize your editor
- jrockway 15y agoThat's not true. You get all the keybindings of Emacs in insert mode, and you get all the keybindings of vi in command mode. vi and vim are different enough that experienced vim users cannot use vi at all. I know, because I've invited them to try. (Incidentally, mg is pretty easy to use as an Emacs users. The only odd thing is that ENT does not end an isearch, because mg thinks C-m and C-j are the same thing. What?)
- callmeed 15y agoVery cool ... but why teach paste before cut/copy?
- georgebashi 15y agoBecause vim's paste command, p, will paste what was last removed with a command (such as d or c). Although you're not explicitly told that d and y are analogous to cut and copy, after learning the mechanics of p, each command you learn adds a new (and powerful!) mechanic which doesn't have a parallel in the normal cut/copy/paste model.
- bsergean 15y ago"Add something at the end of all visually selected lines:" I didn't know about this one, very happy to have read it.
- dbingham 15y agoMy problem with using Vim, and the source of my hesitation to learn it more, is that I'm a fairly haphazard typist. I type fast, but messily. I've never really been able to clean it up. I'm just naturally a little clumsy. In my IDE, this is never, ever a problem. Most of the dangerous commands require I go to the mouse, so I can't simply blaze through them on the keyboard. Anything I mess up at the keyboard, I can always undo with backspace or a cntl+z. Furthermore, there is visual confirmation of exactly what each command I entered is doing and a chance to cancel it if it's going to do stuff I don't want. In Vim, this isn't the case. I can be blazing along on the keyboard, attempt to enter a command, screw it up and enter not just one, but a whole sequence of incorrect commands. These commands could be very problematic -- doing things that are hard to undo. And it can be very difficult for me, as a Vim novice especially, to figure out exactly what I screwed up and how to undo it. I know some of that may be remedied with more knowledge. I'm sure there's some way to view a detailed command history, and I know it has an undo. But I still feel as if, for myself at least, the danger of keyboard mashing screw ups completely counteracts any gains in productivity I'd make. And given that I wouldn't really gain anything by using Vim, I prefer the comfort of my visually based IDE. Aside from which, I'm really fond of the way Eclipse's windows are dockable and movable and I make frequent use of that feature. Interrupting processes or juggling multiple terminal windows just isn't the same.
- humbledrone 15y agoWhat do you mean by "hard to undo?" Every Vim user has, more than once, accidentally begun typing in command mode and done crazy things. The solution is to just hit u (undo) a couple of times. Granted, some commands have side-effects, (e.g. "w! existing.txt" which would overwrite an existing file), but they are sufficiently complex that the odds of typing one are extremely low. I have been using Vim on a daily basis for over a decade, and I cannot recall a single time that I've accidentally typed an irreversible command.
- dbingham 15y agoBy that I mean more that, they go by so fast, often with out much visual confirmation of what just happened, that it's very easy for me to not know even how far back I have to undo. I don't know what I've just done! In a visual IDE, that's a non issue, there's a pretty clear visual cue for everything.
- keithpeter 15y agohttp://gav.brokentrain.net/projects/vimtips/vimtips.pdf http://gav.brokentrain.net/projects/vimtips/vimtips.pdf This PDF file has a lot of tips/command lines about Vim It is also produced really well, with landscape pages and bookmarks, so that it can be displayed on your monitor very efficiently.
- jordinl 15y agoWhat would be the best way to copy text and paste it replacing some other text?
- graywh 15y agopaste from visual mode
- theviciousfish 15y agoproof that you can learn new (vim) things every day! Never used the rectangular blocks before. mind == blown!
- deleted 15y ago[deleted]
- zeke 15y agoOne hint I have not seen here: while in input mode use <Cntl>n to auto-complete the word you are typing. This is very good for longer variable names and ensures your name matches what you have typed already.
- BadassFractal 15y agoAs someone who works on large .NET / Java / RoR projects, would I gain anything from switching to vim from say, VS 2010, Eclipse and RubyMine? I'm quite used to relying on visual IDEs, but if vim is supposed to make me incredibly productive then I'd certainly like to explore that option. Anybody here made the switch and felt it was worth it?
- ajanuary 15y agoYou'd possibly be better off using one of the plugins that adds vim style commands to visual studio.
- sofal 15y agoThere are tradeoffs. In my opinion, the text-editing advantages that vim gives me greatly outweigh the advantages that an IDE has over vim. If you haven't used vim before and you switch now, you will not see it as a favorable tradeoff for a while until you get the hang of it. Using vim for all these things requires a command-line friendly mindset for all of the non-text-editing tasks like building, running, searching directories, etc. Really it's not IDEs versus vim, but rather IDEs versus vim + command line. Some things I give up to use vim over IDEs: * A nice graphical debugger * Superior support for symbol lookup (ctags isn't perfect) * Superior support for autocomplete (given the above) * Automagical refactoring support (I think these features are way overrated, and many of the most common edits fall under vim's domain) * Boilerplate generation (even given the copious amounts that Java requires, I've always thought that this was a code-reading problem rather than a code-writing bottleneck) * Compiler errors as you go * WYSIWYG GUI design (you could just fire up the IDE when you need this anyway)
- BadassFractal 15y agoIs it possible to have it all at once? Would a plugin for VS/Eclipse/whatever like the other poster suggested allow you to use a vim approach with all of the benefits of a cushy IDE?
- Wilduck 15y ago
- akavel 15y agoFor me, the ultimate first lesson of vi survival is absolutely ":q!". I'm surprised it's shown only by the end of the second lesson. Other than that, I hope I'll push myself to try this tutorial.
- alwillis 15y agoI’ve looked at a lot of Vim beginner tutorials—this one is outstanding.