Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

$ cat /path/to/pocke ● Masataka Kuwabara (Pocke) ● SideCI ● RuboCop's core developer ● RuboCop-JP Organizer ← New

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Vim and Ruby

Slide 5

Slide 5 text

Q. attendees.use?(Vim)

Slide 6

Slide 6 text

OK, everyone uses Vim!

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

Vim script and Python...

Slide 9

Slide 9 text

You can write Vim plugins in Ruby

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

How to write ruby code

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Load a ruby file from Vim script $ tree autoload/ ├── foo.vim └── foo.vim.rb

Slide 15

Slide 15 text

Load a ruby file from Vim script " In foo.vim, it loads foo.vim.rb let s:self_path = expand("") execute 'ruby require "' . \ s:self_path . '.rb"'

Slide 16

Slide 16 text

How to communicate with Vim and Ruby

Slide 17

Slide 17 text

Vim → Ruby # In a ruby script source = Vim.evaluate("getbufline('.', 1, '$')") .join("\n") puts source # editing source code is printed

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Vim plugins written in Ruby In the real world

Slide 20

Slide 20 text

github.com/pocke/iro.vim

Slide 21

Slide 21 text

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.

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

github.com/pocke/ yaml-path.vim

Slide 24

Slide 24 text

YAML-Path.vim ● Display a path of YAML. ● It uses Psych to parse a YAML code.

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Conclusion

Slide 27

Slide 27 text

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