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

Vim and Ruby

7bc6612fa20296bf652f6b0357db81c1?s=47 pocke
December 09, 2017

Vim and Ruby

Rails Developers Meetup 2017(飛び込みLT)

7bc6612fa20296bf652f6b0357db81c1?s=128

pocke

December 09, 2017
Tweet

Transcript

  1. Vim and Ruby Rails Developers Meetup 2017(LT) Dec. 9, 2017

  2. $ cat /path/to/pocke • Masataka Kuwabara (Pocke) • SideCI •

    RuboCop's core developer • RuboCop-JP Organizer ← New
  3. None
  4. Vim and Ruby

  5. Q. attendees.use?(Vim)

  6. OK, everyone uses Vim!

  7. Vim Plugins • We can get more powerful Vim with

    plugins. ◦ Plugin examples: vim-rails (I don't use it), Denite.nvim, NeoSnippet, … • Vim plug-ins are written in Vim script. ◦ And, many "dark-powered" Vim plug-ins are written in Python.
  8. Vim script and Python...

  9. You can write Vim plugins in Ruby

  10. Vim Ruby • We can write Vim plugins in native

    language. • We can use gems e.g.) ActiveSupport • We can use Ruby's powerful standard libraries ◦ https://docs.ruby-lang.org/ja/latest/class/String.html • See more information → :help ruby ◦ http://vim-jp.org/vimdoc-ja/if_ruby.html
  11. How to write ruby code

  12. Inline Ruby script " In .vimrc ruby << RUBY def

    hello(name) puts "Hello, #{name}!" end hello("pocke") RUBY ruby hello('pocke') "It prints Hello, pocke!
  13. Inline Ruby script " In .vimrc ruby << RUBY def

    hello(name) puts "Hello, #{name}!" end hello("pocke") RUBY ruby hello('pocke') "It prints Hello, pocke!
  14. Load a ruby file from Vim script $ tree autoload/

    ├── foo.vim └── foo.vim.rb
  15. Load a ruby file from Vim script " In foo.vim,

    it loads foo.vim.rb let s:self_path = expand("<sfile>") execute 'ruby require "' . \ s:self_path . '.rb"'
  16. How to communicate with Vim and Ruby

  17. Vim → Ruby # In a ruby script source =

    Vim.evaluate("getbufline('.', 1, '$')") .join("\n") puts source # editing source code is printed
  18. Ruby → Vim(I think it is a workaround...) # In

    Ruby script, serialize the result, # and assign Vim script's variable Vim.command "let s:result = #{res.to_json}" " In Vim script echo s:result
  19. Vim plugins written in Ruby In the real world

  20. github.com/pocke/iro.vim

  21. Iro.vim • A new syntax highlighter for Ruby, YAML, and

    Python (Python support is experimental). • Use parser to highlight instead of regular expression. ◦ Ripper, Psych, ... • It highlights perfectly.
  22. Iro.vim • See my slide also: "The new syntax highlighter

    for vim." in VimConf 2017 ◦ https://speakerdeck.com/pocke/the-new-syntax-highl ighter-for-vim
  23. github.com/pocke/ yaml-path.vim

  24. YAML-Path.vim • Display a path of YAML. • It uses

    Psych to parse a YAML code.
  25. None
  26. Conclusion

  27. Conclusion • We can write Vim plugins in Ruby •

    You can find examples, iro.vim and yaml-path.vim. • Maybe it is helpful for Rails. Thank you for listening! Follow me Twitter: @p_ck_ GitHub: @pocke