5

Using : st, Ranger, vim, i3

With most files when I open them with ranger it opens in a new window. However, when I try to open a file with vim it opens it in the current terminal which is currently running ranger.

I understand why it does it, I'm just not finding how to get the desired outcome of opening files with vim (from ranger) in a new terminal.

1

5 Answers 5

6

You can edit ranger's rifle config for that. Rifle is ranger's file opener.

ranger --copy-config=rifle.conf

to copy the default rifle config to ~/.config/ranger/rifle.conf

Then change the line in rifle.conf which says

mime ^text, label editor = ${VISUAL:-$EDITOR} -- "$@" to

mime ^text,  label editor = nohup termite -e "${VISUAL:-$EDITOR} $@" >/dev/null &

I use termite terminal emulator. Change that to st in your case.

To open multiple files at once you can use

  mime ^text,  label editor = OPEN_WITH_TABS="${VISUAL:-$EDITOR} -p $@" && nohup termite -e "${OPEN_WITH_TABS}" >/dev/null &
1
  • I had to remove the quotes to get this to work, so my rifle.conf looks like: mime ^text, label editor = nohup termite -e ${VISUAL:-$EDITOR} $@ >/dev/null &
    – Javanator
    Jul 31, 2019 at 0:40
3

You can use t flag to open in a new terminal.

Use r shortcut or type :open_with vim t.

1

I used the solution spotted by Yash for opening mpv in seperate window

mime ^audio|ogg$, terminal, has mpv = nohup gnome-terminal -e "mpv '$a'" > /dev/null &

very useful

1

Instead of hard-coding your preferred terminal, you can simply set the t flag. This will "run [the] program in a separate terminal, as specified by $TERMCMD" (from the man page).

This is the relevant section of my rifle.conf:

# Define the "editor" for text files as first action
mime ^text,  label editor, flag t = ${VISUAL:-$EDITOR} -- "$@"
mime ^text,  label pager, flag t  = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php, flag t = ${VISUAL:-$EDITOR} -- "$@"
!mime ^text, label pager,  ext xml|json|csv|tex|py|pl|rb|js|sh|php, flag t = "$PAGER" -- "$@"
1
  • The right answer.
    – Jortstek
    Oct 19, 2022 at 13:47
0

As the first solution didn't work on me because of quotations as @Javanator mentioned , and because -e option will be deprecated in the feature here is my solution inspired by @Yash:

mime ^text, label editor = gnome-terminal -- vim "$@"

Also bonus points for adding --geometry 153x40-0 option after gnome-terminal to open vim on specific location with specific size and --quiet to ensure what nohup does.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .