Skip to content

Instantly share code, notes, and snippets.

@Frost
Created July 31, 2012 16:02
Show Gist options
  • Select an option

  • Save Frost/3218080 to your computer and use it in GitHub Desktop.

Select an option

Save Frost/3218080 to your computer and use it in GitHub Desktop.
macro for jumping to a relative line in vim
" prompt user for a line to jump to.
" accepts N, +N or -N as input.
" -N will be equivalent of just typing N-
" +N equals typing N+ or running :N
function! JumpToRelativeLine()
let linenumber = line('.')
call inputsave()
let line = input('go to line: ')
call inputrestore()
call setpos('.', [0,eval(linenumber + line),0,0])
endfunction
" map <c-j> set relative line numbers, run the above function, and then reset line numbers.
map <c-j> :set rnu<CR>:call JumpToRelativeLine()<CR>:set nu<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment