Slide 1

Slide 1 text

Developing a Vim plugin with Ruby, or when in Ruby do as the Rubyists do VimConf 2023 Tiny OKURA Masafumi, 2023-11-18

Slide 2

Slide 2 text

English

Slide 3

Slide 3 text

20 minutes

Slide 4

Slide 4 text

Me

Slide 5

Slide 5 text

About me • Name: OKURA Masafumi • Company: nil (freelancer) • Specialty: Web development with Rails • Activities: Rubyist, Kaigi on Rails chief organizer, OSS maintainer (Alba), meetup organizer (Grow.rb, Rubygems Code Reading Meetup) • I brought some KoR swags today, talk to me to get one! • Vim user history: Vim (2013-2018), Neovim (2018-)

Slide 6

Slide 6 text

VimConf and me • -2017: Attendee • 2018: Speaker (A day in the life of a (ordinary) Vimmer) • 2019: Organizer • After the conference, I was recommended to translate a book called “Mastering Vim” and I did it. It’s “ϚελϦϯάVim” • 2023: Speaker <- new!

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Question

Slide 10

Slide 10 text

Your choice of the language

Slide 11

Slide 11 text

…for the development of Vim plugins

Slide 12

Slide 12 text

/(Neo)?vim/

Slide 13

Slide 13 text

Language for the development of vim plugins 1. Vim script 2. Vim9 script 3. Lua 4. Deno

Slide 14

Slide 14 text

Language for the development of vim plugins 1. Vim script 2. Vim9 script 3. Lua 4. Deno 5. Ruby

Slide 15

Slide 15 text

No one (I believe)

Slide 16

Slide 16 text

Why Ruby?

Slide 17

Slide 17 text

Developing a Vim plugin with Ruby, or when in Ruby do as the Rubyists do VimConf 2023 Tiny OKURA Masafumi, 2023-11-18

Slide 18

Slide 18 text

Developing a Vim plugin with Ruby, or when in Ruby do as the Rubyists do VimConf 2023 Tiny OKURA Masafumi, 2023-11-18

Slide 19

Slide 19 text

When in Ruby

Slide 20

Slide 20 text

When you want to manipulate Ruby code

Slide 21

Slide 21 text

Do as the Rubyists do

Slide 22

Slide 22 text

What do Rubyists do?

Slide 23

Slide 23 text

AST

Slide 24

Slide 24 text

Abstract Syntax Tree

Slide 25

Slide 25 text

RubyVM::AbstractSyntaxTree

Slide 26

Slide 26 text

RubyVM::AbstractSyntaxTree • Stdlib • No external dependencies • No need to install something via package managers • Takes Ruby source code as a String and returns AST root node • Not best for modifying code but good enough to get some information from code

Slide 27

Slide 27 text

RSpec

Slide 28

Slide 28 text

RSpec • One of the most famous testing libraries for Ruby • In fact, one of the most downloaded library • Introducing DSLs such as `describe`, `context`, `it` and `let` • Readable as English • These can be deeply nested • Tests can be implicit with `subject` and `is_expected`

Slide 29

Slide 29 text

The problem

Slide 30

Slide 30 text

What is the current context/subject?

Slide 31

Slide 31 text

rspec-current.vim

Slide 32

Slide 32 text

Demo

Slide 33

Slide 33 text

Why not LSP?

Slide 34

Slide 34 text

Why not LSP for this case? • Too trivial/niche • I cannot push this feature into generic LSP servers • Not enough functionality on extension/add-on/plugin system • ruby-lsp provides add-on system, but it’s immature now • Too many things to learn for only one feature • LSP is not the easiest thing to learn

Slide 35

Slide 35 text

Ruby as a solution!

Slide 36

Slide 36 text

Using Ruby as a development language • Simple/Easy • One fi le to work with, no external dependencies • Straightforward • Just plain Ruby code • Less things to learn • We need to learn how to develop a plugin with Ruby, but it’s simpler than learning LSP

Slide 37

Slide 37 text

How to

Slide 38

Slide 38 text

gem install neovim If you use Neovim

Slide 39

Slide 39 text

rubyeval

Slide 40

Slide 40 text

Ruby heredoc

Slide 41

Slide 41 text

Summary

Slide 42

Slide 42 text

Usecase

Slide 43

Slide 43 text

Usecase for using Ruby as a development language for vim

Slide 44

Slide 44 text

Language- speci fi c features

Slide 45

Slide 45 text

Use your own language!

Slide 46

Slide 46 text

Because you can

Slide 47

Slide 47 text

Because of Vim

Slide 48

Slide 48 text

Because Vim is so kind to let you do so

Slide 49

Slide 49 text

Happy vimming!