I would like to handle a drag & drop event of a file into gvim in order to insert the file name into the buffer I am dropping it. This should happen only when such file is an image, e.g. .png, or .jpg.

Instead of the default behavior of opening after dropping the file I want to paste the file name only if I detect it is an image.

I have already checked :help autocmd-events-abc but there was nothing related to drag and drop functionality or event associated to it. Is it written anywhere else?

I already know that ftdetect directory is used to detect the filetypes depending on the file extension, among other possibilities.


According to :help drag-n-drop and :help :drop, it doesn't seem like this behavior is change-able.

The help also says

If Vim happens to be editing a command line, the names of the dropped files
and directories will be inserted at the cursor.  This allows you to use these
names with any Ex command.  Special characters (space, tab, double quote and
'|'; backslash on non-MS-Windows systems) will be escaped.

So, you can instead do

:normal! a

(without hitting Enter), drag-n-drop your file, then press Enter. Rebind to a key for easier access, if you prefer.

  • Thanks for the answer. You provided very good hints to solve my issue.
    – aturegano
    Dec 30 '19 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.