Vim - 运行绑定到F5的外部命令来运行Python脚本会导致错误

Moa*_*ini 3 python vim

我将以下内容添加到我的.vimrc文件中:

nnoremap <silent> <F5>!python %
Run Code Online (Sandbox Code Playgroud)

当我按下F5时,这应该在Python中运行当前文件.相反,它会给出以下错误:

Trackback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 349, in f_with_update
  File "<string>", line 358, in run_this file
NameError: global name 'send' is not defined
Press Enter or type command to continue
Run Code Online (Sandbox Code Playgroud)

如果我每次运行VIM时手动重新映射F5,则此命令有效:

:map <silent> <F5>!python %
Run Code Online (Sandbox Code Playgroud)

我不记得将任何内容映射到F5,我的.vimrc文件不包含任何映射器.知道发生了什么事吗?

idb*_*rii 6

nnoremap <silent> <F5>!python %
Run Code Online (Sandbox Code Playgroud)

地图<F5>!python%.你想要的是这个:

nnoremap <silent> <F5> :!python %<CR>
Run Code Online (Sandbox Code Playgroud)

:如果要使用普通的cmd-line命令,则需要使用法线贴图,并且需要<CR>以执行命令结束它.将右侧的所有内容都视为您自己键入的键.

您可能会发现python上的这个vim wiki页面很有用.