Vim: save call function

I use ghc-mod in vim and would like GhcModCheck (: GhcModCheck) to be called every time I save the file (: w). Could you tell me how I can achieve this? I assume that there is a more general question: how can I call a function to save?

Thanks!

+5
source share
2 answers

You can connect to the BufWritePost event. Globally (i.e. for each file):

 :autocmd BufWritePost * GhcModCheck 

To do this only for Haskell files, you can modify the file template:

 :autocmd BufWritePost *.hs GhcModCheck 

But it's better to use Vim's built-in file type definition and instead put it in ~/.vim/ftplugin/haskell_OnSave.vim :

 :autocmd! BufWritePost <buffer> GhcModCheck 
+5
source

Tuning tips for ghcmod-vim

One of them -

 autocmd BufWritePost *.hs GhcModCheckAndLintAsync 

This is also the answer to the general question about the execution of a specific command when saving.

+4
source

Source: https://habr.com/ru/post/1270263/


All Articles