# VIM Note: Some features require version 8+ of vim. For instance, the ALE plugin which utilizes the built-in `~/.vim/pack/` for autoloading plugins ## Table of Contents * [Keybinding Shortcuts/Snippets](#keybinding-shortcutssnippets) * [Incrementing a column of numbers](#incrementing-a-column-of-numbers) * [Plugins](#plugins) * [Keybindings](#keybindings) * [Display Related](#display-related) * [Formatting Related](#formatting-related) * [Navigation Related](#navigation-related) * [Tabs and Windows Related](#tabs-and-windows-related) * [Misc Related](#misc-related) * [Snippets](#snippets) * [Adding/Editing Custom Snippets](#addingediting-custom-snippets) * [Common Snippet Examples](#common-snippet-examples) * [Go Snippets](#go-snippets) * [Python Snippets](#python-snippets) * [Markdown Snippets](#markdown-snippets) ## Keybinding Shortcuts/Snippets ``` # select to end of word/variable and yank <)> # cut everything before ) [eg func(text-to-cut)] ,gq # Select and wrap current line ``` ### Incrementing a column of numbers ``` # Select all number columns to increment # If using tmux config, may need to hit a twice (e.g. ``` ## Plugins Plugins are managed using [vim-plug](https://github.com/junegunn/vim-plug). `vim-plug` is downloaded automatically on first run. To update the plugins, run `PlugInstall` Below is a list of currently installed plugins: * ~~[Easymotion](https://github.com/easymotion/vim-easymotion) - Easily navigate documents~~ Disabled recently as unused, although useful * [Gruvbox](https://github.com/morhetz/gruvbox) - Retro colorscheme (colorscheme in vimrc) * ~~[Matchit](https://github.com/adelarsq/vim-matchit) - For expanding % matching (matches start/end tags for html, for example)~~ Disabled recently as possibly unused * [Lightline](https://github.com/itchyny/lightline.vim) - Configurable statusline/tabline * [Markdown TOC](https://github.com/mzlogin/vim-markdown-toc) - A markdown Table of Contents generator * [NERDCommenter](https://github.com/preservim/nerdcommenter) - Quick commenting/uncommenting of lines * [NERDTree](https://github.com/scrooloose/nerdtree) - Local file explorer * [python-syntax](https://github.com/vim-python/python-syntax) - Better syntax highlighting for python * [Tabular](https://github.com/godlygeek/tabular/) - Easily align text based on delimeters (e.g. |) * [surround.vim](https://github.com/tpope/vim-surround) - Easily surround with delimeters (e.g. "Something") * [IndentLines](https://github.com/Yggdroot/indentLine) - View the indentations (`i`) * ~~[vim-rainbow](https://github.com/frazrepo/vim-rainbow.git) - Different colors for different levels of brackets~~ Disabled as interfers with spellcheck for some reason * [UltiSnips](https://github.com/SirVer/ultisnips) - Snippets manager for vim * [vim-snippets](https://github.com/honza/vim-snippets) - Snippets for various languages ## Keybindings **Leader Key:** `,` (comma) ### Display Related | Shortcut | Description | Plugin | | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------- | | `` | Toggle wordwrap | | | `bg` | Toggle dark/light background | | | `h` | Disable search highlight | | | `f<0-9>` | Set foldlevel (0-9) | | | `i` | Toggle indent guides | IndentLines | | `sp` | Toggle spellchecking (us-en) | | ### Formatting Related | Shortcut | Description | Plugin | | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------- | | `-` | Comment out selected lines (filetype needs to be configured in vimrc for support) | NERDcommenter | | `_` | Uncomment selected lines (filetype needs to be configured in vimrc for support) | NERDcommenter | | `` | Remove trailing whitespace from file | | | `a` | Accept various common delimiters for tabulizing blocks of code (e.g. `varname = something`, = being the delimiter) | Tabular | | `d` | Add delimiters around entire line (normal mode) or selection (visual mode) | vim-surround | | `fj` | Pretty print json using jq (current open file) | | | `D` | Add delimiters around current word (normal mode) | vim-surround | | `q` | Format a paragraph/line to better fit the textwidth | | | `p` | Toggle paste mode | | | `S)` | Add delimiters current selection | vim-surround | | `cs` | Replace a character with anothere charcter (e.g. `cs"'`, or `cs'

`) | vim-surround | | `ds` | Remove a delimiter | vim-surround | | `ysiw]` | Add delimiters around current word | vim-surround | | `yss)` | Add delimiters around entire line | vim-surround | ### Navigation Related | Shortcut | Description | Plugin | | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------- | | `%` | Find the end {}, [], or start/end tags (e.g. html) | Base, Matchit | | `*` | Highlight all occurences of word under cursor (default in vim) | | | `ff` | Display all occurences of word under cursor | | | `cwd` | Change working dirctory to current file's | | | `n` | Toggle NERDTree | NERDTree | | `j` | Move to next linting error | ALE | | `k` | Move to previous linting error | ALE | ### Tabs and Windows Related | Shortcut | Description | Plugin | | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------- | | `sh` | Split horizontally | | | `sv` | Split vertically | | | `t` | Tab Next | | | `T` | Tab Previous | | | `w` | cycle through split windows | | | `<+>` | Resize horizontal pane (3/2) | | | `<->` | Resize horizontal pane (2/3) | | | `<<>` | Resize vertical pane (3/2) | | | `<>>` | Resize vertical pane (2/3) | | ### Misc Related | Shortcut | Description | Plugin | | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------- | | `` | Reload vimrc file | | | `w!!` | Attempt to sudo and write to file | | ## Snippets Snippets have a few extra things to note: * Snippet Leader: `` (e.g. `class`) * List Snippets: `` * Forward Through Snippet: `` * Backward Through Snippet: `` You run the snippet completion while in insert mode. A simple example: Type `#!` automatically inserts `#!/usr/bin/env python` A more in depth example: 1. `class` 2. Start typing to provide name of class (already selected) 3. `` to move to the parent class (`class MyObject():`) 4. `` to move to docstring 5. `` to move to inputs of the `__init__` function (typing a new input name automatically adds `self._varname = varname`) ### Adding/Editing Custom Snippets You can edit the snippets for the current filetype that's open by using `:UltiSnipsEdit` After making any changes to the snippets, run `:call UltiSnips#RefreshSnippets()` to refresh the snippets **Important Note**: If using chezmoi, make sure to copy the snippet to the chezmoi repo so it isn't overwritten during next `chezmoi apply` ### Common Snippet Examples These are taken from [this article](https://bhupesh-v.github.io/learn-how-to-use-code-snippets-vim-cowboy/). #### Go Snippets [All Go snippets](https://github.com/honza/vim-snippets/blob/master/snippets/go.snippets). Also, see Ultisnips specific [snippets](https://github.com/honza/vim-snippets/blob/master/UltiSnips/go.snippets) | Snippet Trigger | Description | | --------------- | ----------- | | `fun` | Go function | | `fum` | Go Method | | `for` | Infinite for loop | | `forr` | Range based for loop | | `err` | Go Basic Error Handling | | `im` | Import Packages | | `pf` | fmt.Printf(…) | | `pl` | fmt.Println(…) | | `ps` | fmt.Sprintf(…) | | `om` | if key in map | | `if` | Go basic if statement | | `ife` | Go basic if/else statement | | `sw` | Switch statement | | `sl` | Go select for channels | | `ga` | goroutine anonymous function | | `test` | Go Test function | | `testt` | Go Table test function | #### Python Snippets [All python snippets](https://github.com/honza/vim-snippets/blob/master/snippets/python.snippets). Also see Ultisnips specific [snippets](https://github.com/honza/vim-snippets/blob/master/UltiSnips/python.snippets) | Snippet Trigger | Description | | --------------- | ----------- | | `cl` | New Python class | | `dataclass` | Create a dataclass (**Custom**) | | `def` | New Python function definition | | `adef` | Python Async function definition | | `err` | Go Basic Error Handling | | `try` | Try/Except Block | | `trye` | Try/Except/Else Block | | `tryf` | Try/Except/Finally Block | | `tryef` | Try/Except/Else/Finally Block | | `"` | Python docstring | | `if` | Python basic if statement | | `el` | Python basic else statement | | `for` | Range based for loop | | `forkey` | Enumerate using key value of an interable (**Custom**) | | `lcp` | List comprehension | #### Markdown Snippets [All shell snippets](https://github.com/honza/vim-snippets/blob/master/snippets/markdown.snippets). Also, see Ultisnips specific [snippets](https://github.com/honza/vim-snippets/blob/master/UltiSnips/markdown.snippets) | Snippet Trigger | Description | | --------------- | ----------- | | `*` | Italics text | | `**` | Bold text | | `/*` | Markdown/HTML Comment | | `cbl` | Code block | | `link or [` | Markdown link | | `img or ![` | Markdown image | | `tb` | Markdown Table | | `tbN,M` | Responsive Table
(tb12 creates a table with 1 row & 2 columns) |