mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 22:20:06 +08:00
feat(mapping): add gD
to go to declaration
This commit is contained in:
parent
e1d68de4c2
commit
d94bdb6f88
@ -150,6 +150,10 @@ endfunction
|
|||||||
|
|
||||||
" config {{{
|
" config {{{
|
||||||
function! SpaceVim#layers#lang#c#config() abort
|
function! SpaceVim#layers#lang#c#config() abort
|
||||||
|
call SpaceVim#mapping#g_capital_d#add('c',
|
||||||
|
\ function('s:go_to_declaration'))
|
||||||
|
call SpaceVim#mapping#g_capital_d#add('cpp',
|
||||||
|
\ function('s:go_to_declaration'))
|
||||||
call SpaceVim#mapping#gd#add('c',
|
call SpaceVim#mapping#gd#add('c',
|
||||||
\ function('s:go_to_def'))
|
\ function('s:go_to_def'))
|
||||||
call SpaceVim#mapping#gd#add('cpp',
|
call SpaceVim#mapping#gd#add('cpp',
|
||||||
@ -309,7 +313,6 @@ function! s:language_specified_mappings() abort
|
|||||||
\ 'call SpaceVim#lsp#go_to_typedef()', 'type definition', 1)
|
\ 'call SpaceVim#lsp#go_to_typedef()', 'type definition', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'R'],
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'R'],
|
||||||
\ 'call SpaceVim#lsp#refactor()', 'refactor', 1)
|
\ 'call SpaceVim#lsp#refactor()', 'refactor', 1)
|
||||||
" TODO this should be gD
|
|
||||||
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'D'],
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'D'],
|
||||||
\ 'call SpaceVim#lsp#go_to_declaration()', 'declaration', 1)
|
\ 'call SpaceVim#lsp#go_to_declaration()', 'declaration', 1)
|
||||||
|
|
||||||
@ -452,6 +455,16 @@ function! s:update_neoinclude(argv, fts) abort
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
" local function: go_to_declaration {{{
|
||||||
|
function! s:go_to_declaration() abort
|
||||||
|
if !SpaceVim#layers#lsp#check_filetype(&ft)
|
||||||
|
execute "norm! g\<c-]>"
|
||||||
|
else
|
||||||
|
call SpaceVim#lsp#go_to_declaration()
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}
|
||||||
|
|
||||||
" local function: go_to_def {{{
|
" local function: go_to_def {{{
|
||||||
function! s:go_to_def() abort
|
function! s:go_to_def() abort
|
||||||
if !SpaceVim#layers#lsp#check_filetype(&ft)
|
if !SpaceVim#layers#lsp#check_filetype(&ft)
|
||||||
|
@ -106,6 +106,14 @@ function! SpaceVim#mapping#enter() abort
|
|||||||
return SpaceVim#mapping#enter#i_enter()
|
return SpaceVim#mapping#enter#i_enter()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#mapping#g_capital_d() abort
|
||||||
|
if !empty(SpaceVim#mapping#g_capital_d#get())
|
||||||
|
call call(SpaceVim#mapping#g_capital_d#get(), [])
|
||||||
|
else
|
||||||
|
normal! gD
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#mapping#gd() abort
|
function! SpaceVim#mapping#gd() abort
|
||||||
if !empty(SpaceVim#mapping#gd#get())
|
if !empty(SpaceVim#mapping#gd#get())
|
||||||
call call(SpaceVim#mapping#gd#get(), [])
|
call call(SpaceVim#mapping#gd#get(), [])
|
||||||
|
@ -107,8 +107,10 @@ function! SpaceVim#mapping#g#init() abort
|
|||||||
nnoremap gv gv
|
nnoremap gv gv
|
||||||
let g:_spacevim_mappings_g['<C-]>'] = ['call feedkeys("g<c-]>", "n")', 'jump-to-tag-under-cursor']
|
let g:_spacevim_mappings_g['<C-]>'] = ['call feedkeys("g<c-]>", "n")', 'jump-to-tag-under-cursor']
|
||||||
nnoremap g<c-]> g<c-]>
|
nnoremap g<c-]> g<c-]>
|
||||||
|
let g:_spacevim_mappings_g['D'] = ['call SpaceVim#mapping#g_capital_d()', 'goto-declaration']
|
||||||
|
call SpaceVim#mapping#def('nnoremap <silent>', 'gD', ':call SpaceVim#mapping#g_capital_d()<CR>', 'Goto declaration', '')
|
||||||
let g:_spacevim_mappings_g['d'] = ['call SpaceVim#mapping#gd()', 'goto-definition']
|
let g:_spacevim_mappings_g['d'] = ['call SpaceVim#mapping#gd()', 'goto-definition']
|
||||||
call SpaceVim#mapping#def('nnoremap <silent>', 'gd', ':call SpaceVim#mapping#gd()<CR>', 'Goto declaration', '')
|
call SpaceVim#mapping#def('nnoremap <silent>', 'gd', ':call SpaceVim#mapping#gd()<CR>', 'Goto definition', '')
|
||||||
|
|
||||||
let g:_spacevim_mappings_g['='] = ['call SpaceVim#mapping#format()', 'format-current-buffer']
|
let g:_spacevim_mappings_g['='] = ['call SpaceVim#mapping#format()', 'format-current-buffer']
|
||||||
call SpaceVim#mapping#def('nnoremap <silent>','g=',':call SpaceVim#mapping#format()<cr>','format current buffer','call SpaceVim#mapping#format()')
|
call SpaceVim#mapping#def('nnoremap <silent>','g=',':call SpaceVim#mapping#format()<cr>','format current buffer','call SpaceVim#mapping#format()')
|
||||||
|
16
autoload/SpaceVim/mapping/g_capital_d.vim
Normal file
16
autoload/SpaceVim/mapping/g_capital_d.vim
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"=============================================================================
|
||||||
|
" g_capital_d.vim --- gD key binding
|
||||||
|
" Copyright (c) 2016-2022 Wang Shidong & Contributors
|
||||||
|
" Author: sisynb < bsixxxx at gmail.com >
|
||||||
|
" URL: https://spacevim.org
|
||||||
|
" License: GPLv3
|
||||||
|
"=============================================================================
|
||||||
|
|
||||||
|
let s:g_capital_d = {}
|
||||||
|
function! SpaceVim#mapping#g_capital_d#add(ft, func) abort
|
||||||
|
call extend(s:g_capital_d,{a:ft : a:func})
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#mapping#g_capital_d#get() abort
|
||||||
|
return get(s:g_capital_d, &filetype, '')
|
||||||
|
endfunction
|
Loading…
Reference in New Issue
Block a user