简体   繁体   English

Vim-.vimrc文件中只有1个“ bind”

[英]Vim - Only 1 'bind' in .vimrc file

I've got problem with .vimrc file. .vimrc文件有问题。 I've installed NerdTree and I added this line into vimrc file: 我已经安装了NerdTree,并将此行添加到vimrc文件中:

map <C-n> :NERDTreeToggle<CR>

It works perfectly, but I want to use python in vim. 它运行完美,但是我想在vim中使用python。 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. 当我只有“ python绑定”时,它可以工作,但是当我添加NerdTree链接时,“ python绑定”就停止了工作。

The <buffer> in nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr> means that the mapping is local to the current buffer. 所述<buffer>nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr>意味着该映射是局部于当前缓冲区。

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 . 由于您在vimrc具有该映射,因此它不是为vimrc定义的,而是为您编辑的第一个缓冲区定义的, 而仅是第一个缓冲区定义的

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. 一旦打开另一个缓冲区,无论使用哪种类型的缓冲区(包括NERDTree),映射都将不适用于除第一个缓冲区之外的任何其他缓冲区。

Here is a revised version of your mapping that will only work in Python buffers, all of them: 这是映射的修订版,仅适用于所有Python缓冲区:

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. 切勿在您的配置中添加您不完全了解的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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