Reputation: 13
I want to: Automaticaly close Lexpore after opening a file for better experience but I don't know vim script. It shouldn't be hard, I suppose. I will appreciate any comment!
I'm now learning vim script and trying to do it. here is where I've got by now:
:autocmd <Lexplore> * :<Lexplore-exit>
or
if <command-mode> == "Lexplore *.*"
excute \\close last buffer. (because now I am in new buffer)
I just need to know how to say "RUN" / "RUNED" in script then i use regex for anyfile and i need to say "CLOSE".
The truth is I'm actually Hopeless! :)))))))))))))
Upvotes: 1
Views: 438
Reputation: 196546
There are other avenues to try before going full-on with VimScript. In this case, a simple mapping would probably be enough.
Basically, the right-hand side of a mapping is just a macro, a sequence of commands that you would type yourself, which makes mappings a very good and approchable way to discover Vim automation.
Assuming a simple layout, with only one window, how do you do what you describe manually?
:Lexplore
and browse around.<CR>
to open the file.<C-w>p
.<C-w>q
.Steps 2-4 above are easy to turn into a mapping (<key>
is a placeholder, use what you want):
nmap <key> <CR><C-w>p<C-w>q
But that mapping will be available everywhere, which may not be a good idea. Enters the notion of filetype plugins:
Create these directories if they don't already exist:
~/.vim/after/ftplugin/ (Unix-like systems)
%userprofile%\vimfiles\after\ftplugin\ (Windows)
Create a netrw.vim
file in the directory above:
~/.vim/after/ftplugin/netrw.vim (Unix-like systems)
%userprofile%\vimfiles\after\ftplugin\netrw.vim (Windows)
Put the mapping above in that file:
nmap <buffer> <key> <CR><C-w>p<C-w>q
The <buffer>
tells Vim to only define that mapping in Netrw
.
This is the simplest approach, which may or may not work for you.
A few notes regarding your comments…
:Lexplore
. :Explore
, :Sexplore
, :Vexplore
, and :Texplore
are much more useful.:help netrw-t
.Upvotes: 2