diff --git a/vim-smartcase/README.md b/vim-smartcase/README.md new file mode 100644 index 0000000..0ba204f --- /dev/null +++ b/vim-smartcase/README.md @@ -0,0 +1,75 @@ +--- +title: vim-smartcase +homepage: https://webinstall.dev/vim-smartcase +tagline: | + vim smartcase is Vim's built-in semi-insensitive case matching +--- + +To update (replacing the current version) run `webi vim-smartcase`. + +### Files + +These are the files / directories that are created and/or modified with this +install: + +```txt +~/.vimrc +~/.vim/plugins/smartcase.vim +``` + +## Cheat Sheet + +Vim search `/foo` is case-sensitive by default, but comes with options for +swapping that to be: + +1. _case-insensitive_ by default - i.e. `/foo\c` +2. and _case-sensitive_ on mixed-case search - i.e. `/Foo\C` + +This vim-smartcase plugin adds `set ignorecase` and `set smartcase` to your +`~/.vimrc`. + +### Case Sensitivity in Vim + +```vim +" treat everything in text and search as lowercase +set ignorecase +``` + +```vim +" treat mixed case as case sensitive +" requires 'ignorecase' to work +set smartcase +``` + +```vim +" explicit case-insensitive search for 'Bar' +" (\c can go anywhere in the search) +/Bar\c +/\cBar +/Ba\cr +``` + +```vim +" explicit case-sensitive search for 'Bar' +" (\C can go anywhere in the search) +/Bar\C +/\CBar +/Ba\Cr +``` + +### How to do this manually + +Set `~/.vimrc`: + +```vim +" make searches case-insensitive by default (i.e. /foo\c) +:set ignorecase +" make mixed-case searches case-sensitive by default (i.e. /Foo\C) +:set smartcase + +" fyi: you can put \c or \C before, after, or in the middle of a search +" ex: /Bar\c or /\cBar or /B\car +``` + +Available at + diff --git a/vim-smartcase/install.sh b/vim-smartcase/install.sh new file mode 100644 index 0000000..5ebe859 --- /dev/null +++ b/vim-smartcase/install.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +__init_vim_smartcase() { + set -e + set -u + + mkdir -p "$HOME/.vim/plugins" + rm -rf "$HOME/.vim/plugins/smartcase.vim" + + echo "" + + if [ ! -e "$HOME/.vimrc" ]; then + touch "$HOME/.vimrc" + fi + + if ! [ -f "$HOME/.vim/plugins/smartcase.vim" ]; then + mkdir -p ~/.vim/plugins + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + curl -fsS -o ~/.vim/plugins/smartcase.vim "$WEBI_HOST/packages/vim-smartcase/smartcase.vim" + fi + + if ! grep 'source.*plugins.smartcase.vim' -r ~/.vimrc > /dev/null 2> /dev/null; then + set +e + mkdir -p ~/.vim/plugins + printf '\n" Smart Case: reasonable defaults from webinstall.dev/vim-smartcase\n' >> ~/.vimrc + printf 'source ~/.vim/plugins/smartcase.vim\n' >> ~/.vimrc + set -e + echo "added ~/.vim/plugins/smartcase.vim" + echo "updated ~/.vimrc with 'source ~/.vim/plugins/smartcase.vim'" + echo "" + fi + + echo "vim-smartcase enabled with reasonable defaults" +} + +__init_vim_smartcase diff --git a/vim-smartcase/smartcase.vim b/vim-smartcase/smartcase.vim new file mode 100644 index 0000000..e11cac2 --- /dev/null +++ b/vim-smartcase/smartcase.vim @@ -0,0 +1,7 @@ +" make searches case-insensitive by default (i.e. /foo\c) +:set ignorecase +" make mixed-case searches case-sensitive by default (i.e. /Foo\C) +:set smartcase + +" fyi: you can put \c or \C before, after, or in the middle of a search +" ex: /Bar\c or /\cBar or /B\car