TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Learn Vim Progressively

605 pointsby yogsotothover 13 years ago

32 comments

dschobelover 13 years ago
Damn, I've been using vim for almost a decade and didn't realize that /&#60;term&#62; worked as a movement so you can do things like <i>y2/foo</i> and yank to the second occurrence of “foo” (to use the example from the tutorial).<p>That's why I scan every beginner vim tutorial that comes across hn. I always learn <i>something</i>
评论 #2937399 未加载
评论 #2938065 未加载
评论 #2939961 未加载
评论 #2939879 未加载
thristianover 13 years ago
Here'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.<p>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:<p><pre><code> foo = makeFoo( globalConfig.getParam( "FooSize", int, default="37", ) ) </code></pre> 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.
评论 #2937534 未加载
评论 #2937442 未加载
评论 #2937270 未加载
评论 #2937508 未加载
beaumartinezover 13 years ago
Nice tutorial—better than many.<p>However, these kind of tutorials always fail to mention the number one way to learn Vim:<p><pre><code> vimtutor </code></pre> and<p><pre><code> :h usr_02.txt </code></pre> Those two (and successive pages in the user manual) will teach you practically everything about Vim—<i>and they're included right in Vim</i>.
评论 #2940026 未加载
评论 #2936782 未加载
d0mover 13 years ago
Actually "cw" doesn't change the current word.. it changes where the cursor is to the end of the word. Something I tend to use <i>a lot</i> is: (| is the cursor)<p><pre><code> ciw (Really change the current word. "Fo|o Bar" -&#62; "| Bar" ci" (Change in between ": "Test 12|34" -&#62; "|" da" (Delete in between " AND the "": a"Test 12|34"b -&#62; ab </code></pre> 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:<p><pre><code> "pac|kageManager" ci,w "|Manager" "pac|kage_manager" ci,w "|_manager"</code></pre>
评论 #2937035 未加载
评论 #2936967 未加载
评论 #2937041 未加载
评论 #2937028 未加载
评论 #2938259 未加载
ma2rtenover 13 years ago
Don'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.<p>I would recommend going thought the tutorial, that comes with vim (vimtutor command) and after that reading those articles:<p><a href="http://www.moolenaar.net/habits.html" rel="nofollow">http://www.moolenaar.net/habits.html</a><p><a href="http://www.viemu.com/a-why-vi-vim.html" rel="nofollow">http://www.viemu.com/a-why-vi-vim.html</a>
评论 #2937415 未加载
评论 #2936858 未加载
crazydiamondover 13 years ago
This is an _amazing_ collection once you've gone past the beginner's stage:<p><a href="http://www.rayninfo.co.uk/vimtips.html" rel="nofollow">http://www.rayninfo.co.uk/vimtips.html</a><p>For some great plugins, check <a href="http://stevelosh.com/blog/2010/09/coming-home-to-vim/" rel="nofollow">http://stevelosh.com/blog/2010/09/coming-home-to-vim/</a>
insraqover 13 years ago
Great 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.
dbinghamover 13 years ago
My 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.<p>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.<p>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.<p>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.<p>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.
评论 #2938099 未加载
antonpover 13 years ago
This post on SO has some nice bits in it : <a href="http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about" rel="nofollow">http://stackoverflow.com/questions/726894/what-are-the-dark-...</a><p>"imap jj &#60;esc&#62;" being my favourite.
cruxover 13 years ago
One 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 <i>'You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press &#60;Esc&#62; to go to normal mode.'</i> 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.<p>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.
评论 #2937731 未加载
评论 #2937600 未加载
评论 #2937976 未加载
评论 #2939154 未加载
评论 #2938103 未加载
ranzaover 13 years ago
Love the small videos that illustrates whats going on! Nice one!
评论 #2936790 未加载
评论 #2936793 未加载
JshWrightover 13 years ago
"A last word about notation: instead of writing Ctrl-λ, I’ll write &#60;C-λ&#62;."<p>Does anybody else's keyboard have a λ key?
评论 #2937564 未加载
评论 #2938976 未加载
评论 #2940281 未加载
shocksover 13 years ago
Everyone 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.
pestaaover 13 years ago
Nicely illustrated tutorial, well done.<p>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.
评论 #2937551 未加载
评论 #2937115 未加载
Bo102010over 13 years ago
What I would love (and suppose I should make) is a CodeAcademy sequence for vi.
WilhelmJover 13 years ago
When I learned to use vim years ago, one interesting observation was that the biggest thing to learn in vim is efficient navigation.<p>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.<p>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.
BadassFractalover 13 years ago
As 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.<p>Anybody here made the switch and felt it was worth it?
评论 #2939232 未加载
评论 #2938995 未加载
评论 #2939145 未加载
评论 #2938954 未加载
keithpeterover 13 years ago
<a href="http://gav.brokentrain.net/projects/vimtips/vimtips.pdf" rel="nofollow">http://gav.brokentrain.net/projects/vimtips/vimtips.pdf</a><p>This PDF file has a lot of tips/command lines about Vim<p>It is also produced really well, with landscape pages and bookmarks, so that it can be displayed on your monitor very efficiently.
tudorizerover 13 years ago
Does anyone fancy a game of vim golf? :) (after finishing the last phase, of course).
kmmover 13 years ago
I'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.
zekeover 13 years ago
One hint I have not seen here: while in input mode use &#60;Cntl&#62;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.
jordinlover 13 years ago
What would be the best way to copy text and paste it replacing some other text?
评论 #2939077 未加载
akavelover 13 years ago
For 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.<p>Other than that, I hope I'll push myself to try this tutorial.
dcossonover 13 years ago
Does 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
评论 #2937126 未加载
theviciousfishover 13 years ago
proof that you can learn new (vim) things every day! Never used the rectangular blocks before. mind == blown!
评论 #2948558 未加载
Tychoover 13 years ago
is ESC really the only way to get back out of insertion mode? that feels like CTS waiting to happen
评论 #2937111 未加载
评论 #2937005 未加载
评论 #2937378 未加载
评论 #2937055 未加载
评论 #2937091 未加载
评论 #2937785 未加载
评论 #2938116 未加载
评论 #2937681 未加载
katiebenover 13 years ago
I'd love to see this in emacs.
评论 #2938095 未加载
alwillisover 13 years ago
I’ve looked at a lot of Vim beginner tutorials—this one is outstanding.
sidconnover 13 years ago
Anybody explain 'edition mode' 'insertion mode' ? New terms?
评论 #2937124 未加载
评论 #2937061 未加载
callmeedover 13 years ago
Very cool ... but why teach paste before cut/copy?
评论 #2938062 未加载
dupe123over 13 years ago
even 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
评论 #2940141 未加载
HenryFondaover 13 years ago
I am on a strange website
评论 #2937940 未加载