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

Vim and Ruby

Avatar for pocke pocke
December 09, 2017

Vim and Ruby

Rails Developers Meetup 2017(飛び込みLT)

Avatar for pocke

pocke

December 09, 2017
Tweet

More Decks by pocke

Other Decks in Programming

Transcript

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

    RuboCop's core developer • RuboCop-JP Organizer ← New
  2. 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.
  3. 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
  4. Inline Ruby script " In .vimrc ruby << RUBY def

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

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

    ├── foo.vim └── foo.vim.rb
  7. 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"'
  8. Vim → Ruby # In a ruby script source =

    Vim.evaluate("getbufline('.', 1, '$')") .join("\n") puts source # editing source code is printed
  9. 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
  10. 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.
  11. 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
  12. 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