0

I'm writing a simple command for an operation I do quite often in vim:

command! EslintFix !./node_modules/.bin/eslint --fix %

This will change the file I'm currently working on, so I'd like to reload the file in the same command but I'm not sure how to follow the shell command with the Vim command e% to reload the current file. If I write this:

command! EslintFix !./node_modules/.bin/eslint --fix % | e%

Vim ends up running e% in the shell instead of Vim.

How can I write a custom command like this where I want to execute something in the shell followed by executing a Vim command?

1 Answer 1

2

Option #1 (using system()):

command! EslintFix call system('./node_modules/.bin/eslint --fix ' . fnameexpand('%:p:S')) | e%

Option #2 (using execute):

command! EslintFix execute '!./node_modules/.bin/eslint --fix %' | e%
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.