That's why I scan every beginner vim tutorial that comes across hn. I always learn something
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/
(Eventually, you'll learn to expect this behavior because pretty much every interactive motion command does this and prints "Mark set.")
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. :)
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(
However, these kind of tutorials always fail to mention the number one way to learn Vim:
"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."
This guide is much more interesting: http://www.viemu.com/a-why-vi-vim.html
I would recommend going thought the tutorial, that comes with vim (vimtutor command) and after that reading those articles:
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
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.
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 ;-)
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
"pac|kageManager" ci,w "|Manager"
"pac|kage_manager" ci,w "|_manager"
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
da" => 'delete a "-block'
di" => 'change in "-block'
Paste with "ap
For some great plugins, check http://stevelosh.com/blog/2010/09/coming-home-to-vim/
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.
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.
"imap jj <esc>" being my favourite.
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.
Some suggestions for .vimrc to change movement behaviour and line wrapping. I'm not a vimer by the way, still using Gedit.
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.
I don't edit while I'm writing the first draft. But when I do edit, I'm always pressing <Esc>. That's why changed the keymap.
/<text> is an editor's best friend.
Does anybody else's keyboard have a λ key?
You can have the complete list with :dig
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.
"make shift Y behave like shift-[cd] (copy to end of line)
nnoremap Y y$
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.
Anybody here made the switch and felt it was worth it?
If you only do ASP all day, VS is worth sticking with.
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)
However, when it comes to doing some real coding, I always go back to Emacs. After learning a really good text editor, you don't even have to think about doing complex things with the text, you just get into a zen mode, and the cursor does what you want. Combine that with easy access to any shell/interpreter you're using and it makes for a very productive way to just write some code.
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.
Other than that, I hope I'll push myself to try this tutorial.
Wikipedia backs up this story: http://en.wikipedia.org/wiki/HJKL_keys#HJKL_keys
However, I also recommend mapping ESC to Caps Lock. Once you have vimified your whole computing experience, it starts paying back big time.. ;-)
- type j
- wait 1 second
- type k.
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
Warning: If you do this you will wind up typing those characters by memory nearly everywhere.kj
I find emacs's ctrl-meta-foo-bang key combinations to be far more stressful (you have to hit multiple keys in one swell foop) than vi/vim's modal just-one-key-at-a-time standard keystrokes.
One now about using Ctrl-c: that bypasses InsertLeave autocmd's.
(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?)
And what specifically is strange about this web site, or about this thread?