Pro Yearly is on sale from $80 to $50! »

reply.vim

Dea1add99f4cf942792c0f185aa2f2fd?s=47 Linda_pp
February 18, 2019

 reply.vim

@ gorilla.vim #1

Dea1add99f4cf942792c0f185aa2f2fd?s=128

Linda_pp

February 18, 2019
Tweet

Transcript

  1. Reply.vim at gorilla.vim #1

  2. About Me @Linda_pp @rhysd  

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

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

    ͰฤूதͷίʔυΛ෦෼తʹ REPL Ͱ࠶ ར༻͍ͨ࣌͠ɼ෦෼͝ͱʹ Vim ͔Β REPL ʹ ίϐʔ͠ͳ͍ͱ͍͚ͳ͍ • REPL Ͱࢼͨ͠ޙʹ Vim ʹ໭͖ͬͯͨ࣌ʹίʔ υΛଧͪ௚͞ͳ͍ͱ͍͚ͳ͍ • gVim Λ࢖ͬͯΔ࣌ʹࠔΔ  
  5. reply.vim https://github.com/rhysd/reply.vim

  6. reply.vim https://github.com/rhysd/reply.vim Vim ͱ REPL ͷΠϯλϥΫγϣϯΛվળ͢Δϓ ϥάΠϯʢVim 8+ ͱ Neovim

    ྆ରԠʣ ϨϓϦʔͱಡΈ·͢  
  7. reply.vim • :[range]Repl [{name} [{args...}] • {name} Ͱࢦఆͨ͠ REPL Λىಈʢࢦఆ͠ͳ͍ͱ

    filetype ͔Βࣗಈ൑ผʣɽ{args} ΛίϚϯυ࣮ߦʹ௥ ՃͰ͖Δɽ[range] ͷίʔυΛ REPL ։࢝࣌ʹૹ৴ • :ReplStop • REPL Λऴྃ͢Δ • :ReplList • :Repl ͷ {name} Ͱ࢖͑Δ REPL ͷҰཡ • Ϛοϐϯά͸σϑΥϧτͰ͸ແ͠  
  8. :Repl Ͱىಈ͠ɼ:ReplSend ͰςΩετΛςΩετόοϑΝ͔Β REPL ʹ ૹΔ

  9. REPL Ͱ࣮ߦͨ͠ίʔυΛ Vim ͷςΩετόοϑΝʹ :ReplRecv Ͱॻ͖ ग़͢

  10. :ReplAuto ͰςΩετόοϑΝͰฤूதͷίʔυΛࣗಈͰ REPL ʹૹ࣮ͬͯߦ͢Δ ʢexperimentalʣ

  11. reply.vim • REPL ࣗମ͸ :terminal Ͱಈ͔͢ͷͰɼREPL ͷ ิ׬΍ίʔυϋΠϥΠτ͸ͦͷ··࢖͑Δ • σϑΥϧτͰ30Ҏ্ͷݴޠɼ40Ҏ্ͷ

    REPL ʹରԠ • ࣗલͷ REPL Λ௥Ճ͢Δ͜ͱ΋Ͱ͖Δ • vim-themis Ͱ୯ମςετ  
  12. 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 ίϚϯυͷ௥Ճ  
  13. Vim ͱ Neovim ͷλʔϛφϧ ػೳͷࡉ͔͍ҧ͍

  14. Vim ͱ Neovim ͷ :terminal ͸جຊతʹಉ͡ Α͏ʹ࢖͑ɼ࣮૷΋ͲͪΒ΋ libvterm ϕʔε ͕ͩɼ࣮૷ࣗମ͸ผ෺ͷͨΊࡉ͔͍ͱ͜Ζ͕

    ҧ͏  
  15. ΢Οϯυ΢ͷ։͖ํ͕ҧ͏ Vim → ΢Οϯυ΢Λ෼ׂͯ͠৽͍͠λʔϛφϧΛ։ ͘ɽterm_start() ͷҾ਺ʹ౉ࣙ͢ॻͷ term_opencmd Ͱ։͖ํ͕ࢦఆͰ͖Δʢྫɿ'botright sbuffer %d'ʣ

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

    ͱදࣔ͞ΕΔ͕ɼ:term echo 'foo' ͸ 'foo' ͱ දࣔ͞ΕΔ Neovim → γϯάϧΫΥʔτͰ΋μϒϧΫΥʔ τͰ΋ OK  
  17. λʔϛφϧ΁ͷจࣈྻૹ৴ 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"])  
  18. ຤ඌͷۭനߦͷඳըͷ࢓ํ͕ ҧ͏ Vim → getline(1, '$') ͢Δͱ ['echo foo', '',

    '', '', '', ..., ''] ͱ2ߦ໨Ҏ߱ͷۭനߦ΋ೖͬͯ͘Δ Neovim → γ getline(1, '$') ͢Δͱ ['echo foo'] ͷΈͰ຤ඌͷۭനߦ͸ೖͬͯ͜ͳ͍ > echo foo  
  19. ऄ଍ɿ୯ମςετͰ 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