Upgrade to Pro — share decks privately, control downloads, hide ads and more …

reply.vim

Avatar for Linda_pp Linda_pp
February 18, 2019

 reply.vim

@ gorilla.vim #1

Avatar for Linda_pp

Linda_pp

February 18, 2019
Tweet

More Decks by Linda_pp

Other Decks in Technology

Transcript

  1. REPL (Read Eval Print Loop) ࢖ͬͯ·͔͢ʁ node, python, ghci, swift

    -repl, bash, iex, irb, clojure,... API ΍ݴޠػೳΛͪΐͬͱ֬ೝ͢Δ࣌ʹͨ͠ ͍ͱ͖ʹศར  
  2. ୺຤ Vim + Tmux Ͱ REPL Λ࢖ͬ ͍ͯͨ࣌ͷ໰୊఺ • Vim

    ͰฤूதͷίʔυΛ෦෼తʹ REPL Ͱ࠶ ར༻͍ͨ࣌͠ɼ෦෼͝ͱʹ Vim ͔Β REPL ʹ ίϐʔ͠ͳ͍ͱ͍͚ͳ͍ • REPL Ͱࢼͨ͠ޙʹ Vim ʹ໭͖ͬͯͨ࣌ʹίʔ υΛଧͪ௚͞ͳ͍ͱ͍͚ͳ͍ • gVim Λ࢖ͬͯΔ࣌ʹࠔΔ  
  3. reply.vim • :[range]Repl [{name} [{args...}] • {name} Ͱࢦఆͨ͠ REPL Λىಈʢࢦఆ͠ͳ͍ͱ

    filetype ͔Βࣗಈ൑ผʣɽ{args} ΛίϚϯυ࣮ߦʹ௥ ՃͰ͖Δɽ[range] ͷίʔυΛ REPL ։࢝࣌ʹૹ৴ • :ReplStop • REPL Λऴྃ͢Δ • :ReplList • :Repl ͷ {name} Ͱ࢖͑Δ REPL ͷҰཡ • Ϛοϐϯά͸σϑΥϧτͰ͸ແ͠  
  4. REPL ͷΧελϚΠζ filetype ͝ͱʹىಈ͢Δ REPL ͷΧελϚΠζ͕Ͱ͖ ΔɽREPL ໊Ͱ͸ͳ͘ Funcref Λ༩͑Δͱɼࣗલͷ

    REPL ΛఆٛͰ͖Δ let g:reply_repls = { \ 'python': ['python3'], \ 'scheme': ['mit_scheme', 'gauche'], \ 'javascript': ['ts_node'], \ 'text': [ \ {-> reply#repl#base('mycalc', { \ 'prompt_start' : '^calc> ', \ 'prompt_continue' : v:null, \ })} \ ], \ } ྫɿ 'calc> ' ͱ͍͏ϓϩϯϓτΛग़͢ mycalc ͱ͍͏ REPL ίϚϯυͷ௥Ճ  
  5. ΢Οϯυ΢ͷ։͖ํ͕ҧ͏ Vim → ΢Οϯυ΢Λ෼ׂͯ͠৽͍͠λʔϛφϧΛ։ ͘ɽterm_start() ͷҾ਺ʹ౉ࣙ͢ॻͷ term_opencmd Ͱ։͖ํ͕ࢦఆͰ͖Δʢྫɿ'botright sbuffer %d'ʣ

    Neovim → ΢Οϯυ΢Λ෼ׂͤͣ։͘ɽ෼ׂ͍ͨ͠ ৔߹͸ࣄલʹ޷͖ͳํ๏Ͱ෼ׂ͔ͯ͠Β։͘ ʢྫɿ:vsplit | termʣ  
  6. :terminal ͷҾ਺ͷΫΥʔτ Vim → γϯάϧΫΥʔτ͸ͦͷ··λʔϛφϧ ʹ౉ͯ͠͠·͏ɽྫ͑͹ɼ:term echo "foo" ͸ foo

    ͱදࣔ͞ΕΔ͕ɼ:term echo 'foo' ͸ 'foo' ͱ දࣔ͞ΕΔ Neovim → γϯάϧΫΥʔτͰ΋μϒϧΫΥʔ τͰ΋ OK  
  7. λʔϛφϧ΁ͷจࣈྻૹ৴ Vim → γઐ༻ͷؔ਺ term_sendkeys() Λ࢖͏ɽ୺຤δϣϒϞʔ υͰͳ͍ͱಈ͔ͳ͍ͷͰ஫ҙ Neovim → ୺຤όοϑΝͷ

    &l:channel Φϓγϣϯʹ channel ID ͕ೖ͍ͬͯΔͷͰɼͦΕΛ࢖ͬͯ jobsend() Ͱૹ৴͢Δ " ·ͣ͸୺຤΢Οϯυ΢ʹҠಈ 1wincmd " ୺຤δϣϒϞʔυʹೖΔ normal! i " จࣈྻૹ৴ call term_sendkeys(bufnr, "echo hello\n") call jobsend(getbufvar(bufnr, '&channel'), ["echo hello\n"])  
  8. ຤ඌͷۭനߦͷඳըͷ࢓ํ͕ ҧ͏ Vim → getline(1, '$') ͢Δͱ ['echo foo', '',

    '', '', '', ..., ''] ͱ2ߦ໨Ҏ߱ͷۭനߦ΋ೖͬͯ͘Δ Neovim → γ getline(1, '$') ͢Δͱ ['echo foo'] ͷΈͰ຤ඌͷۭനߦ͸ೖͬͯ͜ͳ͍ > echo foo  
  9. ऄ଍ɿ୯ମςετͰ Vim ͱ Neovim ͷλʔϛ φϧύϑΥʔϚϯεൺֱ > time ./vim-themis/bin/themis test/

    >/dev/null 2>&1 ./vim-themis/bin/themis test/ > /dev/null 2>&1 0.97s user 0.24s system 12% cpu 9.330 total > time THEMIS_VIM=nvim ./vim-themis/bin/themis test/ >/dev/null 2>&1 THEMIS_VIM=nvim ./vim-themis/bin/themis test/ > /dev/null 2>&1 2.17s user 0.04s system 82% cpu 2.662 total • iMac 2015 Late (core i7) • Vim 8.1 873 • Neovim 0.3.4