2

I have a leader key set up, and a mapping that allows me to exit windows without typing ::

let mapleader = 'f'
map <leader>q = :q<CR>

Today I installed MattesGroeger/vim-bookmarks using Vundle, and everything went fine. However when I view the annotations list using ma, and then I try to exit it using fq, vim spits out this error phrase:

E21: Cannot make changes, 'modifiable' is off

But I can exit it just fine if I manually type out :q

The other answers I've seen so far regarding the modifiable/nonmodifiable attributes of buffers imply that a solution is to set the buffer as modifiable, however that seems like a hack. It looks like map and friends are restricted in use in buffers without modifiable set, so is there a specific kind of map that will allow me to use this mapping across all buffers?

1 Answer 1

2

The problem is with the = in your command. It's being taken as part of the expansion for the mapping.

That's triggering the = command, which typically reformats a block of code. Since you have a space after the =, that's being swallowed as the "motion" for = (which is roughly equivalent to the motion of going right one character.)

I guess this reformatting wasn't doing anything on your regular buffers, so it wasn't leaving your buffer in a modified state, which would have interfered with the second part of the command.

But with a read-only buffer, that's likely to be a problem, since the command will fail early, in the way you experienced.

To fix it:

map <leader>q :q<CR>

But you might also want to make this mapping non-recursive (usually a best practice) and probably only allow it in normal mode (and not visual or select modes):

nnoremap <leader>q :q<CR>
1
  • 1
    Oh!!! Yes you're right! I don't know how that slipped in because my initial mappings file just didn't have it, and my brain just filtered it out for some reason :) Thank you!
    – Aster
    Feb 28, 2020 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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