5

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?

muru
  • 24,838
  • 8
  • 82
  • 143
Aaron Shen
  • 2,519
  • 3
  • 24
  • 37

1 Answers1

5

Since 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
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
byaruhaf
  • 786
  • 6
  • 9