1

I'm trying to pass a command to 'vim-tmux-runner' on each file save with au bellow.

autocmd FileWritePost,BufWritePost *.py :VtrSendCommandToRunner python manage.py test <afile>:p:h:t

Where:

  • :VtrSendCommandToRunner sends a command to shell in another tmux pane

  • python manage.py test is the actual command being sent to shell

  • <afile>:p:h:t and at the end of the command I add a variable that should be expanded to the name of the folder that my file was just saved in.

On each save my shell command tells me that there is no such file as <afile>:p:h:t so as I understand vim did not expand those variables.

Before I added :VtrSendCommandToRunner (originally my Ex command started with :!) my Ex command was expanded correctly.

I tried to rewrite that Ex command in couple other ways but I can't get anything to work.

Some versions of Ex command that I tried(all failed me):

<afile>:p:h:t
%:p:h:t
expand(%:p:h:t)

How can I get vim to expand % to a file name then?

  • 1
    Might need to use execute(). – Tumbler41 Apr 25 '18 at 18:27
  • 2
    use expand() . – Christian Brabandt Apr 25 '18 at 18:30
  • @Tumbler41 not sure if you want to post it as an answer for point, if not I will to help next person with this issue – sgp667 Apr 25 '18 at 18:46
  • Can't do a full write-up right now. If you want to post something that's fine. If not, I'll do it in a couple hours. – Tumbler41 Apr 25 '18 at 18:52
  • @sgp667 Wait, maybe you should answer with what worked for you, because now I'm confused. Expand seems to work as long as you have the contents enclosed in a string: '%:p:h:t'. I can't get execute to work. – Tumbler41 Apr 27 '18 at 15:37

Your Answer

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

Browse other questions tagged or ask your own question.