aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorTeddy Wing2018-03-05 20:55:57 +0100
committerTeddy Wing2018-03-05 20:55:57 +0100
commit1bb1fe8927ad8df734adaf89cee0c95b04a396eb (patch)
tree2711dba795171b14c73373612266d1b134b6de91 /plugin
parent1826d17d9b0e9aec18d1b50ac0874defb46901b3 (diff)
downloadvim-rails-locale-alternate-1bb1fe8927ad8df734adaf89cee0c95b04a396eb.tar.bz2
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.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/rails_locale_alternate.vim16
1 files 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(<q-args>, <q-mods>)
-command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale(<q-args>)
-command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(<q-args>, '')
-command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(<q-args>, 'vertical')
+function! s:CreateCommands()
+ command! -buffer -nargs=1 RailsLocaleAlternate :call s:SplitAlternate(<q-args>, <q-mods>)
+ command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale(<q-args>)
+ command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(<q-args>, '')
+ command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(<q-args>, 'vertical')
+endfunction
+
+augroup rails_locale_alternate
+ autocmd!
+
+ autocmd BufNewFile,BufRead config/locales/*.\a\a.yml call s:CreateCommands()
+augroup END