Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Created July 22, 2011 07:04
Show Gist options
  • Save AndrewRadev/1099011 to your computer and use it in GitHub Desktop.
Save AndrewRadev/1099011 to your computer and use it in GitHub Desktop.
nnoremap << :call <SID>KeepCursorAfterShift('<<', -1)<cr>
nnoremap >> :call <SID>KeepCursorAfterShift('>>', 1)<cr>
function! s:KeepCursorAfterShift(cmd, modifier)
let column = col('.')
exe "normal! ".a:cmd
call cursor(line('.'), column + a:modifier * &shiftwidth)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment