0

I use :mkview %.vimview to create a view file under current directory, and in the file created there is a line of code like this:

if bufexists(fnamemodify("~/PycharmProjects/rl/report/rl_qf_report.tex", ":p")) | buffer ~/PycharmProjects/rl/report/rl_qf_report.tex | else | edit ~/PycharmProjects/rl/report/rl_qf_report.tex | endif

what does this do?

(The file I want to save view has the path ~/PycharmProjects/rl/report/rl_qf_report.tex, but it will be a different path if I clone the repository from GitHub to other directories. I want this view file also can be used in other location.)

1 Answer 1

0

That line loads the buffer or file at fnamemodify("~/PycharmProjects/rl/report/rl_qf_report.tex", ":p"), which is really ~/PycharmProjects/rl/report/rl_qf_report.tex with the ~ expanded.

AFAICT from :help 'viewoptions', there is no way to force relative paths. But you might be able to run a script to modify the view file to use relative paths.

3
  • that shouldn't really matter, because the fnamemodify will be evaluated when restoring the view (on a possibly different system). Also this is just the check, which checks if the buffer for that file exists, else it will go to it (or load the buffer). But both times, it uses the ~ so it doesn't really matter if the home directory of the user changes Commented Jul 13, 2022 at 21:51
  • 1
    @ChristianBrabandt the problem is that I might copy the file to a different location, so if that happens then when I am sourcing this view file in that copied file, I will be redirected to the original file, which is not I want Commented Jul 13, 2022 at 22:09
  • 1
    And I found this only happens when I use :mkview %.view, if I just use :mkview, it wont have that line of code, but it will create the view file in ~/.vim/view/, I have ask this on another question since I am confused now about the two command, here it is:vi.stackexchange.com/q/37959/41836 Commented Jul 13, 2022 at 22:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.