Skip to content

Instantly share code, notes, and snippets.

@lgalke
Last active February 25, 2017 15:08
Show Gist options
  • Save lgalke/a65bf89418073c6be4c633435f829f81 to your computer and use it in GitHub Desktop.
Save lgalke/a65bf89418073c6be4c633435f829f81 to your computer and use it in GitHub Desktop.
Snippets in a single VimL line instead of plugin
" Snippets (or reanimating skeletons) in plain vim which just uses ONE LINE OF CODE:
" The following is one single abbreviation for all:
" The graveyard.
" - Visual selection -> :w\g/<filename> will create a grave
" - Reanimating a skeleton by -> :r\g/<filename>
" Of course you can get a list of your skeletons by hitting <tab> instead of writing a filename (wildmenu).
" Or hit *.py<Tab> to get a list of only python snippets.
" - Editing a skeleton... -> :e\g/<filename>
cabbrev \g $HOME/.vim/graveyard
" That's it. Of course you can get a little more crazy by putting markers on your skeletons for later replacement:
" In case you have surround of the pope installed:
let g:surround_{char2nr('m')} = "<++\r++>"
" Or if you want to be independent, just iabbrev or whatever you desire
iabbrev +++ <++++><Left><Left><Left>
" Along with a mapping for finding your runes, erm..: markers.
nnoremap <leader>m /<++.*++>/<CR>
" After initiiating the search, navigate through them via n/N as usual.
" If you want to replace one of them: just hit gn<C-G> and start typing.
" It's all inside vim already, no additional maps needed.
" Okay if you want to quicken up the reanimating a little:
set wildcharm = <c-z>
nnoremap <Leader>r :r $HOME/.vim/graveyard/*<c-z>
" which opens up the candidate list immedtiately and even filters for current extension matches.
" Round up:
" - Good for rather large skeletons
" - Good for quickly saving your very personal skeletons by just entombing (writing) them in your graveyard.
" e.g. that tex template for acm style you are always using, or that sklearn estimator skeleton
" - A little too cumbersome for small snippets like def, but hey you can just use iabbrevs for that.
" This should not prevent you from using your favorite snippet engine,
" but rather encourage you to just write and read some often used bigger skeletons in your very personal graveyard.
" This is necromancy. In plain vim.
@lgalke
Copy link
Author

lgalke commented Feb 25, 2017

Inspired by a talk from @mcantor, which made me finally get rid of the snippet engines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment