简体   繁体   English

vim与python:如何映射:silent make | 打开到vimrc中的功能键

[英]vim with python: how to map :silent make | copen to function key in vimrc

Thats it, what I have in my vimrc and I would like it to work is : 就是这样,我在vimrc中拥有的功能是:

set makeprg=python\ %
nmap <F5> :silent make | copen

It doesnt work, it echoes :silent make and doesnt run or report errors in script. 它不起作用,它回显:silent make,并且不运行或报告脚本错误。 But if I just type in Vim 但是如果我只输入Vim

:silent make | copen

I get my desired result. 我得到了想要的结果。

I'm using GVim 7.4 on windows vista 我在Windows Vista上使用GVim 7.4

You are executing your python code not linting it. 您正在执行的python代码不掉毛。 A quick google shows pylint and Python - check syntax and run script . 一个快速的谷歌显示pylintPython检查语法和运行脚本 There is also synstastic.vim if you want a heavier handed approach. 如果您想使用更重的方法,也可以使用synstastic.vim

You mapping has the following problems: 您的映射存在以下问题:

  • the pipe, | 管道, | , is not escaped. ,无法逃脱。 Use <bar> instead. 使用<bar>代替。
  • As a general rule of thumb should be using *noremap unless using <Plug> mappings 通常,除非使用<Plug>映射,否则应使用*noremap
  • You need to execute the command by adding <cr> at the end 您需要通过在末尾添加<cr>来执行命令
  • Optionally use an :autocmd to execute :cwindow / :copen after :make . (可选)在:make之后使用:autocmd执行:cwindow / :copen eg autocmd QuickFixCmdPost * cwindow 例如autocmd QuickFixCmdPost * cwindow
  • Optionally make a new command for this action: command! -nargs=* Smake silent make <args> (可选)为此操作创建新命令: command! -nargs=* Smake silent make <args> command! -nargs=* Smake silent make <args> . command! -nargs=* Smake silent make <args> Now you can do :Smake instead of :make 现在您可以执行:Smake而不是:make

Your new mapping: 您的新映射:

nnoremap <F5> :silent make <bar> copen<cr>

For more help see: 有关更多帮助,请参见:

:h :map
:h <bar>
:h :au
:h QuickFixCmdPost
:h :cwindow
:h :cope
:h :compiler
:h write-compiler-plugin

我认为这是因为map命令不接受将竖线字符作为命令分隔符并将其作为输入,因此您可以将其替换为<bar> ,例如:

:nmap <F5> :silent make <bar> copen<CR>

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

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