How to change the default text editor in ranger?

46,068

Solution 1

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.

Solution 2

I figured it out.

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

 export VISUAL=vim;
 export EDITOR=vim;

otherwise, follow these instructions

Solution 3

  • Open ranger, press S, that will open ranger's shell
  • Then enter select-editor, it will show a numbered list of aveilable options and you have to enter the numer of the option that you want.

Solution 4

It is also worth considering the difference between pressing Enter and pressing E on the file that you want to edit

export VISUAL=vim;
export EDITOR=vim;

Though this solution might work when you press E on the file but pressing Enter may vary.

Share:
46,068

Related videos on Youtube

Display name
Author by

Display name

Updated on September 18, 2022

Comments

  • Display name
    Display name almost 2 years

    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.

  • Ava
    Ava over 3 years
    In later versions (currently I'm using 1.9.3) command to copy the config is ranger --copy-config=rifle.