All Projects → andreyorst → SimpleSnippets.vim

andreyorst / SimpleSnippets.vim

Licence: GPL-3.0 license
Simple snippet support for your Vim and Neovim

Programming Languages

Vim Script
2826 projects
shell
77523 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to SimpleSnippets.vim

Vim Vsnip
Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
Stars: ✭ 224 (+160.47%)
Mutual labels:  snippets, vim-plugin, neovim-plugin
skim.vim
vim support for skim
Stars: ✭ 127 (+47.67%)
Mutual labels:  vim-plugin, neovim-plugin
bolt.nvim
⚡ Ultrafast multi-pane file manager for Neovim with fuzzy matching
Stars: ✭ 100 (+16.28%)
Mutual labels:  vim-plugin, neovim-plugin
code runner.nvim
Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
Stars: ✭ 234 (+172.09%)
Mutual labels:  vim-plugin, neovim-plugin
vim-readme-viewer
📖 Viewing plugin's README easily like vim help
Stars: ✭ 26 (-69.77%)
Mutual labels:  vim-plugin, neovim-plugin
miniSnip
Lightweight snippet plugin for Vim
Stars: ✭ 45 (-47.67%)
Mutual labels:  snippets, vim-plugin
vim-lineletters
because letters are easier to touch type than numbers
Stars: ✭ 38 (-55.81%)
Mutual labels:  vim-plugin, neovim-plugin
denops-docker.vim
Manage Docker in Vim/Neovim
Stars: ✭ 48 (-44.19%)
Mutual labels:  vim-plugin, neovim-plugin
vim-counterpoint
Cycle between file counterparts in vim or neovim.
Stars: ✭ 12 (-86.05%)
Mutual labels:  vim-plugin, neovim-plugin
42header.vim
Add and update the 42 comment header at the top of your files
Stars: ✭ 15 (-82.56%)
Mutual labels:  vim-plugin, neovim-plugin
pipet
Personal snippet manager, store bits of text.
Stars: ✭ 21 (-75.58%)
Mutual labels:  snippets, snippet-manager
denops-gh.vim
Vim/Neovim plugin for GitHub
Stars: ✭ 27 (-68.6%)
Mutual labels:  vim-plugin, neovim-plugin
qf helper.nvim
A collection of improvements for the quickfix buffer
Stars: ✭ 70 (-18.6%)
Mutual labels:  vim-plugin, neovim-plugin
stable-windows
Keeps vim windows stable on layout changes
Stars: ✭ 41 (-52.33%)
Mutual labels:  vim-plugin, neovim-plugin
vim-snipp-snapp-snut-and-the-legend-continues
💇 (Experimental) Vim snippet plugin
Stars: ✭ 24 (-72.09%)
Mutual labels:  snippets, vim-plugin
beacon.nvim
Whenever cursor jumps some distance or moves between windows, it will flash so you can see where it is
Stars: ✭ 217 (+152.33%)
Mutual labels:  vim-plugin, neovim-plugin
snippets.nvim
No description or website provided.
Stars: ✭ 30 (-65.12%)
Mutual labels:  snippets, neovim-plugin
Ncm R
R autocompletion for Neovim and vim 8 📝 📊 ⚡️
Stars: ✭ 102 (+18.6%)
Mutual labels:  snippets, vim-plugin
auto-pairs
Vim plugin, insert or delete brackets, parentheses, and quotes in pairs
Stars: ✭ 109 (+26.74%)
Mutual labels:  vim-plugin, neovim-plugin
vim-tips-wiki
1500+ tips downloaded from Vim Tips Wiki, parsed and formatted to look and work like native Vim help files
Stars: ✭ 56 (-34.88%)
Mutual labels:  vim-plugin, neovim-plugin

SimpleSnippets.vim

GitHub release GitHub Release Date Github commits (since latest release) license

Simple snippets is a fast, lightweight, and simple snippet manager for Vim and NeoVim based on standard editor features. It integrates with Deoplete to provide available snippets in popup menu and provides basic support of snippet feature to Vim.

simplesnippets

This plugin was inspired by other snippet managers, like UltiSnips, snipMate, Neosnippets, etc. However, it has major differences in implementation, and features it provides.

Installation

Assuming you are using Vundle, place this in your .vimrc:

Plugin 'andreyorst/SimpleSnippets.vim'

Then run the following in Vim:

:source %
:PluginInstall

You're ready to use SimpleSnippets. However SimpleSnippets.vim doesn't come with snippets within it. Snippets can be installed with SimpleSnippets-snippets plugin. It's not full featured collections of snippets for now, but I will extend it over time. Help is always appreciated.

If you want to redefine keys, consider adding this:

let g:SimpleSnippetsExpandOrJumpTrigger = "<Tab>"
let g:SimpleSnippetsJumpBackwardTrigger = "<S-Tab>"
let g:SimpleSnippetsJumpToLastTrigger = "<C-j>"

to your .vimrc or init.vim. If you want to disable default mappings, to write your own using functions, append let g:SimpleSnippets_dont_remap_tab = 1 to those settings. For other settings please read the documentation.

If you want a horizontal split while editing a snippet, instead of vertical one, add let g:SimpleSnippets_split_horizontal = 1 to your .vimrc or init.vim.

Plugin was created and being maintained by @andreyorst. It is being tested against Vim 8.0, Vim 7.4.1689 and NeoVim 0.3.0. Other versions are not officially supported, but might work. If you found an issue, or want to propose a change, you're welcome to do so at SimpleSnippets.vim GitHub repository: https://github.com/andreyorst/SimpleSnippets.vim

Syntax

SimpleSnippets supports these kinds of placeholders:

  • ${1:text} - normal placeholder
    Normal placeholder's body must be some unique text, which will be later searched over the snippet's body, and selected.
  • ${2:text} $2 - mirroring
    For the mirroring Simplesnippets uses the same syntax as most of other plugins, however mirroring of empty tabstops is not possible. Mirroring is also non-realtime.
  • ${3|option1, option2|} - choice placeholder
    Choice placeholder lets you choose the candidate, or write your own instead.
  • ${4!echo "shell or viml"} - command placeholder
    Command placeholder can execute shell, or vimscript commands, which can be echoed.

For the information about missing types of placeholders please check limitations section

Why?

Back in the days I didn't use snippets at all. Because, I thought, that I don't need them at all. The idea was that it is not that big difference in time spent on typing everything by hands, and I was lazy to figure out how to setup and use snippet managers.

But then I've watched this amazing talk about how to do most of your things without plugins. I was inspired with snippets, that can be created with abbreviations, and I've started experimenting.

First approach was something like this:

iabbr class/ <Esc>:-1read $HOME/.vim/snippets/class<CR><Esc>/_Class_Name_<CR>:noh<CR>:%s//g<left><left>

Which read my file with class template to current file, and started a substitute command, where I was able to define class name. But then I needed to go to class body by myself, but even so, I've noticed how easer it to type single word, expand it and then just edit the rest.

Days passed, I've defined bunch of this abbreviations. It was very fun to create this abbreviations, and confuse people with such "magic" ones:

autocmd FileType cpp,h,hpp nnoremap <F3> <Esc>0:set nohlsearch<CR>/;<CR>y^?private<CR>:-1read $HOME/.vim/snippets/getSet.cpp<CR>0Pa()<Esc>bbyw~hiobtain<Esc>/;<CR>P:noh<CR>==j0==/)<CR>bPnbb~hiestablish<Esc>nPnb~/ =<CR>P/;<CR>Pnb~?obtain<CR>y^j/(<CR>p^:set hlsearch<CR>:noh<CR>

(which generates getter and setter methods for current private variable under cursor in current class)

I've even made some placeholder support with mappings, so I could jump to snippet body and edit things:

inoremap <silent><c-j> <Esc>:set nohlsearch<Cr>/\v\$\{[0-9]+:.*\}<Cr>msdf:f}:set hlsearch<Cr>:noh<Cr>i<Del><Esc>me`sv`e<c-g>
nnoremap <silent><c-j> <Esc>:set nohlsearch<Cr>/\v\$\{[0-9]+:.*\}<Cr>msdf:f}:set hlsearch<Cr>:noh<Cr>i<Del><Esc>me`sv`e<c-g>

I highly recommend you go through this yourselves, as it boosts your Vim's movement knowledge beyond the limitations of any emacs user. But again, I decided to try snippet managers. I've tried many, and sticked with Ultisnips. It is great plugin, and I highly recommend you use it, if you're using Vim (ultisnips works in NeoVim too, but it is not supported officially), and you have rather powerful machine, because ultisnips requires some resources, wich in my case was performance killer on my GPD Pocket, and Nexus 5x (yes I use NeoVim on my smartphone a lot).

So I've decided to try other plugins, but some of them were poor for functional, some were even slower, and some lacked functions to use in my mappings.

I like the idea of single key for multiple things, wich is my case is Tab. I use Tab to scroll through auto completion popup, provided by Deoplete, to expand snippets, provided by UltiSnips, and to jump between placeholders in the snippet body. I wasn't able to setup snipMate to such configuration, and it still was not that fast as I needed, and It needs two extra plugins, so I've decided:

If I was able to use such abbreviation snippets for a long time, maybe I should just create a snippet manager for them?

Bang! The first thing I thought of is to create function that will parse my snippet, remove placeholder markers, and somehow let me jump on them. Some days after, I've started working on this plugin and here it is.

But!

You may think that there are already plenty of other snippet managers, and you may noticed that I've said, that I've made it with just Vim's native features, wich means that it should have lot of limitations, and will have even poorer functional then other plugins?

The answer is... Yes. It has some limitations, and far less functions, than other snippet managers. It's main feature is speed. It provides basic snippet support to Vim. Which means that you can expand, jump, mirror, use shell commands, and there is even a small interface which other plugins can use to integrate with SimpleSnippets.

I may extend the functionality of this plugin in the future, if I figure out how, to implement things in better way, without using third party plugins, or other languages.

List Of Limitations / design flaws

Here I'll try to list all limitations that you may encounter when using Simple Snippets:

  • No tabstops.
    Why? Well, jumping is based on text searching. Because placeholders are deleted from snippet body when it is pasted to your file there is no way to find empty ones, because text behind them for example may change. If NeoVim will add ability to use multicursor and position it in text like in other modern editors this may be implemented. Because of this limitation mirroring is done differently too.
  • Normal placeholders should contain per snippet unique bodies.
    So you can't use ${2:text_a} ${0:text_b} ${1:text_a} constructions. SimpleSnippets will jump to first match of text_a in snippet body. This is major limitation.
  • Jumping is based on searching for a string.
    As was already said before. So if you replace some part of snippets in the same way, how your next placeholder is defined, you may jump to it instead of that placeholder.
  • Single snippet editing at time.
    If you expanded a snippet, and you try to expand snippet inside this one, you will lose ability to jump in your previous snippet.
  • No nested placeholders.
  • There may be more, which I've not thought about.

Withdrawn limitations:

  • Every snippet must contain zero indexed placeholder, aka ${0:text}
  • Command placeholders, that output is more then single line can't be jumped.
  • Trigger must be separated from everything
  • No back jumping.
  • Placeholders must be separated from each other and another text.
  • Placeholders have slightly different syntax than other plugins use.

After reading this list you may want to ask me this question:

Why would I even may want to use it?

You probably won't! I understand this, because I've developed it for myself in first place, and I can obey these restrictions and limitations because I need simple snippets and fast plugin for them. I know that having an advanced, full-featured, complex solution is great, because of powers, that you gain form it. However often too powerful tool need a powerful hardware to run smoothly. If you feel that other snippet solutions are making your Vim slow, then you probably may want to use it.

This plugin is fast. It is lightweight, and can be used on phones, netbooks, slow PCs, via ssh, and maybe in more cases, which I've not thought about for now. And there was a reason to call it SimpleSnippets, you know.

If after reading this you still want to try it out, you re welcome to! This plugin is not that bad, however you may think of it. Please read the documentation provided with the plugins to understand how things work. If you encounter any problem feel free to file an Issue

Some SimpleSnippets action gifs

Deoplete completion popup

compmenu

Adding a snippet:

adding a snippet

Adding a Flash snippet:

adding flash snippet

Shell and plain text snippets:

shell and plain text viml and shell

Jumping back and forth

backjumping

Choice placeholders

choice

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].