font Menlo Bold 32
neocomplcache-snippet-complete -> neosnippet
made by Shougo
- to expand a piece of code
- to jump placeholders
" e.g.
function! #:func_name(<`2`>)
<`0:TARGET`>
endfunction
- only for some specific languages?
- Java
- difficult to remember?
- difficult to learn?
- neocomplcache integration
- unite integration
- you remember snippet -> snippet remembers you
- snippet on demand
hello world in C
- install
- map expand key
- map jump key
NeoBundle 'Shougo/neosnippet'
imap <C-l> <Plug>(neosnippet_expand_or_jump)
smap <C-l> <Plug>(neosnippet_expand_or_jump)
(from :h neosnippet
)
- g:neosnippet#snippets_directory
let g:neosnippet#snippets_directory = '~/.neosnippet/'
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
- filetype snippet
snippet snippet
abbr snippet abbr options <snippet code>
alias snip
options head
snippet ${1:#:trigger}
abbr ${2:#:abbr}
options head
${3:#:TARGET}
- :NeoSnippetEdit -split
- opens a snippet file (with window splitting)
- :Unite snippet
- 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
- "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`>))