【问题标题】:How to -enable- vim's "Press ENTER or type command to continue"如何 -enable-vim 的“按 ENTER 或键入命令继续”
【发布时间】:2015-03-30 17:08:15
【问题描述】:

这里有很多关于如何在从 vim 运行外部命令时禁用“按 ENTER 或键入命令继续”文本的问题。但我想知道如何启用它。正如您在下面看到的,我没有使用silent 或任何其他方式来禁用它。

这是我的 .vimrc 的相关部分:

nmap <leader>r :call NoFrills()<CR>     "(r)eveal hidden chars
nmap <leader>i :set paste!<CR>          "(i)ndenting on/off
nmap <leader>h :set nohlsearch!<CR>     "(h)ighlighting of search terms on/off
nmap <leader>w :call SudoWrite()<CR>    "(w)rite file, sudoing first
nmap <leader>a :! sudo service httpd restart<CR>"(a)pache restart
nmap <leader>p :! perl -c %<CR>         "(p)erl -c

当我执行一个应该有输出的命令时,比如使用键序列\ p,命令会执行,但任何输出都会很快从屏幕上消失,而不会暂停或提示我继续。这是为什么呢?

如果我从 vim 的命令模式执行 :! perl -c %,它会按预期显示输出并提示我继续。

:version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Feb 17 2012 10:23:31)

:set
--- Options ---
  background=dark     filetype=perl       incsearch           scrolloff=3         ttyfast
  comments=:#         helplang=en         list                shiftwidth=4        ttymouse=xterm
  commentstring=#%s   history=50          number              syntax=perl         viminfo='20,"50
  define=[^A-Za-z_]   hlsearch            ruler               tabstop=4           wildmenu
  backspace=indent,eol,start
  complete=.,w,b,u,t,i,k
  fileencoding=utf-8
  fileencodings=ucs-bom,utf-8,latin1
  formatoptions=tcrq
  guicursor=n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block,a:blinkon0
  include=\<\(use\|require\)\>
  includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.pm','')
  indentexpr=GetPerlIndent()
  indentkeys=0{,0},:,0#,!^F,o,O,e,0=,0),0=or,0=and
  isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,:
  keywordprg=perldoc -f
  listchars=tab:>-,trail:o
  path=/usr/local/lib64/perl5,/usr/local/share/perl5,/usr/lib64/perl5/vendor_perl,/usr/share/perl5/vendor_perl,/usr/lib64/perl
5,/usr/share/perl5,,
  wildmode=longest,list,full

【问题讨论】:

  • 我不知道它们是否真的在你的 vimrc 中,但内联 cmets 是禁止映射的。
  • 你一针见血。谢谢!

标签: vim


【解决方案1】:

正如@romainl 已经在 cmets 中指出的那样,附加的 cmets 是映射的一部分,并且其中一个字符(例如 &lt;Space&gt;)会关闭 hit-enter 提示。您可以通过在映射中用|(必须转义或写为&lt;Bar&gt;)分隔来包含尾随注释:

nnoremap <leader>p :! perl -c %<CR>| "(p)erl -c

但我建议将 cmets 放在单独的一行:

" (p)erl -c
nnoremap <leader>p :! perl -c %<CR>

PS:You should use :noremap;它使映射不受重映射和递归的影响。

【讨论】:

  • 我现在感觉自己像个傻瓜。我什至有语法突出显示,当 cmets 没有这样突出显示时,我没有三思而后行。谢谢! (附:我已经更新到 nnoremap)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2022-11-02
  • 2012-11-15
  • 2010-10-28
相关资源
最近更新 更多