简体   繁体   中英

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 :

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

It doesnt work, it echoes :silent make and doesnt run or report errors in script. But if I just type in Vim

:silent make | copen

I get my desired result.

I'm using GVim 7.4 on windows vista

You are executing your python code not linting it. A quick google shows pylint and Python - check syntax and run script . There is also synstastic.vim if you want a heavier handed approach.

You mapping has the following problems:

  • the pipe, | , is not escaped. Use <bar> instead.
  • As a general rule of thumb should be using *noremap unless using <Plug> mappings
  • You need to execute the command by adding <cr> at the end
  • Optionally use an :autocmd to execute :cwindow / :copen after :make . eg autocmd QuickFixCmdPost * cwindow
  • Optionally make a new command for this action: command! -nargs=* Smake silent make <args> command! -nargs=* Smake silent make <args> . Now you can do :Smake instead of :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>

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