9

Currently, ranger will only open text files with nano, and I want it to open them with vim.

As per the Arch Wiki I have tried adding

has xdg-open, flag f = xdg-open "$1"
ext txt = vim "$@"

to rifle.conf, but that didn't work.

9

I figured it out.

If you are using BASH, add the following to your .bashrc :

 VISUAL=vim; export VISUAL EDITOR=vim; export EDITOR

otherwise, follow these instructions

4

You don't have to edit .bashrc, only the ranger config. Here is how:

After startup, ranger creates a directory ~/.config/ranger.

You want to edit the rifle.conf file. Rifle is the program that chooses what to open files with. To copy the default configuration for rifle to this directory, issue the following command:

$ ranger --copy-config=rifle.conf

(Alternatively, add all of rangers config files with $ ranger --copy-config=all)

In rifle.conf, find this part. Change the $EDITOR variable on the two lines below:

#-------------------------------------------
# Misc
#-------------------------------------------
# Define the "editor" for text files as first action
mime ^text,  label editor = $EDITOR -- "$@"
mime ^text,  label pager  = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = $EDITOR -- "$@"
!mime ^text, label pager,  ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"

Change it to whatever you want to edit text files with, like vim. I use Kakoune, so I change it to kak:

#-------------------------------------------
# Misc
#-------------------------------------------
# Define the "editor" for text files as first action
mime ^text,  label editor = kak -- "$@"
mime ^text,  label pager  = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = kak -- "$@"
!mime ^text, label pager,  ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"

This was done on ranger version 1.8.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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