0

I've run into an odd problem in Vim. I would like to drag and drop a file from my desktop or file manager into Vim and edit it. Gvim handles this behavior correctly.

When I attempt to do the same thing in console Vim, the path to the file name is inserted instead. For example, if I drag and drop the file /home/myuser/foo.matic, it will apply the text string '/home/myuser/foo.matic' to the current buffer.

If I type :edit, then drag and drop the file name, Vim treats '/home/myuser/foo.matic' as a new directory.

I believe the problem here is the quotes before and after the file path. These appear to be inserted by both gnome-terminal and terminator. Is there a way to strip these quotes from the file name when dragging and dropping? Alternatively, is there a way for Vim to ignore the quotes?

rustushki
  • 164
  • 1
  • 9
  • 3
    It seems a bit weird to use drag&drop with terminal vim. For graphical use, there is gVim. I'd rather type `:e foo.matic` in vim or `vim foo.matic` in the terminal. Another way to go is `gvim -p --remote-tab-silent foo.matic` to open the file in gvim in a new tab. – epsilonhalbe Jul 01 '12 at 14:06
  • I've found recently that screen redraw weirdness happen far less in terminal Vim. Since I use very little of gVim's extra GUI functionality, it made sense to me to try using terminal Vim instead. Whenever it makes sense, I'll drag a file into the editor rather than open it with :e or NERD Tree. – rustushki Jul 02 '12 at 15:50
  • It looks like I can use --remote-tab-silent with terminal Vim as well. This might be a good option. – rustushki Jul 02 '12 at 15:51

1 Answers1

2

You can’t make vim own :e command to do what you need, but you can define your own one. Most straightforward solution - make shell parse what was intended to be parsed by the shell - is listed below:

command -nargs=? -bang -bar E :execute "e<bang> ".fnameescape(system("echo -n ".<q-args>))

. This command accepts only :e[!] {file} variant, no +cmd and ++opts are allowed.

ZyX
  • 52,536
  • 7
  • 114
  • 135
  • This seems to solve my problem with dragging files into Vim. It requires that I type :e before dragging, but that is acceptable for as much as I actually require the dragging of files. Thank you ZyX. – rustushki Jul 02 '12 at 15:52
  • @rustushki Not typing `:e` before dragging, but `:E`. I don’t believe it is possible to something better (though there may be a pointer somewhere in gnome-terminal documentation, terminal emulators have quite a lot features compared to old terminals and framebuffer). Definitely not without patching vim: documentation states that drag'n'drop works only in GTK, win16 and win32 GUIs. – ZyX Jul 02 '12 at 20:41