Commit 93723e9a authored by Adrien Dorsaz's avatar Adrien Dorsaz
Browse files

transform as VIM plugin, use Gio.File to retrieve file info

parent 85aa93b8
# gtk-recent.vim - a gnome logger for Vim
## Behaviour
If you modify a file with vim and want to upload it on a web interface, you wish you could find this file in Firefox's "recent files" category. Well now you can : with this plugin, each opened file will be added to Gnome's recent list (and to Zeitgeist as a consequence, see [Gnome's wiki](
This extension add files opened with vim to the GNOME recent files feature
(visible in the "Recent files" view of GNOME File Manager and file chooser).
## Limitations
This thing adds quite a huge latency to vim startup/shutdown. I made a C
version that you can find [here](
This plugin adds quite a huge latency to vim startup/shutdown.
## Installation
If you're using Arch linux, there's a PKGBUILD : .
Drop this file in a vim plugin folder ($HOME/.vim/plugin,/usr/share/vim/vimfiles/plugin, ...). Vim should be compiled with python enabled.
You will need to have python-gobject installed, and vim or neovim with python support.
This is a vim plugin which can be installed with default vim plugin manager.
## History
Derived from :
Improved to use python 3, and to use [GtkRecentManager](
* [Port to python3 and GtkRecentManager by lafleur](
* [Original idea](
## License
......@@ -9,16 +9,22 @@ if v:version < 703
function! GtkRecentLog(filename,use_id)
function! GtkRecentLog(filename)
python3 << endpython
filename = vim.eval("a:filename")
manager = Gtk.RecentManager()
recent_data = Gtk.RecentData()
recent_data.app_name = "vi"
recent_data.mime_type = "text/plain"
recent_data.app_exec = "vi"
manager.add_full("file://" + filename, recent_data)
# Use Gio to ensure file exists and retrieve content type
file = Gio.File.new_for_path(filename)
info = file.query_info(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, Gio.FileQueryInfoFlags.NONE)
manager = Gtk.RecentManager()
recent_data = Gtk.RecentData()
recent_data.app_name = "vim"
recent_data.mime_type = info.get_content_type()
recent_data.app_exec = "vim %f"
recent_data.is_private = False
manager.add_full(file.get_uri(), recent_data)
......@@ -29,13 +35,12 @@ import vim
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio
if match(system('whoami'), 'root') == -1
augroup gtkRecent
au BufRead * call GtkRecentLog (expand("%:p"), "read")
au BufNewFile * call GtkRecentLog (expand("%:p"), "new")
au BufWrite * call GtkRecentLog (expand("%:p"), "write")
au BufNewFile,BufRead,BufWrite,BufEnter,VimEnter * call GtkRecentLog (expand("%:p"))
augroup END
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment