Set Vim in Terminal as Permanent Default Text Editor

I use Vim on every distro for text editing, so I like to make sure that it is the Default text editor both in the Terminal and the Gui Desktop.

How to set Vim as default system wide, issue the command and choose Vim:

sudo update-alternatives –config editor

Which gives me this output:
You can see that Nano is currently set as default so I choose number 3 to set vim.basic


There are 4 choices for the alternative editor (providing /usr/bin/editor).

Selection    Path                Priority   Status
————————————————————
* 0            /bin/nano            40        auto mode
1            /bin/ed             -100       manual mode
2            /bin/nano            40        manual mode
3            /usr/bin/vim.basic   30        manual mode
4            /usr/bin/vim.tiny    10        manual mode

Setting the Terminal Vim as the Gui Text Editor:
Most desktop environments and distros have one of the top 3 terminals and text editors set as default, so we are going to create a little Bash script to tell the system to use our terminal Vim text editor instead of the system’s default Gui Editor:

D/E        TERM                    EDITOR
Xfce       xfce4-terminal         Mousepad
Gnome   gnome-terminal      Gedit
Kde        konsole                 Kate

1. Create the script:

 vim vim-gui

 2. Add this with your particular terminal:
Leave it as it is for Gnome, Xfce, Xterm, etc but remove the quotes “” from [vim $ARGS] for konsole.
Thanks to penguiniator for pointing that out in the comments 🙂

 #!/bin/bash
ARGS=”$@”
gnome-terminal -e “vim $ARGS”

3. Save and Quit:

 :wq

4. Make script executable:

 chmod +x vim-gui

5. Copy script to your scripts directory (/home/USER/bin)

 cp vim-gui /home/rich/bin/

 6. Set it as the default editor from your desktop:
Open your file browser; Dolphin, Nautilus, Thunar etc, right click on any text file and select “Properties“.
Now look for the “Open With” option, and select “Add” or “Use Custom Command” and navigate to your vim-gui script in /home/USER/bin.

You can do this for any files you wish to open with Vim in the terminal by default.

 

Advertisements

2 thoughts on “Set Vim in Terminal as Permanent Default Text Editor

  1. The same commands will work with konsole if you remove the quotes from around vim $ARGS. This is documented at konsole –help, which shows the -e cmd Command to execute option and args Arguments passed to command as a separate set of arguments not quoted as a part of cmd.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s