Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vimprint - A Vim Keystroke Parser
Search
nelstrom
May 28, 2013
Technology
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vimprint - A Vim Keystroke Parser
nelstrom
May 28, 2013
More Decks by nelstrom
See All by nelstrom
Follow my leader
nelstrom
10
2.3k
Modelling State Machines with Ragel
nelstrom
11
25k
When & why you should stay out of visual mode
nelstrom
1
3.8k
Vim - Precision editing at the speed of thought
nelstrom
29
6k
This is the problem
nelstrom
1
290
Progressive enhancement - a barrier to progress?
nelstrom
1
660
Other Decks in Technology
See All in Technology
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
2.5k
ゴールデンパスは敷いただけでは道にならない ─ 企画部門のエンジニアが技術標準を事業価値に変えるまで
mhrtech
1
180
ZOZOTOWNの進化と信頼性を両立する負荷試験
zozotech
PRO
2
170
CDKで書くECSのベストプラクティス、 改めて考え直す2026 #cdkconf2026
makies
1
610
美しいコードを書くためにF#を学んでみた話
yud0uhu
1
440
企業でAWS Organizationsを動かすための組織設計の考え方
nrinetcom
PRO
1
100
非定型なドキュメントを効率よくリファクタする 〜えぇ!?仕様書27本の移行が1日で終わったって!?〜
subroh0508
2
510
LLM/Agent評価:トップ営業の発言を「正解」にする 〜暗黙的正解による評価を営業資産に変える〜
takkuhiro
1
230
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
290
2年前に削除したPHPクラスが、 ある日突然決済をエラーにした
ykagano
1
170
穢れた技術選定について
watany
17
5.1k
Making sense of Google’s agentic dev tools
glaforge
1
250
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.4k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
How to Ace a Technical Interview
jacobian
281
24k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
The agentic SEO stack - context over prompts
schlessera
0
840
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.6k
We Have a Design System, Now What?
morganepeng
55
8.2k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
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