I would like to open a (text) file with Vim in nautilus. This part is easy: Right-Click -> Open With Vim
starts a terminal with vim inside running, file open already.
When I close vim, the terminal closes too. I would like the terminal to remain open, with the working directory set to the directory the file is in.
I'm sure there is a simple way to achieve this by creating a custom bash script and adding it to the context menu (or even as the default action on Enter when the file is selected) but I don't know how. So, How to do this?
I am on ubuntu 18.04 but I hope it is similar for later versions.
Maybe not exactly what you want, but the following script does the thing you want, when put as a Nautilus script under the
~/.local/share/nautilus/scripts/
directory:Usage: Please, add the above script contents as a new file with a meaningful name (like
VIM
) under the~/.local/share/nautilus/scripts/
directory. Then, using Nautilus, select a single text file, right click and on the popup menu select Scripts → VIM.__
Disclaimer: Tested only under Ubuntu 21.10
If you want to insert the above functionality into the
vim.desktop
file provided by the system, you can "localize" the contents of this file by copying it to the directory~/.local/share/applications/
and changing the lineExec=vim %F
to call your custom shell script which can be created based on the script I provided above (Hint: Replace the linefile=…
in my script withfile="$1"
in your new script.)