5

I want to assign a terminal based program as a default program in Gnome Shell 3.2. I am running Ubuntu 11.10.

More specifically, I want my .txt files to open in vim with maximized Gnome Terminal.

The 'Open with other application' menu does not provide for this.

Thanks in advance for help.

2 Answers 2

4

I found another solution as above solution didn't work for me (I don't know why).

Create a file mvim in /usr/bin/ by:

sudo vim /usr/bin/mvim

And paste the following two lines:

#!/bin/bash
/usr/bin/gnome-terminal -e "/usr/bin/vim $1"

Press :wq and Enter to save.

Now give executable permissions to this your command by:

sudo chmod +x /usr/bin/mvim

To test if it's gonna work or not, you can type:

mvim anyfile

It should open a new terminal with anyfile opened in vim.

Now open your file manager (mine is SpaceFM) and right click a text file and click Properties. If there is an option of open with command then type in the path to your command i.e. /usr/bin/mvim.

And yay! meanwhile you created your own command!

3
  • 1
    You'll run into trouble with filenames with spaces. Use /usr/bin/gnome-terminal -e "/usr/bin/vim '$1'", or /usr/bin/gnome-terminal -x /usr/bin/vim "$1". Better yet, use -x and $@: /usr/bin/gnome-terminal -x /usr/bin/vim "$@", in case you want to pass options to Vim, or open multiple files.
    – muru
    Dec 26, 2015 at 12:47
  • Thanks for the information, muru. I am using lxterminal as of now. Is there any alternative for -x flag or something to make multiple files thing work for me. Dec 26, 2015 at 13:03
  • @MandeepSingh Care to try xfce4-terminal? It's also lightweight, and supports -x.
    – muru
    Dec 26, 2015 at 17:28
3

For files handling in gnome you will have to use the graphical version of vim called gvim, to install it type sudo apt-get install vim-gnome.

Has an option you can create a .desktop file that will be listed on 'Open with other application' tab:

  • Navigate to ~/.local/share/applications
  • Create a file called vim-console.desktop with these contents:
[Desktop Entry]
Encoding=UTF-8
Name=Vim Text Editor (Console)
Comment=Edit text files in a console using Vim
Exec=gnome-terminal --full-screen --execute bash -c "vim %u"
Terminal=true
Type=Application
Icon=/usr/share/pixmaps/vim.svg
Categories=Application;Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;
NoDisplay=true

After this you will see Vim Text Editor (Console) in your Open with other application tab, select it and when you double click the file you will be able to open it using vim terminal editor.

0

You must log in to answer this question.

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