'Vim, how to make Netrw to replace current open file instead of split opening new window, when you press preview or create new file commands?

Recently I've been using netrw. I've put these four lines on my .vimrc:

let g:netrw_banner = 0

let g:netrw_liststyle = 3

let g:netrw_winsize = 25

map <C-n> :Lexplore <CR>

And I can easily toggle Lexplore and browse through the files to edit them. In this mode when I press Enter on any file on left hand side Netrw, it replaces the file in the right hand side window with new file; exactly what I want.

Problems start when I want to preview a file with "p" command on netrw or create a new file with "%" command. In former case (Preview) it split to the new window but I want it again to replace the file in right hand side window just like when I press Enter to to edit the file. And in latter case (creating a new file) it replaces the Lexplore (Netrw in the left hand side) instead of replacing the file on the right hand side window.

Is there any way that I can fix these issues? I've tried a lot of Netrw commands but nothing gives me what I want.



Solution 1:[1]

The "p" netrw command is mostly just pedit. So, assuming you don't already have a preview window, just press <cr> atop the file you want to preview and then :set pvw. That will make the window holding the file the preview window.

The second issue concerns "%" to create a new file. I'll think this over, but I think perhaps the better behavior is as you suggest -- keep the Lexplore window but open the new file in the editing window.

Please try version 171e of netrw which you can find at my website.

Solution 2:[2]

I believe this is related to a bug in vim. Once you use :Lexplore it apparently changes the g:netrw_chgwin option permanently, so whenever you try to pres <CR> in any netrw window, it will always open in a new window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Bastian Venthur