I want to execute some external program to format my code.
:silent execute "!eslint --fix -o /dev/null %" | redraw!
But the screen will jump to the shell output screen and shortly back to vim again. How I can avoid this short flash?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communitySince the external command is executed via the shell, you need to append an ampersand (&
) to launch the process in the background:
:silent execute '!eslint --fix -o /dev/null % &' | execute ':redraw!'
You could also try the plugin vim-fixmyjs.
Then, to format on save, just add the following to your .vimrc
:
au BufWritePre *.js :Fixmyjs
au BufWritePre *.jsx :Fixmyjs