2

I have added this to my .vimrc in order to append a newline without leaving Normal mode:

nmap <Enter> o<Esc>

The problem is when I q: to the command history buffer. This binding clashes with the usage of Enter for selecting a command from history. A lesser problem is when reading a help page hitting Enter will display a warning that the file is read-only. How can I remap this key in a way that ignores these two contexts?

ramblenode
  • 207
  • 3
  • 12

2 Answers2

1

You can undo the global mapping for the command-line window via a buffer-local mapping to itself:

autocmd CmdwinEnter * nnoremap <buffer> <Enter> <Enter>

(My ingo-library plugin provides a generic ingo#window#cmdwin#UndefineMappingForCmdwin() function for that.)


For the help buffer, use the same approach, but trigger on the FileType event:

autocmd FileType help nnoremap <buffer> <Enter> <Enter>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
0

You can set it with autocmd using this method https://stackoverflow.com/a/10410590/3627387

let blacklist = ['nofile', 'help']
autocmd FileType * if index(blacklist, &bt) < 0 | nmap <Enter> o<Esc>

Here we are checking for buffer type :help 'buftype'

Community
  • 1
  • 1
Sardorbek Imomaliev
  • 14,861
  • 2
  • 51
  • 63