Ads
Tom's Guide > Forum > Linux/Free BSD > General Discussion > Launching files in vim with a click

Launching files in vim with a click

Forum Linux/Free BSD : General Discussion Launching files in vim with a click

Related Content
Can't find your answer?
Ask!
Word :    Username :           
 
- 0 +

In GNOME, they let you add custom commands to associate a file with a certain program to open it. This has proven pretty useful for me as I have been able to change my music files to associate with audacious and my movies to associate with mplayer, so now I would like to do the same kind of thing, but with text files. How do I make it so that I can double click on a source code file and it will open it in an instance of vim in the terminal? I know you can just have it open with gvim, but I prefer working with vim in the terminal because I have my terminal set to be transparent, and I like that (it is pretty useful sometimes). The closest i have come to getting a double click of a .c or .asm file to launch a terminal and start vim is the following command ' gnome-terminal -e vim ', but that will only allow me to start a blank vim (i.e. it doesn't open the file i clicked on), so I figure I need some sort of way to specify "this file" or the file that I just clicked on, but I don't know how to do this. I've tried looking for a solution online and it is a difficult problem for me to describe so it doesn't lend itself well to a google search. Any help you can provide is appreciated.

-Zorak

Reply to Zorak
Register or log in to remove.
- 0 +

/usr/bin/vim ~/Zvim

#!/bin/bash

/usr/bin/gnome-terminal -e "/usr/bin/vim $1"
:wq


Right click on a .c file, properties, open with, Add, Use a custom command, browse, point it to "/home/zorak/Zvim", Open then Add and Close

Double click on a .c file it should open inside vi in a gnome-terminal

Repeat for .asm files and any other extensions you want

This was tested and confirmed to work on Fedora ;)

Perhaps not the most elegant way to do it but hey it works.

GL :)

------------------------------ $GNU_Linux=$Linus_Torvalds=AWESOME();
Reply to linux_0
- 0 +

Oh yeah Zvim = Zorak's vim

Any other legal command combo should work as well

GL :)

------------------------------ $GNU_Linux=$Linus_Torvalds=AWESOME();
Reply to linux_0
- 0 +

hahahaha, Linux_0 you are a god damn genius! Thanks! :)

-Zorak

Reply to Zorak
- 0 +

:blushing: thanks :)

------------------------------ $GNU_Linux=$Linus_Torvalds=AWESOME();
Reply to linux_0
- 0 +

So this script has been pretty useful to me, but even so I have tried to find a way to improve it. The change I've tried to make is to have an instance of bash running on top of gnome-terminal and have that instance of bash start vim. That way, when I close vim or ^z vim, I still have a fully functioning shell to work with. More accurately, I've been using a modified form of this script under cygwin at work, and now I am trying to add the functionality I just described.

So, the script should do this: gnome-terminal (rxvt at work) ----> bash ----> vim with the file i want to edit

I tried doing the following: (at home) gnome-terminal -e bash -l -i -c "vim "$1""
(at work) rxvt -e bash -l -i -c "vim "%1""

both of these commands will work in that they will get vim to open up in a terminal, but if i ^z out of vim or if i :q I don't have an instance of bash to fall back on. In the case of ^z, the program is successfully stopped, but since there is no shell to drop to, I can't start it again or execute commands. If I :q, the whole window closes. I appreciate any additional light you can shed on this subject.

-Zorak

Reply to Zorak
TomsGuide.com: Over 800,000 questions and answers to address all your high-tech questions. Sign up now! Its free!
Tom's Guide > Forum > Linux/Free BSD > General Discussion > Launching files in vim with a click
Go to:

There are 46 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Tom's Guide around the World