Skip to content

edit files using a relative path when possible#71

Open
fabi1cazenave wants to merge 2 commits intofrancoiscabrol:masterfrom
fabi1cazenave:relative_path
Open

edit files using a relative path when possible#71
fabi1cazenave wants to merge 2 commits intofrancoiscabrol:masterfrom
fabi1cazenave:relative_path

Conversation

@fabi1cazenave
Copy link

Files that have been chosen with Ranger are open in Vim / Neovim with their absolute paths, which is a pity.

This quick patch allows to use the relative path (from Vim’s current working directory) when possible.

@francoiscabrol
Copy link
Owner

francoiscabrol commented Dec 1, 2018

Hey thank you for your contribution.
But I tried locally and I found one feature broken: if I try to open the current directory in neovim with the command nvim . and then I choose a file, I get the error

Error in EditFiles
E492: Unknown command editplugin/ranger.vim

@fabi1cazenave
Copy link
Author

Oh, good catch. Looking at it.

I confess I hadn’t really tried the let g:ranger_replace_netrw = 1 trick yet.

@fabi1cazenave
Copy link
Author

fabi1cazenave commented Dec 2, 2018

[EDIT] Got it, see commit 98e3e73, line 124.

Without this PR, the command was edit/home/user/file.ext, which is understood by nvim (the space between the command and the path is not needed because the path starts with a slash). With this PR, the command became editfile.ext, which is not understood.

@fabi1cazenave
Copy link
Author

fabi1cazenave commented Dec 2, 2018

In fact I find the trailing space in edit_cmd a bit error-prone, and I think it would be safer to add this space explicitly in the EditFiles function instead.

That’s what I did in commit 60146fb, but it works without this commit. Feel free to drop it if you prefer keeping the code the other way.

EDIT: updated commit references after a rebase.

Having a trailing space in the `edit_cmd` variable is error-prone.
Adding a space between this command and the file path in the `EditFiles`
function should be safer.

function! s:GetRangerCmd(path)
return s:ranger_command . ' --choosefiles=' . s:choice_file_path .
\ (isdirectory(a:path) ? ' "' : ' --selectfile="') . expand(a:path) . '"'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why but the path is not concatenated correctly and that breaks the default behaviour:

  • if you open a file in vim
  • then you open ranger in the same window
  • it should select the file in Ranger and it does not (see the command RangerCurrentFile).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants