From 6b4020f3a06db6068d33c88d93dbf0a1e28beaef Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Wed, 22 Dec 2021 08:51:05 -0500 Subject: [PATCH] Updating custom UltiSnips --- dot_vim/README.md | 12 +++++++++++- dot_vim/UltiSnips/python.snippets | 4 ++++ dot_vim/vimrc | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 dot_vim/UltiSnips/python.snippets diff --git a/dot_vim/README.md b/dot_vim/README.md index 86b1b10..244390b 100644 --- a/dot_vim/README.md +++ b/dot_vim/README.md @@ -15,6 +15,7 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic * [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) @@ -124,7 +125,7 @@ Note: Some features require version 8+ of vim. For instance, the ALE plugin whic Snippets have a few extra things to note: -* Snippet Leader: `` +* Snippet Leader: `` (e.g. `class`) * List Snippets: `` * Forward Through Snippet: `` * Backward Through Snippet: `` @@ -141,10 +142,18 @@ A more in depth example: 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` + +**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) @@ -188,6 +197,7 @@ These are taken from [this article](https://bhupesh-v.github.io/learn-how-to-use | `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 | diff --git a/dot_vim/UltiSnips/python.snippets b/dot_vim/UltiSnips/python.snippets new file mode 100644 index 0000000..b517867 --- /dev/null +++ b/dot_vim/UltiSnips/python.snippets @@ -0,0 +1,4 @@ +snippet forkey "Enumerate an iterable for key/value pair" +for ${1:key}, ${2:value} in enumerate(${3}): + pass +endsnippet diff --git a/dot_vim/vimrc b/dot_vim/vimrc index 47ee8f4..8379426 100644 --- a/dot_vim/vimrc +++ b/dot_vim/vimrc @@ -96,7 +96,7 @@ endif " Plugin - Vim Snippets (UltiSnips) - let g:UltiSnipsSnippetDirectories=["UltiSnips", $HOME.'/.vim/snippets/'] " Add custom snippets + let g:UltiSnipsSnippetDirectories=["~/.vim/UltiSnips/", "UltiSnips"] " Add custom snippets let g:UltiSnipsExpandTrigger="" let g:UltiSnipsListSnippets="" " list all snippets for current filetype let g:UltiSnipsJumpForwardTrigger=""