mirror of
https://github.com/gryf/tagbar.git
synced 2025-12-17 11:30:28 +01:00
Make keybindings configurable, closes #159
This commit is contained in:
@@ -919,35 +919,38 @@ function! s:MapKeys() abort
|
||||
inoremap <script> <silent> <buffer> <LeftRelease>
|
||||
\ <LeftRelease><C-o>:call <SID>CheckMouseClick()<CR>
|
||||
|
||||
nnoremap <script> <silent> <buffer> <CR> :call <SID>JumpToTag(0)<CR>
|
||||
nnoremap <script> <silent> <buffer> p :call <SID>JumpToTag(1)<CR>
|
||||
nnoremap <script> <silent> <buffer> <Space> :call <SID>ShowPrototype(0)<CR>
|
||||
let maps = [
|
||||
\ ['jump', 'JumpToTag(0)'],
|
||||
\ ['preview', 'JumpToTag(1)'],
|
||||
\ ['nexttag', 'GotoNextToplevelTag(1)'],
|
||||
\ ['prevtag', 'GotoNextToplevelTag(-1)'],
|
||||
\ ['showproto', 'ShowPrototype(0)'],
|
||||
\
|
||||
\ ['openfold', 'OpenFold()'],
|
||||
\ ['closefold', 'CloseFold()'],
|
||||
\ ['togglefold', 'ToggleFold()'],
|
||||
\ ['openallfolds', 'SetFoldLevel(99, 1)'],
|
||||
\ ['closeallfolds', 'SetFoldLevel(0, 1)'],
|
||||
\
|
||||
\ ['togglesort', 'ToggleSort()'],
|
||||
\ ['zoomwin', 'ZoomWindow()'],
|
||||
\ ['close', 'CloseWindow()'],
|
||||
\ ['help', 'ToggleHelp()'],
|
||||
\ ]
|
||||
|
||||
nnoremap <script> <silent> <buffer> + :call <SID>OpenFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> <kPlus> :call <SID>OpenFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> zo :call <SID>OpenFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> - :call <SID>CloseFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> <kMinus> :call <SID>CloseFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> zc :call <SID>CloseFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> o :call <SID>ToggleFold()<CR>
|
||||
nnoremap <script> <silent> <buffer> za :call <SID>ToggleFold()<CR>
|
||||
|
||||
nnoremap <script> <silent> <buffer> * :call <SID>SetFoldLevel(99, 1)<CR>
|
||||
nnoremap <script> <silent> <buffer> <kMultiply>
|
||||
\ :call <SID>SetFoldLevel(99, 1)<CR>
|
||||
nnoremap <script> <silent> <buffer> zR :call <SID>SetFoldLevel(99, 1)<CR>
|
||||
nnoremap <script> <silent> <buffer> = :call <SID>SetFoldLevel(0, 1)<CR>
|
||||
nnoremap <script> <silent> <buffer> zM :call <SID>SetFoldLevel(0, 1)<CR>
|
||||
|
||||
nnoremap <script> <silent> <buffer> <C-N>
|
||||
\ :call <SID>GotoNextToplevelTag(1)<CR>
|
||||
nnoremap <script> <silent> <buffer> <C-P>
|
||||
\ :call <SID>GotoNextToplevelTag(-1)<CR>
|
||||
|
||||
nnoremap <script> <silent> <buffer> s :call <SID>ToggleSort()<CR>
|
||||
nnoremap <script> <silent> <buffer> x :call <SID>ZoomWindow()<CR>
|
||||
nnoremap <script> <silent> <buffer> q :call <SID>CloseWindow()<CR>
|
||||
nnoremap <script> <silent> <buffer> <F1> :call <SID>ToggleHelp()<CR>
|
||||
for [map, func] in maps
|
||||
let def = get(g:, 'tagbar_map_' . map)
|
||||
if type(def) == type("")
|
||||
let keys = [def]
|
||||
else
|
||||
let keys = def
|
||||
endif
|
||||
for key in keys
|
||||
execute 'nnoremap <script> <silent> <buffer> ' . key .
|
||||
\ ' :call <SID>' . func . '<CR>'
|
||||
endfor
|
||||
unlet def
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" s:CreateAutocommands() {{{2
|
||||
@@ -2729,28 +2732,36 @@ function! s:PrintHelp() abort
|
||||
silent 0put ='\" Tagbar keybindings'
|
||||
silent put ='\"'
|
||||
silent put ='\" --------- General ---------'
|
||||
silent put ='\" <Enter> : Jump to tag definition'
|
||||
silent put ='\" p : As above, but stay in'
|
||||
silent put ='\" Tagbar window'
|
||||
silent put ='\" <C-N> : Go to next top-level tag'
|
||||
silent put ='\" <C-P> : Go to previous top-level tag'
|
||||
silent put ='\" <Space> : Display tag prototype'
|
||||
silent put ='\" ' . s:get_map_str('jump') . ': Jump to tag definition'
|
||||
silent put ='\" ' . s:get_map_str('preview') . ': As above, but stay in'
|
||||
silent put ='\" Tagbar window'
|
||||
silent put ='\" ' . s:get_map_str('nexttag') . ': Go to next top-level tag'
|
||||
silent put ='\" ' . s:get_map_str('prevtag') . ': Go to previous top-level tag'
|
||||
silent put ='\" ' . s:get_map_str('showproto') . ': Display tag prototype'
|
||||
silent put ='\"'
|
||||
silent put ='\" ---------- Folds ----------'
|
||||
silent put ='\" +, zo : Open fold'
|
||||
silent put ='\" -, zc : Close fold'
|
||||
silent put ='\" o, za : Toggle fold'
|
||||
silent put ='\" *, zR : Open all folds'
|
||||
silent put ='\" =, zM : Close all folds'
|
||||
silent put ='\" ' . s:get_map_str('openfold') . ': Open fold'
|
||||
silent put ='\" ' . s:get_map_str('closefold') . ': Close fold'
|
||||
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 ='\"'
|
||||
silent put ='\" ---------- Misc -----------'
|
||||
silent put ='\" s : Toggle sort'
|
||||
silent put ='\" x : Zoom window in/out'
|
||||
silent put ='\" q : Close window'
|
||||
silent put ='\" <F1> : Remove help'
|
||||
silent put ='\" ' . s:get_map_str('togglesort') . ': Toggle sort'
|
||||
silent put ='\" ' . s:get_map_str('zoomwin') . ': Zoom window in/out'
|
||||
silent put ='\" ' . s:get_map_str('close') . ': Close window'
|
||||
silent put ='\" ' . s:get_map_str('help') . ': Toggle help'
|
||||
silent put _
|
||||
endif
|
||||
endfunction
|
||||
function! s:get_map_str(map) abort
|
||||
let def = get(g:, 'tagbar_map_' . a:map)
|
||||
if type(def) == type("")
|
||||
return def
|
||||
else
|
||||
return join(def, ', ')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" s:RenderKeepView() {{{2
|
||||
" The gist of this function was taken from NERDTree by Martin Grenfell.
|
||||
|
||||
@@ -311,27 +311,51 @@ KEY MAPPINGS *tagbar-keys*
|
||||
The following mappings are valid in the Tagbar window:
|
||||
|
||||
<F1> Display key mapping help.
|
||||
Map option: tagbar_map_help
|
||||
<CR>/<Enter> Jump to the tag under the cursor. Doesn't work for pseudo-tags
|
||||
or generic headers.
|
||||
Map option: tagbar_map_jump
|
||||
p Jump to the tag under the cursor, but stay in the Tagbar window.
|
||||
Map option: tagbar_map_preview
|
||||
<LeftMouse> When on a fold icon, open or close the fold depending on the
|
||||
current state.
|
||||
<2-LeftMouse> Same as <CR>. See |g:tagbar_singleclick| if you want to use a
|
||||
single- instead of a double-click.
|
||||
<C-N> Go to the next top-level tag.
|
||||
Map option: tagbar_map_nexttag
|
||||
<C-P> Go to the previous top-level tag.
|
||||
Map option: tagbar_map_prevtag
|
||||
<Space> Display the prototype of the current tag (i.e. the line defining
|
||||
it) in the command line.
|
||||
Map option: tagbar_map_showproto
|
||||
+/zo Open the fold under the cursor.
|
||||
Map option: tagbar_map_openfold
|
||||
-/zc Close the fold under the cursor or the current one if there is
|
||||
no fold under the cursor.
|
||||
Map option: tagbar_map_closefold
|
||||
o/za Toggle the fold under the cursor or the current one if there is
|
||||
no fold under the cursor.
|
||||
Map option: tagbar_map_togglefold
|
||||
*/zR Open all folds by setting foldlevel to 99.
|
||||
Map option: tagbar_map_openallfolds
|
||||
=/zM Close all folds by setting foldlevel to 0.
|
||||
<C-N> Go to the next top-level tag.
|
||||
<C-P> Go to the previous top-level tag.
|
||||
Map option: tagbar_map_closeallfolds
|
||||
s Toggle sort order between name and file order.
|
||||
Map option: tagbar_map_togglesort
|
||||
x Toggle zooming the window.
|
||||
Map option: tagbar_map_zoomwin
|
||||
q Close the Tagbar window.
|
||||
Map option: tagbar_map_close
|
||||
|
||||
These mappings can be redefined with the given map options. The argument can
|
||||
be either a string or a |List| of strings. In the latter case the
|
||||
functionality will be assigned to all of the keys in the list. For example, if
|
||||
you want to remap the sort toggling functionality to "r":
|
||||
>
|
||||
let g:tagbar_map_togglesort = "r"
|
||||
<
|
||||
See |key-notation| for how to write special keys like <Space> or the keypad
|
||||
keys.
|
||||
|
||||
==============================================================================
|
||||
5. Configuration *tagbar-configuration*
|
||||
|
||||
@@ -44,7 +44,7 @@ endif
|
||||
|
||||
function! s:init_var(var, value) abort
|
||||
if !exists('g:tagbar_' . a:var)
|
||||
execute 'let g:tagbar_' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", 'g') . "'"
|
||||
execute 'let g:tagbar_' . a:var . ' = ' . string(a:value)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -67,6 +67,7 @@ let s:options = [
|
||||
for [opt, val] in s:options
|
||||
call s:init_var(opt, val)
|
||||
endfor
|
||||
unlet s:options
|
||||
|
||||
if !exists('g:tagbar_iconchars')
|
||||
if has('multi_byte') && has('unix') && &encoding == 'utf-8' &&
|
||||
@@ -77,6 +78,31 @@ if !exists('g:tagbar_iconchars')
|
||||
endif
|
||||
endif
|
||||
|
||||
let s:keymaps = [
|
||||
\ ['jump', '<CR>'],
|
||||
\ ['preview', 'p'],
|
||||
\ ['nexttag', '<C-N>'],
|
||||
\ ['prevtag', '<C-P>'],
|
||||
\ ['showproto', '<Space>'],
|
||||
\
|
||||
\ ['openfold', ['+', '<kPlus>', 'zo']],
|
||||
\ ['closefold', ['-', '<kMinus>', 'zc']],
|
||||
\ ['togglefold', ['o', 'za']],
|
||||
\ ['openallfolds', ['*', '<kMultiply>', 'zR']],
|
||||
\ ['closeallfolds', ['=', 'zM']],
|
||||
\
|
||||
\ ['togglesort', 's'],
|
||||
\ ['zoomwin', 'x'],
|
||||
\ ['close', 'q'],
|
||||
\ ['help', '<F1>'],
|
||||
\ ]
|
||||
|
||||
for [map, key] in s:keymaps
|
||||
call s:init_var('map_' . map, key)
|
||||
unlet key
|
||||
endfor
|
||||
unlet s:keymaps
|
||||
|
||||
augroup TagbarSession
|
||||
autocmd!
|
||||
autocmd SessionLoadPost * nested call tagbar#RestoreSession()
|
||||
|
||||
Reference in New Issue
Block a user