From 67a46b6db8a8abf685580ef8436f3a83ec58f7d2 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Tue, 21 Dec 2021 18:17:51 -0500 Subject: [PATCH] Adding support for vim-snippets and Ultisnips --- .chezmoiexternal.toml | 9 ++++ dot_vim/README.md | 97 ++++++++++++++++++++++++++++++++++++++++++- dot_vim/vimrc | 4 ++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/.chezmoiexternal.toml b/.chezmoiexternal.toml index d900a7a..935a03b 100644 --- a/.chezmoiexternal.toml +++ b/.chezmoiexternal.toml @@ -43,3 +43,12 @@ type = "archive" url = "https://github.com/tpope/vim-surround/archive/master.tar.gz" stripComponents = 1 + +[".vim/pack/git-plugins/start/ultisnips"] + type = "archive" + url = "https://github.com/SirVer/ultisnips/archive/master.tar.gz" + stripComponents = 1 +[".vim/pack/git-plugins/start/vim-snippets"] + type = "archive" + url = "https://github.com/honza/vim-snippets/archive/master.tar.gz" + stripComponents = 1 diff --git a/dot_vim/README.md b/dot_vim/README.md index a2e45e5..86b1b10 100644 --- a/dot_vim/README.md +++ b/dot_vim/README.md @@ -5,7 +5,7 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic ## Table of Contents -* [Snippets](#snippets) +* [Keybinding Shortcuts/Snippets](#keybinding-shortcutssnippets) * [Incrementing a column of numbers](#incrementing-a-column-of-numbers) * [Plugins](#plugins) * [Keybindings](#keybindings) @@ -14,10 +14,15 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic * [Navigation Related](#navigation-related) * [Tabs and Windows Related](#tabs-and-windows-related) * [Misc Related](#misc-related) +* [Snippets](#snippets) + * [Common Snippet Examples](#common-snippet-examples) + * [Go Snippets](#go-snippets) + * [Python Snippets](#python-snippets) + * [Markdown Snippets](#markdown-snippets) -## Snippets +## Keybinding Shortcuts/Snippets ``` # select to end of word/variable and yank <)> # cut everything before ) [eg func(text-to-cut)] @@ -42,6 +47,8 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic * [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 @@ -112,3 +119,89 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic | `` | Reload vimrc file | | | `w!!` | Attempt to sudo and write to file | | + +## Snippets + +Snippets have a few extra things to note: + +* Snippet Leader: `` +* 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`) + + +### 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 | +| `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 | +| `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) | diff --git a/dot_vim/vimrc b/dot_vim/vimrc index 545ed86..17f3e64 100644 --- a/dot_vim/vimrc +++ b/dot_vim/vimrc @@ -95,6 +95,10 @@ vmap a :Tab / endif + " Plugin - Vim Snippets (UltiSnips) + let g:UltiSnipsExpandTrigger="" + let g:UltiSnipsListSnippets="" " list all snippets for current filetype + " Plugin - vim-surround " This allows for surrounding test with something " Note: In the following, [ will add a space around text, ] will not (e.g. [ TEST ] vs [TEST])