Skip to content

Instantly share code, notes, and snippets.

@strokirk
Created September 22, 2014 13:00
Show Gist options
  • Select an option

  • Save strokirk/1ed2dcb0c6e7a78811ec to your computer and use it in GitHub Desktop.

Select an option

Save strokirk/1ed2dcb0c6e7a78811ec to your computer and use it in GitHub Desktop.
function! CountSpaces(line)
return strlen(substitute(a:line, '^ *\zs[^ ].*', '', ''))
endfunction
" Move to the next or previous line with less indent than the current line.
function! IndentSearchLess(dir)
let spaces = CountSpaces(getline('.'))
if spaces == 0
return
endif
let pattern = '^ \{0,'.(spaces-1).'}[^ ]'
call search(pattern, a:dir . 'eW')
endfunction
" Move to the next or previous line with more indent than the current line.
function! IndentSearchMore(dir)
let spaces = CountSpaces(getline('.'))
let pattern = '^ \{'.(spaces+1).',}[^ ]'
" FIXME: Currenly jumps past dedents
call search(pattern, a:dir . 'eW')
endfunction
" Some basic mappings using the [] standard
nnoremap [f :call IndentSearchLess('b')<cr>
nnoremap ]f :call IndentSearchLess('')<cr>
nnoremap [F :call IndentSearchMore('b')<cr>
nnoremap ]F :call IndentSearchMore('')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment