From 1bb1fe8927ad8df734adaf89cee0c95b04a396eb Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 5 Mar 2018 20:55:57 +0100 Subject: Use an `autocmd` to create the commands To ensure these commands are only created for Rails locale buffers, use an `autocmd` that matches any locale YAML files in the Rails `config/locales/` directory or subdirectories. --- plugin/rails_locale_alternate.vim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugin/rails_locale_alternate.vim b/plugin/rails_locale_alternate.vim index 0fa0d23..b0a82f0 100644 --- a/plugin/rails_locale_alternate.vim +++ b/plugin/rails_locale_alternate.vim @@ -10,7 +10,15 @@ function! s:SplitAlternate(key, modifiers) endfunction -command! -buffer -nargs=1 RailsLocaleAlternate :call s:SplitAlternate(, ) -command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale() -command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(, '') -command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(, 'vertical') +function! s:CreateCommands() + command! -buffer -nargs=1 RailsLocaleAlternate :call s:SplitAlternate(, ) + command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale() + command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(, '') + command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(, 'vertical') +endfunction + +augroup rails_locale_alternate + autocmd! + + autocmd BufNewFile,BufRead config/locales/*.\a\a.yml call s:CreateCommands() +augroup END -- cgit v1.2.3