Vim autocommand on write - pass full file path
Asked Answered
P

1

8

I want to execute a bash script whenever I save a file in Vim. The problem is I don't how can I, or if it's possible to pass the full path to the file, rather than just the file name, or relative path that was opened.

This is the code I'm using, it works, however only relative paths, which is useless to me.

autocmd BufWritePost * !~/.config/nvim/scripts/on_save.sh <afile> 

Is there any way to pass the full file path to the bash script?

Pizzicato answered 10/7, 2018 at 19:4 Comment(0)
P
11

I found it:

autocmd BufWritePost * !~/.config/nvim/scripts/on_save.sh %:p  

The %:p does it

Pizzicato answered 10/7, 2018 at 19:17 Comment(3)
You forgot to mention where you found it: :help filename-modifiers.Unseasonable
Actually I found it on ServerFault or some other QA but thanks for referencePizzicato
web link for the lazy folks like me: vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiersClastic

© 2022 - 2024 — McMap. All rights reserved.