This topic in SE has confirmed that I cannot use Lexplore in Vim 7.4 (which is what I'm currently using). I cannot download plug-ins as my workstation is in a secure environment, and unless I request our IT to upgrade Vim (which is very difficult), I'm stuck with finding workarounds to mimic Lexplore.
Any help on how I can mimic Lexplore in Vim is much appreciated. Thank you in advance!
This topic in SE has confirmed that I cannot use Lexplore in Vim 7.4 (which is what I'm currently using). I cannot download plug-ins as my workstation is in a secure environment, and unless I request our IT to upgrade Vim (which is very difficult), I'm stuck with finding workarounds to mimic Lexplore.
Any help on how I can mimic Lexplore in Vim is much appreciated. Thank you in advance!
Share Improve this question asked Feb 18 at 3:38 renvillrenvill 1631 silver badge11 bronze badges 1- 1 Note that Vim 7.4 was released in 2013 and superseded by Vim 8 in 2016. One hell of a secure environment to work in. – Friedrich Commented 2 days ago
1 Answer
Reset to default 1How faithful do you want your :Lexplore
emulation to be?
A superficial "open a slim vertical Netrw window on the left side of the current window" is as simple as:
:20Vexplore!
But you may want that slim window to take the full height of the screen. Moving the window to the far left side of the screen is easy enough with an additional :help :wincmd
:
:20Vexplore!|wincmd H
Note that 20
is a percentage, here, not a number of columns.
But, here, the width of the window is lost in the process. In my quick tests, neither :set noequalalways
nor :set winfixwidth
appear to have any effect on that, which is surprising, honestly. But you can still use :help vertical-resize
and a bit of calculation:
:Vexplore!|wincmd H|execute 'vertical resize ' .. &columns / 100 * 20
Let's turn that into a custom mapping:
function! LexploreOpen()
Vexplore
wincmd H
execute 'vertical resize ' .. &columns / 100 * 20
endfunction
nnoremap <F5> :<C-u>call LexploreOpen()<CR>
Now you can press <F5>
to open your :lexplore
lookalike.
But what really sets :Lexplore
apart from :help Vexplore
is that it is a toggle: you do :Lex
to open it and :Lex
again to close it.
You can use a global variable for that:
function! LexploreToggle()
if exists('g:FakeLexploreIsOpened')
wincmd t
close
unlet g:FakeLexploreIsOpened
else
Vexplore
wincmd H
execute 'vertical resize ' .. &columns / 100 * 20
let g:FakeLexploreIsOpened = 1
endif
endfunction
nnoremap <F5> :<C-u>call LexploreToggle()<CR>
Setting a window-local option and closing the window that has it set would be cleaner, IMO, but I don't remember what functions were available back then for that. See if :help getwinvar()
can help.
Anyway, this should give you a reasonable approximation of :Lexplore
but it accepts a path, for starter, and the snippet above doesn't. And it is entirely possible that the original command does other things, like setting various useful internal Netrw variables and so on. This means that the closer you want to get from the real :Lexplore
, the more involved it will be. For a full clone of :Lexplore
I'm afraid you will have to look at Netrw's code.
Note that there is no fundamental difference between the snippet above and a "plugin" so, if you can get that snippet into your secure environment, then you can also probably get a recent Netrw.