简体   繁体   English

重新映射以普通模式输入,但不在命令行中

[英]remap Enter in normal mode but not in command line

I have remapped the Enter key in normal mode to add a new line: 我在正常模式下重新映射了Enter键以添加新行:

nnoremap <CR> o<Esc>k

Works great, but now in the command line (entered by q:) this command add new line either, but I would like to leave it in default mode, this is execute the selected command from history. 效果很好,但是现在在命令行中(由q:输入)此命令也添加了新行,但我想将其保留为默认模式,这是从历史记录中执行选定的命令。

So the question is, how can I remap a key in normal mode, but not in command line? 所以问题是,如何在正常模式下而不在命令行中重新映射键?

This autocommand does what you want: 此自动命令可以执行您想要的操作:

augroup commandlinewindow
  autocmd!
  autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>
augroup END

It's the "command-line window", by the way, not the "command line". 顺便说一下,它是“命令行窗口”,而不是“命令行”。

In addition to command-line window you'll almost certainly need this one. 除了命令行窗口,您几乎肯定会需要这一窗口 For quickfix window: 对于快速修复窗口:

autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>

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

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