Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is window splitting forcing readonly?

Tags:

vim

I'm using vim for programming. At the start of the day I'll open a file and proceed to do a couple window splits and open some files into buffers so they're readily available. Up until very recently this has just worked.

In the last week or so, though, something changed; one of my writable buffers is getting switched to readonly and I have no idea why. Here's the sequence of commands:

  1. Open fileA.h
  2. vsplit ./
  3. open fileA.cpp
  4. C-w C-w to switch to window containing fileA.h
  5. sp ./

For steps 1-4 all windows are editable. When I execute step 5 the new file browsing window is readonly (as expected), but now the window holding fileA.cpp is marked as readonly too. fileA.h is still editable. Why is this happening?

To confuse me even more, if I don't do step 4 there are no problems (i.e. I split the window holding fileA.cpp instead of fileA.h). Also, if I do 'sp fileB.h' in step 5 instead of splitting to a file browser first there are no problems.

like image 581
ryan0270 Avatar asked Jan 08 '12 23:01

ryan0270


People also ask

Why do my folders become read only?

If your folder keeps reverting to read-only it could be due to a recent Windows 10 upgrade. Many users have reported that when upgrading their system to Windows 10, they encountered this error. Read-only is a file/folder attribute that lets only a specific group of users read or edit the files or folder.

How do I unsplit my computer screen?

To exit split-screen mode, maximize one of the program windows by clicking the maximize icon at the window's top-right window.


1 Answers

It looks like this might be a bug in the netrw plugin. I tested with several versions of netrw with two builds of Vim 7.3 (MacPorts vim 7.3-353, and MacPorts MacVim “snapshot64” 7.3-390):

  • v140 (included in the MacPorts vim: 7.3-353)
    Tested only with the MacPorts vim build.
  • v141 (from the vim.org/scripts netrw page)
  • v142 (from the vim.org/scripts netrw page)
  • v143 (included in MacPorts MacVim: 7.3-390)
    Tested only with the MacPorts MacVim build.
  • v144b (pre-release from the netrw author’s Vim page)

You can check your active netrw version with :let g:loaded_netrwPlugin.

v140 through v142 all had reasonable behavior when reproducing your scenario:

  • Only the netrw buffer (from sp .; right side, upper window) is read-only.
    The fileA.cpp buffer in the window on the left remains non–read-only.

With v143 and v144b I was able to reproduce your behavior:

  • Both the netrw buffer (right side, upper window) and the fileA.cpp buffer (left side) become read-only.
  • Additionally (i.e. not reported by the OP, but seemingly related), the fileA.cpp window on the left side becomes the active window.
    Normally, the right side, upper window (the one from the sp .) should be active.

The fileA.cpp window was originally a netrw window (from vsp .). My guess is that something in v143 and v144b is a bit overzealous in resetting the old window for some reason (it probably should not be touching that window at all). sp fileB.h avoids the problem by not invoking netrw (i.e. the problem is not with splitting windows, but with something that netrw does when it creates the directory listing buffer).


If your problem is coming from netrw (i.e. your behavior matches my description, and your directory listing buffers have the text Netrw Directory Listing and (e.g.) (netrw v143) on the second line—assuming you have not disabled the netrw banner), then you may be able to fix it by installing an older(?) version of netrw (i.e. v142).

netrw is packaged as a “vimball archive”. The vimball plugin comes with Vim 7.0 and later. You just source a vimball file to install it to the first directory in your runtimepath (usually ~/.vim).

:e /path/to/netrw.vba.gz
:so %
:q

If you are using pathogen to isolate your Vim plugins (highly recommended!), you can install it to a bundle directory instead:

:e /path/to/netrw.vba.gz
:UseVimball ~/.vim/bundle/netrw
:q
like image 83
Chris Johnsen Avatar answered Oct 18 '22 15:10

Chris Johnsen