Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
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",
function! GoTo(range)
    normal! Hmt
    for i in range(0,a:range)
        exe 'normal! Wr' . g:LABEL[i%len(g:LABEL)]
    normal! 'tzt
    echo "Index?"
    let label=nr2char(getchar())
    normal! u'tzt
    for i in range(0,a:range)
        exe 'normal! Wr' . (1+i/len(g:LABEL))
    normal! 'tzt
    echo "Number?"
    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'
nnoremap <TAB> :call GoTo(248)<CR>

Related pluginsEdit

  • The EasyMotion plugin provides exactly this functionality and more.


Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.