ranger.vim icon indicating copy to clipboard operation
ranger.vim copied to clipboard

Bad path when inside a terminal in Neovim

Open pmaoui opened this issue 7 years ago • 3 comments

Hi,

Thank you for your work, I love using ranger inside Vim :+1: When I want to open ranger from a terminal in NeoVim (:te<CR>), I can't open it because the path is corrupted like this :

Inaccessible paths: ['/my/current/folder/term:/3653:/bin']

I guess it's not a wanted behavior... Any thought ?

pmaoui avatar Jan 24 '18 00:01 pmaoui

Are you aware that ranger expects to open in a certain directory, and that you decide which one that is. The 'Ranger' command opens ranger in the directory of the current file, when you are on a terminal buffer, this doesn't really make sense. While in a terminal, you can use RangerWorkingDirectory though...

enthudave avatar Jan 24 '18 17:01 enthudave

Yes I'm aware thank you. And for me it completely makes sense. I have to execute ranger in my terminal to open it where in Vim using :Ranger doesn't work. If Ranger.vim was able to deduce /my/current/folder from ['/my/current/folder/term:/3653:/bin'] it would do the trick. Speaking of the meaning it could have: when I'm in a terminal, I have a current directory, just like in Vim. It would be an advantage for Ranger.vim to take this path into account.

pmaoui avatar Jan 25 '18 10:01 pmaoui

ok, I think this might suffice, it works for me but does rely on the variable b:term_title to reflect the terminal's CWD. In other words, if you or some function sets that title to something, it won't work like this...(a running process in that terminal would cause that, but you wouldn't run ranger then would you?).

function! RangerFromTerm(title)
  if !empty(a:title)
    let dir = split(a:title, '\s')[1]
    call OpenRangerIn(dir, 'edit ')
  endif
endfunction

nnoremap <localleader>x :call RangerFromTerm(b:term_title)<cr>

you can off course just drop that in your $VIMRC, and use whatever key mapping you want

enthudave avatar Jan 25 '18 17:01 enthudave