From f84a4c5b694ccfc736e43751098e4fd9da35048f Mon Sep 17 00:00:00 2001 From: Ryan Burnette Date: Sat, 1 Jan 2022 11:16:18 -0500 Subject: [PATCH] feat: add vim-commentary --- vim-commentary/README.md | 49 +++++++++++++++++++++++++++++++++++ vim-commentary/commentary.vim | 2 ++ vim-commentary/install.ps1 | 17 ++++++++++++ vim-commentary/install.sh | 43 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 vim-commentary/README.md create mode 100644 vim-commentary/commentary.vim create mode 100644 vim-commentary/install.ps1 create mode 100644 vim-commentary/install.sh diff --git a/vim-commentary/README.md b/vim-commentary/README.md new file mode 100644 index 0000000..f6493aa --- /dev/null +++ b/vim-commentary/README.md @@ -0,0 +1,49 @@ +--- +title: vim-commentary +homepage: https://github.com/tpope/vim-commentary +tagline: | + Toggle blocks of line comments. +--- + +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: + +```text +~/.vimrc +~/.vim/pack/plugins/start/vim-commentary/ +~/.vim/plugins/smartcase.vim +``` + +## Cheat Sheet + +> Makes it super easy to toggle entire blocks of comments. + +```vim +gc +``` + +- `v` to enter visual model +- `hjkl` (or arrow keys) to select lines +- `gc` to toggle comments on or off + +### How to add file types + +Update `~/.vim/plugins/commentary.vim` with a line like this: + +```vim +autocmd FileType apache setlocal commentstring=#\ %s +``` + +### How to do Advanced Vim-Nerd Stuff + +All the typical navigation applies: + +> Use `gcc` to comment out a line (takes a count), `gc` to comment out the +> target of a motion (for example, `gcap` to comment out a paragraph), `gc` in +> operator pending mode to target a comment. You can also use it as a command, +> either with a range like `:7,17Commentary`, or as part of a `:global` +> invocation like with `:g/TODO/Commentary`. - The Official README diff --git a/vim-commentary/commentary.vim b/vim-commentary/commentary.vim new file mode 100644 index 0000000..f0e63dd --- /dev/null +++ b/vim-commentary/commentary.vim @@ -0,0 +1,2 @@ +" Example of a adding additional file type support: +"autocmd FileType apache setlocal commentstring=#\ %s diff --git a/vim-commentary/install.ps1 b/vim-commentary/install.ps1 new file mode 100644 index 0000000..19d801e --- /dev/null +++ b/vim-commentary/install.ps1 @@ -0,0 +1,17 @@ +#!/usr/bin/env pwsh + +$my_name = "commentary" +$my_pkg_name = "vim-commentary" +$my_repo = "https://github.com/tpope/vim-commentary" + +IF (!(Test-Path -Path "$Env:USERPROFILE\.vim\pack\plugins\start")) { + New-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start" -ItemType Directory -Force | out-null +} + +Remove-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start\${my_name}" -Recurse -ErrorAction Ignore +& git clone --depth=1 "$my_repo" "$Env:USERPROFILE\.vim\pack\plugins\start\$my_name.vim" + +IF (!(Test-Path -Path "$Env:USERPROFILE\.vim\plugin\$my_name.vim")) { + IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" } + curl.exe -sS -o "$Env:USERPROFILE\.vim\plugin\$my_name.vim" "$Env:WEBI_HOST/packages/${my_pkg_name}/${my_name}.vim" +} diff --git a/vim-commentary/install.sh b/vim-commentary/install.sh new file mode 100644 index 0000000..a568147 --- /dev/null +++ b/vim-commentary/install.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +__install_vim_plugin() { ( + set -e + set -u + + my_name="commentary" + my_pkg_name="vim-commentary" + my_repo="https://github.com/tpope/vim-commentary.git" + my_note="vim-commentary: installed via webinstall.dev/vim-commentary" + my_installed_msg="${my_pkg_name} installed with example config" + + mkdir -p ~/.vim/pack/plugins/start + rm -rf ~/.vim/pack/plugins/start/"${my_pkg_name}" + git clone --depth=1 "${my_repo}" ~/.vim/pack/plugins/start/"${my_pkg_name}" + + if [ ! -f ~/.vimrc ]; then + touch ~/.vimrc + fi + + mkdir -p ~/.vim/plugins + if ! [ -f ~/.vim/plugins/"${my_name}.vim" ]; then + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + curl -fsSL -o ~/.vim/plugins/"${my_name}.vim" "$WEBI_HOST/packages/${my_pkg_name}/${my_name}.vim" + fi + + if ! grep "source.*plugins.${my_name}.vim" -r ~/.vimrc > /dev/null 2> /dev/null; then + set +e + mkdir -p ~/.vim/plugins + printf '\n" %s\n' "${my_note}" >> ~/.vimrc + printf 'source ~/.vim/plugins/%s.vim\n' "${my_name}" >> ~/.vimrc + set -e + echo "" + echo "add ~/.vim/plugins/${my_name}.vim" + echo "updated ~/.vimrc with 'source ~/.vim/plugins/${my_name}.vim'" + fi + + echo "" + echo "${my_installed_msg}" + +); } + +__install_vim_plugin