Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: move around quickly inside of long line

Tags:

vim

I have word-wrap enabled and tend to have quite long lines. But moving around inside a line that's actually 4 lines high with "w" is cumbersome. I keep using / to jump to the word I'm looking for, but that seems overdoing it a bit.

Any hints on how to move more quickly inside of a line?

Thanks,

MrB

like image 216
MrBubbles Avatar asked Mar 29 '11 21:03

MrBubbles


People also ask

How do I move around in vim?

To move left, press h . To move right, press l . To move down, press j . To move up, press k .

How do you move between lines in vim?

In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up. After visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up.

What is Ctrl I in vim?

In insert mode, Ctrl-o escapes user to do one normal-mode command, and then return to the insert mode. The same effect can be achieved by <ESC> ing to normal mode, doing the single command and then entering back to insert mode. Ctrl-i is simply a <Tab> in insert mode.


2 Answers

  • You can use $, 0, and ^ to move to line endpoints and then use w and b. Also, adding a numeric argument to w and b can accelerate the process, so using 6w instead of just w can put you about to where ou need to be.
  • Using f and t to move to individual characters will help also. (I use this typically with punctuation. If, for example, I have four sentences on one long line 2f. will go to the end of the second sentence)
  • Using the ( and ) keys are an alternative way to navigate entire sentences.
  • Splitting out long lines into multiple lines (manually, or with set tw=72 [or 80]) can make editing them simpler. You can always join them later with J.
  • Something I just discovered, you can move up and down one displayed line by using gj and gk. That way, you can treat your one wrapped line as multiple lines.

If you comment on the type of data you're editing, it might make it easier for us to make suggestions.

like image 63
yan Avatar answered Sep 30 '22 01:09

yan


I think you can benefit from gk and gj instead of just k and j.

Also look at 'virtualedit' for some options that allow you to cursor through 'void' areas without flicking the cursor to the next best physical character.

You might want to (temporarily)

nnoremap <buffer> k gk nnoremap <buffer> j gj 

Leave out the <buffer> part to apply this globally.

like image 38
sehe Avatar answered Sep 30 '22 01:09

sehe