Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created November 6, 2012 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujihisa/4024286 to your computer and use it in GitHub Desktop.
Save ujihisa/4024286 to your computer and use it in GitHub Desktop.

font Menlo Bold 32

neosnippet.vim

neocomplcache-snippet-complete -> neosnippet

made by Shougo

snippet is

  • to expand a piece of code
  • to jump placeholders
" e.g.
function! #:func_name(<`2`>)
  <`0:TARGET`>
endfunction

snippet?

  • only for some specific languages?
    • Java
  • difficult to remember?
  • difficult to learn?

neosnippet revolution

  • neocomplcache integration
  • unite integration
  • you remember snippet -> snippet remembers you
  • snippet on demand

demo1

hello world in C

(minimal) set-up

  • install
  • map expand key
  • map jump key

e.g.

NeoBundle 'Shougo/neosnippet'
imap <C-l>    <Plug>(neosnippet_expand_or_jump)
smap <C-l>    <Plug>(neosnippet_expand_or_jump)

(from :h neosnippet)

conf

  • g:neosnippet#snippets_directory
let g:neosnippet#snippets_directory = '~/.neosnippet/'

snippet file

snippet     function
abbr        func endfunc
alias       func
options     head
    function! ${1:#:func_name}(${2})
        ${0:TARGET}
    endfunction
  • required: snippet and body
  • optional: abbr, alias and options

snippet snippet

  • filetype snippet
snippet     snippet
abbr        snippet abbr options <snippet code>
alias       snip
options     head
    snippet     ${1:#:trigger}
    abbr        ${2:#:abbr}
    options     head
        ${3:#:TARGET}

important commands

  • :NeoSnippetEdit -split
    • opens a snippet file (with window splitting)
  • :Unite snippet

advanced topics

  • uses system snip file to edit
let g:neosnippet#snippets_directory =
\ '~/.vimbundles/neosnippet/autoload/neosnippet/snippets/'

  • backslash to expand only when it's expandable
imap <expr> <Bslash> (pumvisible() && neosnippet#expandable() % 2 == 1) ?
      \ "\<Plug>(neosnippet_expand)" : '\'

  • my key mappings
nnoremap <C-s> :<C-u>Unite snippet<Cr>
imap <C-\> <Plug>(neosnippet_jump)
smap <C-\> <Plug>(neosnippet_jump)
nmap <C-\> a<C-\>

  • automatic snippet expansion on vimshell
imap <buffer><expr> <CR> neosnippet#expandable() ?
  \ "\<Plug>(neosnippet_expand)\<Plug>(vimshell_enter)" : "\<Plug>(vimshell_enter)"

demo

  • note for automatic snippet expansion

  • global settings

    • date, date_full, date_day, and date_time
  • disable them

neosnippet life

  • "ruby's url-encoding is hard to remember"
require 'erb'
puts ERB::Util.url_encode ''

  • clojure's ref-set
(dosync
  (ref-set ref <`2:value`>))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment