5

I like to replace the default enter/return key functionality with actually inserting a new line, and the same with space (but inserting a line above), e.g. here is my map:

nnoremap <CR> O<ESC>
nnoremap <space> o<ESC>

But the problem I have here is that it breaks selecting functionality. For example Omnisharp and Flake8 both bring up a new buffer which allows you to select errors, or browse found items. For example Flake8 lists any errors that it finds with the file, then you can select an item and press enter to navigate to that error. But if you do this with the enter/return key remapped then instead it will give the error:

E21: Cannot make changes, 'modifiable' is off

Unfortunately I can't find the default mapping for enter/return. Is there any other way to handle this? Or is there a way to change mapping based on what buffer you're currently in, as unmapping the enter/return key once mapped will restore this functionality. But any autocmd solutions with buffers I have came up with are poor and not very reliable.

8

I guess those plugins are using the quickfix-window; if there were using scratch buffers, they should set up buffer-local mappings that would override your global ones.

As Vim treats the quickfix buffer just like any other, your global mappings apply there as well. But fortunately, there's an easy fix: You just need to provide :help :map-<buffer> mappings that restore the original commands. As Vim automatically sets a filetype (cp. :help ft-qf-plugin), you can place those into ~/.vim/ftplugin/qf.vim (as long as you have :filetype plugin on, which most people have), or prepend :autocmd FileType qf to each line and put them into your ~/.vimrc:

" Restore original selection functionality in quickfix windows.
nnoremap <buffer> <CR> <CR>
nnoremap <buffer> <Space> <Space>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.