I want to bind something like this:
For CSS, HTM开发者_Go百科L files:
<c-space> <c-x><c-n>
For Ruby files:
<c-space> <c-x><c-u>
How to do this?
The documentation is more complete, precise and correct, but briefly:
Make a file in your ftplugin folder (create this folder if necessary) starting with the filetype you'd like to use.
├── vim
│ ├── after
│ ├── autoload
│ ├── bundle
│ ├── ftplugin
│ │ ├── python.vim
│ │ ├── rnoweb.vim
│ │ └── tex.vim
│ └── syntax
and in one of of these files, the python.vim one for example, a line like
noremap! <buffer> <F5> <Esc>:w<CR>:!python % <CR>
will be a bind only defined for this filetype, just in this buffer. Make sure filetype plugin on
or similar appears in your vimrc.
Edit: excellent suggestions by Peter Rincker incorporated: noremap version of map command and <buffer>
flag. He also reminds us to use setlocal
instead of set
in our filetype plugin files.
Use autocmd:
autocmd filetype css inoremap <buffer> <c-space> <c-x><c-n>
autocmd filetype html inoremap <buffer> <c-space> <c-x><c-n>
autocmd filetype ruby inoremap <buffer> <c-space> <c-x><c-u>
Put the following in your .vimrc. Substitute the do stuff lines with your bindings.
:if match(@%, ".css") >=0
: do css stuff
:endif
:if match(@%, ".rb") >=0
: do ruby stuff
:endif
精彩评论