Vim: move around quickly inside of long line

后端 未结 8 562
轻奢々
轻奢々 2020-12-22 18:50

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

相关标签:
8条回答
  • 2020-12-22 19:18

    You can use ( and ) to navigate by sentence; it just looks for ., but that can be immensely helpful, especially if you don't like the sentence and want to change it: (c) will jump to the beginning of the current sentence, then change the entire sentence.

    You can also use w and e, with count modifiers, to move words. 3w will move three words at a time.

    You can also use f and F to search forward and backwards for a specific character. This is much more useful if you're looking for the word quite or syzygy than the. :)

    0 讨论(0)
  • 2020-12-22 19:20

    Please notice that using "g" followed by Up or Down arrows indeed works fine, but if you have long lines and move quickly you may enter "gg" by mistake and end-up at the top of the text...! (Undo will not bring you back, and AFAIK there is not one-key-pressed way to go back to where you were.)

    It happened to me too many times.

    What I did was, and I suggest you, to modify (or create) your "~/.vimrc" and add these two lines:

    map <C-Up> g<Up>
    map <C-Down> g<Down>
    

    This will map you control-up and control-down to the movements commands. Will make mistyping "gg" impossible and is perfectly coherent with control-right and control-left to move around long lines.

    If you add these other two lines, you can use the same command in insert mode (!)

    imap <C-Up> <C-[> g<Up> i
    imap <C-Down> <C-[> g<Down> i
    

    (VIM is great !)

    Greg Ruo

    0 讨论(0)
  • 2020-12-22 19:21

    My preferred strategy while jumping around long lines is to use f F and t T to zero in on the character. What makes this family of motions supercharged is that you can utilize the ; and , motions, so you don't have to count the position of character relative to cursor, but just step through them (extremely useful with ' " . etc)

    Let's say we have a line:

    reallyLongObjectName.longMethod().prettyPrettyLongMethod().burp();
    

    If we need to jump to, say, the third dot from the beginning of the line, we can use either 3f. or f.;; visiting two dots and landing on third.

    While the ; , style can use more keystrokes, I found it more agile and fun overall.

    0 讨论(0)
  • 2020-12-22 19:27

    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.

    0 讨论(0)
  • 2020-12-22 19:33

    I recently started using a plugin that I find really nice to move very quickly inside a line (or the hole file).

    The plugin's name is PreciseJump and you can find it here.

    When you use this plugin it defines to mappings _f and _F.

    if you type _f followed by x it will highlight all x characters and will replace temporarily with other characters that you can press to jump to that location. Check the script page for an illustration.

    0 讨论(0)
  • 2020-12-22 19:33

    You can also move around with W B that will skip to the next space :) G moves to the end of the document

    0 讨论(0)
提交回复
热议问题