1

I'd like to overwrite netrw plugin's default file handler keybinding gx but still be able to use it:

" should remap netrw's gx to gX
xnoremap gX gx

" map gx to something else
xmap gx :SomeCommand<cr>
nmap gx :SomeCommand<cr>

Above doesn't work, gX does nothing

1 Answer 1

0

The netrw plug-in also defines a couple of <Plug> mappings that you can use to define your own mapping to the "browse" feature.

To map gX to those, you can use:

nmap gX <Plug>NetrwBrowseX
xmap gX <Plug>NetrwBrowseXVis

netrw checks whether there are already keybindings defined to these two <Plug> mappings and, if so, it skips setting up the gx mappings itself. (It also skips the gx mappings if it finds alternative mappings using that sequence were already defined.) So adding these two should be enough to free up gx for whatever you'd like.

5
  • sorry, this is not working
    – user37373
    Dec 22, 2021 at 21:38
  • I was able to get it working after adding these two lines nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))<cr> xno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr>
    – user37373
    Dec 22, 2021 at 21:49
  • @blackyellow That's odd that you'd have to add those manually, netrw is supposed to add them for you during its startup... I just double checked, by adding the exact two mappings I mentioned in my answer, it worked fine for me, I ended up with the gX mapping defined and the gx one undefined...
    – filbranden
    Dec 22, 2021 at 22:31
  • Ah! It seems the problem is with setting g:netrw_nogx, that prevents the <Plug> mappings from being defined... I'll fix my answer.
    – filbranden
    Dec 22, 2021 at 22:32
  • Ok, fixed now! Please take another look.
    – filbranden
    Dec 22, 2021 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.