From cfb6397ec7a13157c61d776b15da9057b2d0ef02 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 22 Mar 2021 16:56:40 +0000 Subject: [PATCH] add vim-whitespace --- vim-whitespace/README.md | 41 +++++++++++++++++++++++++++++++++++ vim-whitespace/install.sh | 36 ++++++++++++++++++++++++++++++ vim-whitespace/whitespace.vim | 15 +++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 vim-whitespace/README.md create mode 100644 vim-whitespace/install.sh create mode 100644 vim-whitespace/whitespace.vim diff --git a/vim-whitespace/README.md b/vim-whitespace/README.md new file mode 100644 index 0000000..55474dc --- /dev/null +++ b/vim-whitespace/README.md @@ -0,0 +1,41 @@ +--- +title: vim-whitespace +homepage: https://webinstall.dev/vim-whitespace +tagline: | + vim whitespace sets tab, whitespace, trailing whitespace rules to reasonable values +--- + +To update (replacing the current version) run `webi vim-whitespace`. + +## Cheat Sheet + +The idea that tabs should be 8 spaces wide is redonkulous. + +This vim-whitespace plugin sets tabs to spaces (4 wide), trim trailing +whitespace, and makes whitespace handling consistent. + +### How to configure manually + +Create the file `~/.vim/plugins/whitespace.vim`. Add the same contents as +. + +That will look something like this: + +```vim +" handle tabs as 4 spaces, in every direction, consintently +set tabstop=4 +set shiftwidth=4 +set smarttab +set expandtab +set softtabstop=4 + +" remove trailing whitespace on save +autocmd BufWritePre * :%s/\s\+$//e +``` + +You'll then need to update `~/.vimrc` to source that plugin: + +```vim +" Tabs & Whitespace: reasonable defaults from webinstall.dev/vim-whitespace +source ~/.vim/plugins/whitespace.vim +``` diff --git a/vim-whitespace/install.sh b/vim-whitespace/install.sh new file mode 100644 index 0000000..22009f0 --- /dev/null +++ b/vim-whitespace/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +function __init_vim_whitespace() { + set -e + set -u + + mkdir -p "$HOME/.vim/plugins" + rm -rf "$HOME/.vim/plugins/whitespace.vim" + + echo "" + + if [ ! -e "$HOME/.vimrc" ]; then + touch "$HOME/.vimrc" + fi + + if ! [ -f "$HOME/.vim/plugins/whitespace.vim" ]; then + mkdir -p ~/.vim/plugins + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + curl -fsS -o ~/.vim/plugins/whitespace.vim "$WEBI_HOST/packages/vim-whitespace/whitespace.vim" + fi + + if ! grep 'source.*plugins.whitespace.vim' -r ~/.vimrc > /dev/null 2> /dev/null; then + set +e + mkdir -p ~/.vim/plugins + printf '\n" Tab & Whitespace: reasonable defaults from webinstall.dev/vim-whitespace\n' >> ~/.vimrc + printf 'source ~/.vim/plugins/whitespace.vim\n' >> ~/.vimrc + set -e + echo "added ~/.vim/plugins/whitespace.vim" + echo "updated ~/.vimrc with 'source ~/.vim/plugins/whitespace.vim'" + echo "" + fi + + echo "Vim's has been updated with reasonable whitespace settings." +} + +__init_vim_whitespace diff --git a/vim-whitespace/whitespace.vim b/vim-whitespace/whitespace.vim new file mode 100644 index 0000000..3b5cf33 --- /dev/null +++ b/vim-whitespace/whitespace.vim @@ -0,0 +1,15 @@ +" The default tab width is 8 spaces, which is redonkulous. +" We'll set it to 4 instead, which is reasonable. +" (feel free to change to 2, but 3 is right out). +" +" Also, I'm not actually sure what the individual options do, +" but it's something like 'always use spaces' and +" 'use the same width when typing, tabbing, deleting, moving, etc' +set tabstop=4 +set shiftwidth=4 +set smarttab +set expandtab +set softtabstop=4 + +" remove trailing whitespace on save +autocmd BufWritePre * :%s/\s\+$//e -- 2.25.1