Created
October 21, 2011 08:09
-
-
Save Dubhead/1303340 to your computer and use it in GitHub Desktop.
Go to the next (or previous) line with the same indentation to the current line (or less than), ignoring empty lines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" GoUp | |
" include guard | |
"if exists("g:loaded_GoUp") && g:loaded_GoUp | |
" finish | |
"endif | |
"let g:loaded_GoUp = 1 | |
" Go to the next (or previous) line with the same indentation to the | |
" current line (or less than), ignoring empty lines. | |
function! GoUp(forward, lessIndent) | |
if a:forward == 1 | |
let l:increment = 1 | |
else | |
let l:increment = -1 | |
endif | |
if a:lessIndent | |
let l:numIndents = indent(".") - 1 | |
else | |
let l:numIndents = indent(".") | |
endif | |
let l:lastLine = line("$") | |
let l:destLine = line(".") + l:increment | |
while (1 <= l:destLine) && (l:destLine <= l:lastLine) | |
if (indent(l:destLine) <= l:numIndents) && (getline(l:destLine) != "") | |
call cursor(l:destLine, 0) | |
return | |
endif | |
let l:destLine += l:increment | |
endwhile | |
endfunction | |
" suggested keymaps | |
noremap <silent> g[ :call GoUp(0, 0)<CR>^ | |
noremap <silent> g] :call GoUp(1, 0)<CR>^ | |
noremap <silent> g{ :call GoUp(0, 1)<CR>^ | |
noremap <silent> g} :call GoUp(1, 1)<CR>^ | |
" eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment