Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View available snippets for Snipmate (cheatsheet)

Tags:

vim

snipmate

Is there a way to check all available snipMate snippets? Like the i <c-r><tab> does, but with a little more information?

I am curious about:

  • the string that it will complete to.
  • If available the description or comment with the snippet.

Some tool that allows conversion to HTML would be fantastic, but an in-vim trick would be cool too :)

like image 754
berkes Avatar asked Jan 19 '23 00:01

berkes


2 Answers

This may or may not help, but I put together an 'ls_snip' shell script that will list the snippets for various filetypes and any preceding comments. Its not in any way integrated into vim and is dependent on being on a *nix OS. Also, only works for snippets/filetype.snippets files and not snippets/filetype/match.snippets files. You can hack it from here to your liking.

Drop it in ls_snip in some PATH directory, and make it executable.

#! /bin/bash
list_snippets_for() {
  egrep "^snippet|^#" ~/.vim/snippets/$1.snippets | awk '/^#/ {comment = comment $0} /^snippet/ {print $0 "\t\t" comment; comment=""}'
}

if [ "$1" == "" ]
then
  echo "You must specify at least one file type as an argument to ls_snip"
  exit
fi

for filetype in "$@"
do
  echo `echo $filetype | awk '{print toupper($0)}'`
  list_snippets_for $filetype
  echo
done

Here is a sample output

[lwoodson@lwoodson-mint-vb spike] [root@rva-lw] $ ls_snip javascript html
JAVASCRIPT
snippet proto       # Prototype
snippet fun     # Function
snippet f       # Anonymous Function
snippet if      # if
snippet ife     # if ... else
snippet t       # tertiary conditional
snippet switch      # switch
snippet case        # case
snippet for     # for (...) {...}
snippet forr        # for (...) {...} (Improved Native For-Loop)
snippet wh      # while (...) {...}
snippet do      # do...while
snippet :f      # Object Method
snippet timeout     # setTimeout function
snippet get     # Get Elements
snippet gett        # Get Element

HTML
snippet nbs     # Some useful Unicode entities# Non-Breaking Space
snippet left        # ←
snippet right       # →
snippet up      # ↑
snippet down        # ↓
snippet return      # ↩
snippet backtab     # ⇤
snippet tab     # ⇥
snippet shift       # ⇧
snippet control     # ⌃
snippet enter       # ⌅
snippet command     # ⌘
snippet option      # ⌥
snippet delete      # ⌦
snippet backspace       # ⌫
snippet escape      # ⎋
snippet doctype HTML 4.01 Strict        # Generic Doctype
snippet doctype HTML 4.01 Transitional      
snippet doctype HTML 5      
snippet doctype XHTML 1.0 Frameset      
snippet doctype XHTML 1.0 Strict        
snippet doctype XHTML 1.0 Transitional      
snippet doctype XHTML 1.1       
snippet docts       # HTML Doctype 4.01 Strict
snippet doct        # HTML Doctype 4.01 Transitional
snippet doct5       # HTML Doctype 5
snippet docxf       # XHTML Doctype 1.0 Frameset
snippet docxs       # XHTML Doctype 1.0 Strict
snippet docxt       # XHTML Doctype 1.0 Transitional
snippet docx        # XHTML Doctype 1.1
snippet html        
snippet xhtml       
snippet body        
snippet head        
snippet title       
snippet script      
snippet scriptsrc       
snippet style       
snippet base        
snippet r       
snippet div     
snippet movie       # Embed QT Movie
snippet fieldset        
snippet form        
snippet h1      
snippet input       
snippet label       
snippet link        
snippet mailto      
snippet meta        
snippet opt     
snippet optt        
snippet select      
snippet table       
snippet textarea        
snippet fcg     
like image 51
LanceW Avatar answered Jan 21 '23 16:01

LanceW


No.

Frankly, I don't see that option as being terribly useful altogether. For the purpose of snippets is that they're chunks of text that get inserted upon typing a short word, so you don't have to type them in full. They're something you know by heart, just don't want to type over and over again.

They're not code blocks in a way of semi-visual-programming, where you just insert predefined blocks. Which is what you seem to be aiming at.

The easiest way to check out snippets is to go through the snippet files.

like image 45
Rook Avatar answered Jan 21 '23 16:01

Rook