Add mappings for moving through folds, closes #224

This commit is contained in:
Jan Larres 2014-11-09 17:33:42 +13:00
parent f933907afa
commit df09799372
3 changed files with 65 additions and 0 deletions

View File

@ -955,6 +955,8 @@ function! s:MapKeys() abort
\ ['togglefold', 'ToggleFold()'],
\ ['openallfolds', 'SetFoldLevel(99, 1)'],
\ ['closeallfolds', 'SetFoldLevel(0, 1)'],
\ ['nextfold', 'GotoNextFold()'],
\ ['prevfold', 'GotoPrevFold()'],
\
\ ['togglesort', 'ToggleSort()'],
\ ['toggleautoclose', 'ToggleAutoclose()'],
@ -2854,6 +2856,8 @@ function! s:PrintHelp() abort
silent put ='\" ' . s:get_map_str('togglefold') . ': Toggle fold'
silent put ='\" ' . s:get_map_str('openallfolds') . ': Open all folds'
silent put ='\" ' . s:get_map_str('closeallfolds') . ': Close all folds'
silent put ='\" ' . s:get_map_str('nextfold') . ': Go to next fold'
silent put ='\" ' . s:get_map_str('prevfold') . ': Go to previous fold'
silent put ='\"'
silent put ='\" ---------- Misc -----------'
silent put ='\" ' . s:get_map_str('togglesort') . ': Toggle sort'
@ -3302,6 +3306,61 @@ function! s:OpenParents(...) abort
endif
endfunction
" s:GotoNextFold() {{{2
function! s:GotoNextFold() abort
let curlinenr = line('.')
let newlinenr = line('.')
let range = range(line('.') + 1, line('$'))
for linenr in range
let taginfo = s:GetTagInfo(linenr, 0)
if empty(taginfo)
continue
elseif !empty(get(taginfo, 'children', [])) || taginfo.isKindheader()
let newlinenr = linenr
break
endif
endfor
if curlinenr != newlinenr
execute linenr
call winline()
endif
redraw
endfunction
" s:GotoPrevFold() {{{2
function! s:GotoPrevFold() abort
let curlinenr = line('.')
let newlinenr = line('.')
let curtag = s:GetTagInfo(curlinenr, 0)
let curparent = get(curtag, 'parent', {})
let range = range(line('.') - 1, 1, -1)
for linenr in range
let taginfo = s:GetTagInfo(linenr, 0)
if empty(taginfo)
continue
elseif !empty(taginfo.parent) && taginfo.parent != curparent &&
\ empty(get(taginfo, 'children', []))
let newlinenr = linenr
break
endif
endfor
if curlinenr != newlinenr
execute linenr
call winline()
endif
redraw
endfunction
" Helper functions {{{1
" s:AutoUpdate() {{{2
function! s:AutoUpdate(fname, force) abort

View File

@ -347,6 +347,10 @@ o/za Toggle the fold under the cursor or the current one if there is
Map option: tagbar_map_openallfolds
=/zM Close all folds by setting foldlevel to 0.
Map option: tagbar_map_closeallfolds
zj Go to the start of the next fold, like the standard Vim |zj|.
Map option: tagbar_map_nextfold
zk Go to the end of the previous fold, like the standard Vim |zk|.
Map option: tagbar_map_prevfold
s Toggle sort order between name and file order.
Map option: tagbar_map_togglesort
c Toggle the |g:tagbar_autoclose| option.

View File

@ -104,6 +104,8 @@ let s:keymaps = [
\ ['togglefold', ['o', 'za']],
\ ['openallfolds', ['*', '<kMultiply>', 'zR']],
\ ['closeallfolds', ['=', 'zM']],
\ ['nextfold', 'zj'],
\ ['prevfold', 'zk'],
\
\ ['togglesort', 's'],
\ ['toggleautoclose', 'c'],