Vim write temporary info as :write does -


i have macro calls function defined in vimrc

:function! dostuff()   :!mycommand :end  map <c-p>i :call dostuff()<cr> 

when press macro keys right shell output of mycommand , works fine improve that.

i noticed when write file (:w) short message displayed short time in command bar says "file x written", want achieve same result, when macro sequence pressed want check if command went fine (checking return code) , display message (such "ok" or "not okay") :write command does.

any ideas ?

write external command output temporary file

via vimscript functions

first, capture output of external command in variable, contents can written (temporary) file via writefile().

:let output = system('mycommand') :call writefile(output, 'path/to/tempfile') 

via scratch buffer

if need apply arbitrary commands captured contents, or need vim handle different file encodings, have use buffer:

:new path/to/tempfile :0read !mycommand :write :bdelete 

via file redirection

this simplest approach when need output as-is:

:!mycommand > path/to/tempfile 

check command success , notify

after external command execution, special variable v:shell_error contains exit status of last shell command. can test report message user:

!mycommand if v:shell_error != 0     echohl errormsg     echomsg "the command failed"     echohl none else     echomsg "the command succeeded" endif 

if you've used system() execute command, have error message returned it, , can include in notification.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -