1

I want to run clang-format on all open windows.

What I currently do, is:

  • for each open window:
    • :!clang-format --style=file -i %

I have 2 issues:

  1. the clang-format runs in shell, so it doesn't return to Vim until I press ENTER - how can I fix that? (tried fiddeling with terminal but couldn't make it work
  2. How to run this on all open windows / all git diff-ed files? (I have a shell script I would very much like to bind to a Vim shortcut

clang-format shell script:

# unstaged
for FILE in $(git diff --name-only --relative)
do
    clang-format --style=file -i $FILE
done

# staged
for FILE in $(git diff --cached --name-only --relative)
do
    clang-format --style=file -i $FILE
done
2
  • 1
    Your two issues aren't really related to each other. It would be better to post them as separate questions.
    – Rich
    Oct 26, 2022 at 9:27
  • 1
    The first question is answered in :h :windo. For the rest, as Rich suggested, post one question for one problem; don't make it a thread.
    – 3N4N
    Oct 26, 2022 at 11:09

0

Browse other questions tagged or ask your own question.