Wikia

Vim Tips Wiki

Precise Jumps Without Mouse

Talk0
1,599pages on
this wiki
Revision as of 22:15, November 14, 2012 by 216.67.49.7 (Talk)

Recently created tip

We have not yet decided whether to keep this tip as its own page or merge it somewhere else. If you have a suggestion on the tip content, please edit this page or add your comments below (do not use the discussion page).

Please discuss whether to keep this as a new tip, or whether to merge it into an existing tip, on the new tips discussion page.
created March 21, 2012 · complexity basic · author Q335r49 · version 7.0

Making precise jumps around the screen is easy with a mouse but harder with vim's default movement commands. Perhaps your device lacks a pointer, or perhaps mousing ruins your flow. In this case we can do direct jumps by labeling the text. For example,

Is this the real life or is this just fantasy? becomes
0s 1his 2he 3eal 4ife 5r 6s 7his 8ust 9antasy?

and typing "9" would jump to "fantasy".

In the following:

  • The LABELS list can be modified, but labels are limited to a single character.
  • The labeling repeats. To remedy this there are two prompts: the first for the label, the second for which cycle (1,2,3,etc.). The screen is redrawn with the cycle number before the second prompt. So, for example, "K2" jumps to the second occurrence of K.
  • A mapping to "K" (which defaults to man lookup) is included, and is set to label the first 248 words.

Place this in your vimrc:

let LABEL = ["a","b","c",
\"d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s",
\"t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I",
\"J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y",
\"Z","1","2","3","4","5","6","7","8","9","0"]
function! GoTo(range)
    normal! Hmt
    for i in range(0,a:range)
        exe 'normal! Wr' . g:LABEL[i%len(g:LABEL)]
    endfor
    normal! 'tzt
    echo "Index?"
    redraw
    let label=nr2char(getchar())
    normal! u'tzt
    for i in range(0,a:range)
        exe 'normal! Wr' . (1+i/len(g:LABEL))
    endfor
    normal! 'tzt
    echo "Number?"
    redraw
    let offset=getchar()
    let offset=(49 <= offset && offset <= 57) ? offset-48 : 1
    normal! u'tzt
    let index=index(g:LABEL,label)
    exe 'normal! ' . ((offset-1)*len(g:LABEL)+index+1) . 'W'
endfu
nnoremap <TAB> :call GoTo(248)<CR>

Comments

Is it work mentioning EasyMotion here? It basically provides this functionality plus more...

Advertisement | Your ad here

Photos

Add a Photo
103photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki