views:

322

answers:

10
+5  A: 

The more I used the keyboard movement in vim, the less I wanted to use the mouse. It doesn't help that extended periods of time where I'm constantly moving from keyboard to mouse can take a toll on my wrist.

If you want to force doing things the vim way, unplug your mouse for a while! The more you use the keyboard, the more you will love it. This worked for me.

For moving between lines, I usually just use jk but I often skip to lines using :line_num. Getting to a specific column in a line, I typically use wbe^0$ and put modifiers in front of w, b, or e if I'm skipping through several words. And there is also the shifted versions, WBE which also come in handy often.

Corey D
+2  A: 

I have to admit that I often use the arrow keys for specific movement in vim. I rarely use hjkl. However, I find that most of my navigation is done with other commands such as w (skip a word forward), b (skip a word backwards). Combine this with modifiers such as 3w (3 words forward). : skip to a specific line.

I've never really had to abandon the mouse since I never really started with it. All I can say is that attempting to use editors without all the keyboard shortcuts that vim has can feel quite painful.

Evan
A: 

I learned vi so for me the mouse has never been something to use with a text editor.

I don't use hjkl except when the machine/network/keyboard/whatever-in-between is not comfortably configured.

mouviciel
+4  A: 

I think that my speed (and posture at the computer) will be improved by not having to escape from insert mode

No, you must escape from insert mode right after you typed what you want.

The mouse seems fast, but in reality it isn't precise, so you lose time. ViM have a long list of moving commands (see :help usr_03). Use search the most you can (/, ?, *, #, f, t...). I personally use Ctrl+(D,U,F,B) a lot. Also, Ctrl-(O, I) and `` are really useful to go back where you were before a search or something else.

h, j, k, l are there to place your right hand near to useful commands (i, u, o...) : I always have my fingers on them. The arrows force you to move your hand a lot.

Try to look at a few commands in :help, then use them a lot, and you'll get habits about what you should use to move according to the situation. Nobody uses ViM the same way.

Pikrass
+1, but that is not why h,j,k, and l are where they are. They are there because the target computers when vi was first written didn't have dedicated arrow keys.
Randy Morris
+1  A: 

You can seriously revolve your life around jk in hjkl.

nnoremap <c-k> ddkP "move current line up one
nnoremap <c-j> ddp "move current line down one
vnoremap <c-j> dp'[V'] "move visual block down one
vnoremap <c-k> dkP'[V'] "move visual block up one

"These may be a bit more esoteric to me"
inoremap jj <esc>o "Insert mode can move to next line (works mid line)
inoremap kk <esc>O "Insert mode new line on previous line 

also for the desktop gui (ion3 and gnome)

winj - next window

wink - prev window

(This beats alttab if your editing in vim all day)

also read :he motion.txt in its entirety using j and k to scroll up and down as you do.

michael
Nice tips. I particularly like jj and kk. I've added them to my vimrc.
Charles Roper
gt and gT are great for switching tabs too.
dash-tom-bang
A: 

Use the mouse where it makes sense. It often does (copy/paste to and from other gui applications).

To answer your question, though: Once you start using vim as a tool for transforming text bits with macros, the movements will all start to fall into place ;)

Daren Thomas
+2  A: 

I'd run vimtutor from the command line (Terminal.app in OS X). It runs vim with a tutorial document. That document was what really made me realize the power of some of the commands. You'll pick up some that are most useful to you and gain more over time. Eventually you'll find yourself using the mouse less and less.

Benjamin Oakes
I wish I could give this more +++
dash-tom-bang
A: 

I think you're wondering if there's a quick way to move around while in insert mode (without using the mouse or arrow keys) but unfortunately there isn't; you have to escape out of insert mode. However I know that jumping all the way to your Esc key can be really annoying, which is why I've gotten into the habit of escaping with Ctrl+c, it's much faster.

hora
You can also use Ctrl-[, which is an alias for Esc. Ctrl-c is more destructive since it will abort the current command rather than just exit from insert mode.
Dave Kirby
+3  A: 

One command that will really improve your movement speeds is f. f plus a character will jump to the first occurrence of that character on the current line. Pressing ; will jump to the next occurrence. Of course this can be used in combination with other commands. So, for example, removing all characters up to and including the first closing parenthesis is achieved by pressing d+f+).

Ton van den Heuvel
And F (uppercase f) will jump to the previous character.
Charles Roper
and T and t are like F and f but don't include the target character. Want to delete up to the closing quote? `dt"`!
dash-tom-bang
A: 

I almost never use hjkl because it's too tedious. I usually try to jump right to where I want to go. There's a great cheat sheet out there (a Dvorak version is a available also (although it's in PDF)) that you can stare at and imagine the possibilities.

Mostly I use f, F, t, and T, and sometimes they're enhanced by typing a number up front like d2t) will delete up to the second close paren. Sometimes I use search. A lot of the time I use w, W, b, B, e, and E. They're all fantastic.

When I see vim users arrowing all over the place in visual mode just to delete text it makes me shudder, because there are so much easier ways (and hjkl only make you move your arm less, they don't change the number of button presses).

Something I did that I don't know if it's common or not is remapped my arrow keys to be <Esc><Up> and so on. For whatever reason I started out always arrowing around and assuming I'd be back in normal mode, so I just made it do that...

The biggest bummer about Vim is that now when I edit anything anywhere else I hit escape all of the time and type :w after every change...

dash-tom-bang