简体   繁体   中英

How to set conditional mappings in VIM (ie: depending on the extension of a file)?

例如, 如果文件扩展名为.js如何将'<leader>r'映射到:!node % ,然后将其映射到:!make % otherwise?

General case, in your ~/.vimrc :

nnoremap <leader>r :!make %<cr>

JavaScript files, in ~/after/ftplugin/javascript.vim :

nnoremap <buffer> <leader>r :!node %

Or use the makeprg option. See :h makeprg .

Try this:

nnoremap <leader>r :!make %
autocmd FileType javascript nnoremap <leader>r :!node %

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM