Use vim to edit ANY text on Linux

Solution 1:

It would depend on what file manager you are using, but most of them you can usually add some sort of right-click menu item to "Open in Vim".

I use Dolphin for KDE4. To add menu items (called service menus) you create a .desktop file in your service menus folder. In my system this resides in /usr/share/kde4/services/ServiceMenus but it may vary for your system.

Create the file open_in_vim.desktop with the following contents:

[Desktop Entry]
X-SuSE-translate=true
Type=Service
MimeType=all/allfiles
ServiceTypes=KonqPopupMenu/Plugin
Actions=openInVim
X-KDE-Priority=TopLevel

[Desktop Action openInVim]
Name=Open in Vim
Icon=gvim
Exec=gvim %u

Restart Dolphin (or Konqueror) and you should see this option when you right-click on a file.

If you would also like to be able to open folders in vim, then change the mime type to all/all.

If you would prefer to have "Open in Vim" appear under the Actions menu then remove the line, X-KDE-Priority=TopLevel

Granted, it's not intuitive, but you don't have to pay money in order to do it!

Solution 2:

Try this script: quicked. I was inspired to have a bash at it, after having tried It's all Text!.. (Hey, I'm Australian; the "bash" pun was unavoidable :)

It isn't as slick as It's all Text! which is limited to use within Firefox, but it works for (almost) ALL text in (almost) ALL windows ...I'm using Ubuntu 10.04

It should(?) work in other X11 / Gnome environments, but it may not(?).

By default it is set to use gedit, and you can choose gvim if you prefer...
...just change the value of EDITOR=

Be sure to read all the comments..

It should do the trick until something better comes along...

PS: You must pre-select some text, but there is no need to copy it to the Clipboard.
Just select the text and then press whatever shortcut key you've chosen for quicked

PPS:
In the script's comments I forgot to mention: xwininfo is in the x11-utils suite.
...so, to install all the dependencies on Ubuntu/Debianm use the following command

  • sudo apt-get install wmctrl xclip xdotool x11-utils zenity