make switching index.js component.js into vimscript

This commit is contained in:
hophacker 2018-11-27 10:12:57 +08:00
parent 6f8b576585
commit 1905ef741b
2 changed files with 11 additions and 28 deletions

View File

@ -1,28 +0,0 @@
if !has('ruby')
echo "Error: Required vim compiled with +ruby"
finish
endif
if exists('g:loaded_ruby_fix_plugin')
finish
endif
let g:loaded_ruby_fix_plugin = 1
command! -nargs=0 L call Switch()
function! Switch()
ruby<<EOF
buf = VIM::Buffer.current
route = buf.name
if (route.end_with? "component.js") || (route.end_with? "index.js")
target = route.include?("component.js") ? route.sub("component.js", "index.js") : route.sub("index.js", "component.js")
if FileTest::exist?(target)
Vim::command("e #{target}")
else
print "Target file does not exist!"
end
else
print "The current file is incorrect!"
end
EOF
endfunctio

View File

@ -2,3 +2,14 @@ let javascript_enable_domhtmlcss = 0
let javascript_ignore_javaScriptdoc = 0
let g:javascript_conceal=0
let b:javascript_fold=1
function! IndexComponentSwitch()
let b:filename=expand('%')
if b:filename =~ 'index\.js$'
execute 'edit' substitute(b:filename, "index.js", "component.js", "")
else
execute 'edit' substitute(b:filename, "component.js", "index.js", "")
endif
endfunction
au FileType javascript nmap <leader>s :call IndexComponentSwitch()<cr>