Nerdtree破坏了我的一个映射



当我按下F5时,我使用以下映射来运行python解释器:

autocmd Filetype python nnoremap <buffer> <F5> <C-o>:update<Bar>execute '!python '.shellescape(@%, 1)<CR>

偶尔,虽然当前文件变量被扩展为类似"NERD_tree_1…"的东西,当然会导致这个错误:

powershell -command "python NERD_tree_1p"
C:Python27python.exe: can't open file 'NERD_tree_1p': [Errno 2] No such file o
r directory
shell returned 1
Hit any key to close this window...

不知道nerd tree是如何引起这个问题的,也不知道如何解决这个问题。

寄存器%包含当前缓冲区名称。不知何故,当错误发生时,您似乎在NERDTree用来显示其目录树的刮擦缓冲区中。

你应该已经注意到游标在"错误的"(即非python)缓冲区中。如果这发生在Python缓冲区中,我无法解释。

你可以让你的映射更健壮,包括对Python文件类型的检查,像这样:

... if &filetype ==# 'python'<Bar>update<Bar>execute '!python '.shellescape(@%, 1)<Bar>endif<CR>