From: Misomosi Date: Sun, 3 Nov 2024 21:13:35 +0000 (-0500) Subject: Add commands to vim for autoformat X-Git-Url: http://git.misomosispi.com/?a=commitdiff_plain;h=36f77e6331910cc71e7028e922f75bc921394ec2;p=dotfiles.git Add commands to vim for autoformat --- diff --git a/.local/bin/git-vim-format b/.local/bin/git-vim-format new file mode 100644 index 0000000..b0a18b0 --- /dev/null +++ b/.local/bin/git-vim-format @@ -0,0 +1,9 @@ +#!/bin/sh + +# Shell script for auto-formatting on BufWritePost in vim +# I don't want to run this on all files, just those in git +# repos which have a strict code style. +BUFNAME="$1" +if git config --get clangformat.style >/dev/null ; then + exec clang-format -i --style="$(git config --get clangformat.style)" "$BUFNAME" +fi diff --git a/.vimrc b/.vimrc index 8ef5a28..db92c93 100644 --- a/.vimrc +++ b/.vimrc @@ -1 +1,7 @@ source ~/.exrc +set autoread +function! GitVimFormat(filename) + call system('git vim-format ' . shellescape(a:filename)) + e +endfunction +au BufWritePost *.c call GitVimFormat(bufname()) diff --git a/README.md b/README.md index 2032f2a..0ba49ac 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,25 @@ set wrapscan ## .vimrc ``` source ~/.exrc +set autoread +function! GitVimFormat(filename) + call system('git vim-format ' . shellescape(a:filename)) + e +endfunction +au BufWritePost *.c call GitVimFormat(bufname()) +``` + +## git-vim-format +``` +#!/bin/sh + +# Shell script for auto-formatting on BufWritePost in vim +# I don't want to run this on all files, just those in git +# repos which have a strict code style. +BUFNAME="$1" +if git config --get clangformat.style >/dev/null ; then + exec clang-format -i --style="$(git config --get clangformat.style)" "$BUFNAME" +fi ``` ## .tmux.conf