autocmd VimLeave * :!touch /home/odiszapc/vimleave<cr>

After exiting by typing :q<CR> the file is not created. What I'm doing wrong?

Version of ViM:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 20 2015 10:38:14)
Included patches: 1-207, 209-801, 803-808, 810-827

1 Answer 1


What I was doing wrong is adding <cr> at the end of the line. That's work pretty well:

autocmd VimLeave * :!touch /home/odiszapc/vimleave
  • 1
    Yeah, you only need <Cr> in key mappings (nnoremap and friends). For autocmds, it's just a list of "normal" Vim commands. This can be a bit confusing, but does make sense: with a mapping, you want to replicate keys a user might type; leaving of <Cr> for example can be quite useful. With autocmds, you just want to run some VimScript, not emulate what a user might type (although you could, with :normal). Commented Nov 12, 2015 at 13:34

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.