Does something like this exist?
In Vim this is called an autocommand. The relevant help topic can be found by typing :h autocommand (sic!)
An example code to put into vimrc:
augroup typescript_save | au!
autocmd BufWritePost *.ts execute '!tsc' expand("<afile>:p:S")
it doesn't seem to pass in the argument
Because you haven't passed it. The right syntax is:
command! -nargs=1 Vres vertical resize <args>
Simply read :help :command until the very end to know all the options.
Can it be written?
Possibly, but it might be a lot harder than expected. Because, what do you do with commands that close the current window? Or commands, that add lines above the current cursor position?
One problem you are running into is described unter :h function-search-undo.
The last used search pattern and the redo command "."
will not be changed ...
I’d recommend an <expr> mapping—make the following changes:
nnoremap <expr> <Leader>b BuildSystemTask()
And then in your function:
return ':make! '
An alternative would be to use the feedkeys() function
You must add -nargs=1 to your command:
:command -nargs=1 FooCommand :call Foo(<q-args>)
This tells Vim not to treat white space as separator. Only white space between the command name and the first non-white space character is removed from the argument passed to Foo(). All other spaces and tabs, even trailing ones, are included in the argument.
It's faster as :buf won't reload the file from disk, whereas :edit will, which is different behaviour.
This is why it's slightly slower in some cases. For most purposes, this is not a huge issue, although it can be over NFS connections, or with larger files. The performance should be identical when opening files that are not yet loaded by Vim.
You can test/...