VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 01 2022 09:16:32)
Included patches: 1-2269, 3612, 3625, 3669, 3741
Ubuntu MATE 20.04.5 LTS
Caja 1.24.0
Not sure why there is a discrepancy in behaviour.
View of start folder:
Sequence with expected results:
- open a terminal from Caja (Ubuntu MATE 20.04),
- open file with vim junk18.sh
- type :r junk16.sh
Vim imports junk16.sh located in directory which is start directory for vim.
Sequence with unexpected results:
- Default action for *.sh files is to open using gvim
- cursor right-click on junk18.sh
- select open
- from within gvim, type :r junk16.sh
Before hitting the Enter key, the screen looks like this:
Result is following:
So ... why is the work directory or start directory for gvim not the location of the file selected in Caja ???
If I type :!sh then pwd, it reports the ${HOME} of my non-root userID, instead of the current directory of the Caja folder being viewed!!!
You are a victim of the poor way the concept of a "current working directory" is handled in graphical desktops in general.
It is like doing a job in the house, and having to go outside to the garage each time again to pick a new tool for the job.
Answering your question
In the first case, you open a terminal in Caja. The working directory of the terminal is the directory that was selected in Caja. A program launched from the terminal will also by default look in this working directory.
In the second case, you open the file with the right-click menu. That causes gvim to be opened based on the information provided in a
.desktop
launcher. There is no mechanism in place to pass the current directory of the file manager to the launched process. That one starts by default in your home directory (as you saw for yourself), unless overridden by aPath=
directive in the launcher.It is how it is currently implemented, so would require adjustments to how the current system works.