Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created November 11, 2012 09:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujihisa/4054220 to your computer and use it in GitHub Desktop.
Save ujihisa/4054220 to your computer and use it in GitHub Desktop.

Vim勉強会#11

Sun Nov 11 JST 2012 尼崎市 小田公民館

公式ハッシュタグ #vim11

ujihisa

Vim勉強会主催者 Vim + Gentoo

Clojure

HootSuite

http://hootsuite.com Scala

neocomplcache

made by Shougo 自動補完

vimshell

(去年の発表)

bashを使うのが許されるのは小学生まで zshを使うのが許されるのは中学生まで

vimshell

:VimShell

<C-n> <C-p>などで履歴

with neocomplcache

ファイル名補完・コマンド名補完など

with unite

<C-l>

iexe

$ iexe irb
:VimShellInteractive irb
  • :VimShellSendBuffer
  • :VimShellSendString

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`>))

end

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