Skip to content

Commit

Permalink
Set <leader>ct shortcut to use Git ctags hook
Browse files Browse the repository at this point in the history
In cbdcbce we introduced a Tim
Pope-inspired Git template scheme that automatically ran `ctags`
asynchronously through a hook after certain source control operations.
This hook is bypassed if a user uses `<leader>ct` to reindex their tags
from within Vim.

This change binds `<leader>ct` to use a Vimscript function that will
identify if the `ctags` hook exists in the local repository and executes
it. The function falls back to existing functionality if the hook does
not exist. We are moving the function out of `vimrc` as a first step
toward breaking our Vim configuration up by topic area.
  • Loading branch information
geoffharcourt committed Nov 29, 2015
1 parent 8597a61 commit 76aa931
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 15 additions & 0 deletions vim/plugin/ctags.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" Exclude Javascript files in :Rtags via rails.vim due to warnings when parsing
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"

" Index ctags from any project, including those outside Rails
function! ReindexCtags()
let l:ctags_hook = '$(git rev-parse --show-toplevel)/.git/hooks/ctags'

if exists(l:ctags_hook)
exec '!'. l:ctags_hook
else
exec "!ctags -R ."
endif
endfunction

nmap <Leader>ct :call ReindexCtags()<CR>
6 changes: 0 additions & 6 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" Exclude Javascript files in :Rtags via rails.vim due to warnings when parsing
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"

" Index ctags from any project, including those outside Rails
map <Leader>ct :!ctags -R .<CR>
" Switch between the last two files
nnoremap <leader><leader> <c-^>
Expand Down

0 comments on commit 76aa931

Please sign in to comment.