In a Jekyll file I have

 <IMG SRC="/assets/images/

I would like to use the filename autocompletion shortcut to insert the rest of the filename, but this fails because of the leading slash.

When I remove the leading slash, the completion works perfectly but I then I have to put it back in for the code to work.

How can I tell vim to ignore the slash?

Related question is this one but the solutions do not appear relevant.

  • 3
    Fwiw it’s not usually necessary to write jekyll links that way (one of the template params is site.url or something similar. You can also use {% link file %}, which works with relative paths!)
    – D. Ben Knoble
    Commented Jan 26, 2021 at 13:17
  • 1
    I don't think there's really any way to do this without overriding the <C-x><C-f> logic to implement your own, or using completefunc. See How to create my own autocomplete function? The help page says "Note: the 'path' option is not used here (yet)", so the "real solution" would probably be to implement that in Vim. Commented Jan 26, 2021 at 20:34
  • @D.BenKnoble - oooh, will check that out (although I still find the question interesting)
    – Joe
    Commented Jan 27, 2021 at 11:59

1 Answer 1


I work around it by first typing the path without the leading slash '/', so that vim will complete it, and then afterwards prepend the slash using one of the following maps

nnoremap [MAPKEYS] m'F"a/<Esc>`'l
imap [MAPKEYS] <Esc>[MAPKEYS]a

The cursors position is also restored. Note that the maps rely on the path being surrounded by quotes ("the/path").

PS: remember to use <buffer> if you put this in an ft file (e.g. .vim/after/ftplugin/{markdown,liquid}.vim or in autocommands. A more robust version of the above is given here (put in .vimrc and reload):

augroup slash_bindings
  autocmd! slash_bindings
  autocmd Filetype markdown,liquid,yaml nnoremap <buffer> <MAPKEY> m':call search("['\"]", "b")<CR>a/<Esc>`'l
  autocmd Filetype markdown,liquid,yaml imap <buffer> <MAPKEY> <Esc><MAPKEY>a
augroup end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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