Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Vimprint - A Vim Keystroke Parser
nelstrom
May 28, 2013
Technology
1
870
Vimprint - A Vim Keystroke Parser
nelstrom
May 28, 2013
Tweet
Share
More Decks by nelstrom
See All by nelstrom
Follow my leader
nelstrom
9
1.8k
Modelling State Machines with Ragel
nelstrom
11
24k
When & why you should stay out of visual mode
nelstrom
1
3.1k
Vim - Precision editing at the speed of thought
nelstrom
29
5k
This is the problem
nelstrom
1
240
Progressive enhancement - a barrier to progress?
nelstrom
1
580
Other Decks in Technology
See All in Technology
Scrum Fest Osaka 2022 段階的スクラムマスターのススメ
orimomo
0
740
雑な攻撃からELBを守る一工夫 +おまけ / Know-how to protect servers from miscellaneous attacks
hiroga
0
490
チームとチームのチーム
eiel
1
970
要約 "Add Live Text interaction to your app"
ushisantoasobu
0
140
Implementing Kubernetes operators in Java with Micronaut - TechWeek Java Summit 2022
alvarosanchez
0
110
OpsJAWS Meetup21 システム運用アンチパターンのすすめ
yoshiiryo1
0
1.4k
Security Hub のマルチアカウント 管理・運用をサーバレスでやってみる
ch6noota
0
790
Building smarter apps with machine learning, from magic to reality
picardparis
4
3.2k
220628 「Google AppSheet」タスク管理アプリをライブ作成 吉積情報伊藤さん
comucal
PRO
0
170
2024卒_freee_エンジニア職(ポテンシャル採用)_説明資料
freee
0
210
Azure Arc Virtual MachineとAzure Arc Resource Bridge / VM provisioning through Azure portal on Azure Stack HCI (preview)
sashizaki
0
120
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
10
18k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
219
17k
Thoughts on Productivity
jonyablonski
43
2.3k
Documentation Writing (for coders)
carmenhchung
48
2.5k
The Pragmatic Product Professional
lauravandoore
19
3k
Reflections from 52 weeks, 52 projects
jeffersonlam
337
17k
Learning to Love Humans: Emotional Interface Design
aarron
261
37k
Imperfection Machines: The Place of Print at Facebook
scottboms
253
12k
For a Future-Friendly Web
brad_frost
166
7.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_i
23
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.2k
Typedesign – Prime Four
hannesfritz
33
1.4k
Building a Scalable Design System with Sketch
lauravandoore
448
30k
Transcript
VIMPRINT A VIM KEYSTROKE PARSER 28th May, 2013 Drew Neil
@nelstrom
VIMPRINT should... visualize keystrokes in realtime
VIMPRINT should... understand all built-in commands
VIMPRINT should... be extensible
VimSpeak Turns spoken English into keystrokes https://github.com/AshleyF/VimSpeak
None
VimSplain Turns keystrokes into plain English https://github.com/pafcu/Vimsplain
Vimulator Turns live keystrokes into plain English https://github.com/thoughtbot/vimulator
None
VimGolf Logs real keystrokes https://github.com/igrigorik/vimgolf
None
vim -w keystrokes are BUFFERED
None
Parslet 1st attempt at parsing Vim keystrokes
None
class Vimprint < Parslet::Parser rule(:start) { match('[iIaAoOsS]').as(:switch) } rule(:typing) {
match('[^\e]').repeat.as(:typing) } rule(:terminate) { match('\e').as(:escape) } rule(:insertion) { start >> typing >> terminate } root(:insertion) end
gv major stumbling block: switch from Normal mode to Visual
mode and select the last selected text
Ragel 2nd attempt at parsing Vim keystrokes
Ragel state machines can not only recognize byte sequences as
regular expression machines do, but can also execute code at arbitrary points in the recognition of a regular language.
%%{ machine vim_print; action return { fret; } action push_insert_mode
{ fcall insert_mode; } escape = 27; input = (any - escape); motion = [hjklbwe0]; switch = [iIaAsSoO]; insert_mode := ( input* escape @return ); normal_mode := ( motion | switch @push_insert_mode )*; }%%
2 IN 1 insert_mode normal_mode '0', 'b', 'e', 'h', 'j'..'l',
'w' 'A', 'I', 'O', 'S', 'a', 'i', 'o', 's' / push_insert_mode 3 27 / return DEF
action H { @head = p } action T {
@tail = p } action EmitMotion { @events << {motion: strokes} } action EmitSwitch { @events << {switch: strokes} } action EmitInput { @events << {input: strokes} } action EmitEscape { @events << {escape: '<Esc>'} } escape = 27 >H@T @EmitEscape; input = (any - escape) >H@T @EmitInput; motion = [hjklbwe0] >H@T @EmitMotion; switch = [iIaAsSoO] >H@T @EmitSwitch;
class VimParser attr_accessor :head, :tail, :data def initialize(listener) @events =
listener %% write data; end def process(input) @data = input.unpack("c*") eof = @data.length stack = [] %% write init; %% write exec; end def strokes @data[@head..@tail].pack('c*') end end
VimParser.new(recorder = []).process("helihello\e") puts recorder {:motion=>"h"} {:motion=>"e"} {:motion=>"l"} {:switch=>"i"} {:input=>"h"}
{:input=>"e"} {:input=>"l"} {:input=>"l"} {:input=>"o"} {:escape=>"<Esc>"} https://gist.github.com/nelstrom/5663083
FATAL FLAWS with parsing keystrokes
FATAL FLAWS no timestamps <leader>{...}
FATAL FLAWS no document context :s/{pattern}/{string}/c
FATAL FLAWS no filetype detection
HALP! https://github.com/nelstrom/vimprint Vimprint Realtime Vim keystroke visualizer