Setting vim as default editor using i3WM

I have struggled to determine how to set vim as the default editor using the XFCE terminal with EndeavourOS and i3WM. I use vim for python development and have it setup to meet my programming workflow. I’ve been able to add a hot-key combination to the i3 config file which works. I can’t figure out what needs to be set to use vim to automatically open files with txt, py, sh, and several other extensions.

Help would be appreciated.

add “EDITOR=vim” in /etc/environment and log out.

1 Like

hey @rickig welcome to our community! :enos:

I do not think there is such a thing as automatic open for the files. It is important to know from where you are opening the files (which application).

From terminal - there is no file open. You have to specify vim foofile.txt.

Something like ranger uses environment $VISUAL and $EDITOR variables that are set in $HOME/.config/ranger/rifle.conf. The actualy value of the variable can be set in may places - lie @bitterhalt wrote in /etc/environment, also ~/.profile, ~/.bashrc, …

Thunar is most probably (not sure) set up to use whatever is specified in mimetypes.
Check what type is a file.
xdg-mime query filetype ~/foofile
You can check which application is set to open.
xdg-mime query default text/plain
Set you prefered editor for plain text.
xdg-mime default vim.desktop text/plain
You have to have vim.desktop file correctly set as well. I am not sure if it comes with the default installation package.

Firefox can use its own settings where you can specify what to do with the downloaded file (Settings → General → Applications).

Also, I am not sure if you have gui version of vim so you may have to launch the terminal first - something like xfce4-terminal -e vim.

Thank you for your help I didn’t leave you with enough information my apologies. I was trying to get the lf file manager to launch vim when selecting a .txt .py or .md file. I use urxvt terminal but tried xfce to with lf and couldn’t get it to work. In both terminals emacs was selected when opening a file with one of the three file extensions.

I had my /etc/environment set to “EDITOR=vim” and nothing changed.
xdg-mime didn’t work with vim.desktop because I don’t use gvim just vim from the terminal.

Yet I have no problems when running these file managers Ranger and vifm both use vim to open the three file types.

What’s interesting is the nnn file manager exhibits the same behavior as the lf file manager.

I hope this makes more sense. Thank you for the help!

there is the mime-open-with option on right-click a textfile in thunar and chose properties:

and there is this setting in Thunar to create custom actions:

In addition there is text based config locally in ~/.config/mimeapps.list


thank you for your help your Thunar suggestion appears to have solved my problem.

And thank you bitterhalt and vlkon.