Search code examples
vimtextselectionnetrw

When opening a directory with vim, why does attempting to select text with the mouse gives the error "E21: Cannot make changes, 'modifiable' is off"?


If I run evim foo, where foo is a directory, I get a buffer that looks something like

" ============================================================================
" Netrw Directory Listing                                        (netrw v156)
"   /home/chris-henry/foo
"   Sorted by      name
"   Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:special
" ==============================================================================
../
./
bar/
baz/
qux

I can select text by using Shift + arrow keys (or in other, more modeful ways, I presume), but trying to select text with the mouse gives the error:

E21: "Cannot make changes, 'modifiable' is off"

But I wasn't trying to make changes; I was just trying to select text (in order to middle-click paste it elsewhere). And vim (or netrw?) clearly has no problems with my selecting text, since I can do it with Shift + arrow keys. So why is click-and-drag a problem?


Solution

  • Here is how I understand this…

    • :help netrw-cr maps <CR> to enter the directory/file on the current line.
    • :help netrw-leftmouse emulates a <CR>.
    • You are using "easy Vim" so you are in insert mode by default.
    • In insert mode, <CR> inserts a character so it changes the content of the buffer.
    • You are in a "readonly" buffer, where changes to the content of the buffer are prohibited.
    • Therefore you get an error because Vim thinks you are trying to change the content of the buffer.

    Which is rather unfortunate.

    I don't remember ever trying to disable or alter a Netrw mapping. Maybe you can find something in the very dense :help netrw.