0

I want to override NetRW's response to <CR>. When I hit enter, I want to:

  • get the path of the file or directory of the line with the cursor in the :Lex window
  • test if path is a file
  • if the path is a file:
    • the explorer from :Lex closes
    • tab drop to the path
    • open :Lex

However, I have no idea how I can get the path or directory of the line with the cursor in the :Lex window, without opening the file first. Any advice is appreciated.

3 Answers 3

3

Here's a couple ideas:

  • Combine b:netrw_curdir with expand('<cfile>') to get the path, then do you want you want. There's some trickiness with getting the file on the line at the cursor because netrw has various possible "formats."
  • Run the original to open the file (:execute "normal \<Plug>NetrwLocalBrowseCheck"), grab the path (expand('%')), :Rexplore to go back to the previous state, then do what you want.

I found the <Plug> mapping by opening netrw and checking :map <CR>.

0

Just found a better way without opening file, and is consistent.

netrw#Call('NetrwFile', netrw#Call('NetrwGetWord')) 
0

After reading the source code of netrw, I finnaly find the way.

let l:pathUnderCursor=netrw#Call('NetrwTreePath', w:netrw_treetop) 

The l:pathUnderCursor will get the absolute path under the cursor of the netrw line.The function NetrwTreePath is an internal function in the script netrw.vim, to call it you need to use a form like this netrw#Call. And here is the source code netrw.vim:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.