1

I have remapped the Enter key in normal mode to add a new line:

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.

So the question is, how can I remap a key in normal mode, but not in command line?

lkurylo
  • 1,621
  • 33
  • 59
  • I don't think this is possible because the command buffer you open with `q:` **is** in normal mode. I hope someone will prove me wrong by answering this question. :) – merlin2011 Jul 06 '14 at 19:33
  • This is a [common problem](http://stackoverflow.com/a/16360472/438329) – Peter Rincker Jul 07 '14 at 03:48

2 Answers2

2

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".

romainl
  • 186,200
  • 21
  • 280
  • 313
2

In addition to command-line window you'll almost certainly need this one. For quickfix window:

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