简体   繁体   中英

Vim - Only 1 'bind' in .vimrc file

I've got problem with .vimrc file. I've installed NerdTree and I added this line into vimrc file:

map <C-n> :NERDTreeToggle<CR>

It works perfectly, but I want to use python in vim. I added this line:

nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr>

And It doesn't work. When I've only had "python bind" it was working, but when I added NerdTree link "python bind" stopped working.

The <buffer> in nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr> means that the mapping is local to the current buffer.

Since you have that mapping in your vimrc , it is defined not for the vimrc but for the first buffer you edit and only the first buffer .

As soon as you open another buffer, no matter what kind of buffer (NERDTree included), your mapping won't work anymore for any other buffer than the first one.

Here is a revised version of your mapping that will only work in Python buffers, all of them:

augroup PythonThings
    autocmd!
    autocmd FileType python nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr>
augroup END

See:

:help <buffer>
:help autocommand

Never add anything to your config that you don't fully understand.

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