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
サービス内で複数のOP・ASを連鎖させる(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
290
わたしが知り合いゼロの勉強会に 行けるようになるまで
r5ni4
2
800
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
54k
Kiro Crew で始める マルチエージェント開発
miu_crescent
PRO
0
190
AIエージェントのためのデータ設計
daiz21
0
280
内製AIチャットボット開発で学んだ Datadog Agent Observability活用術
mkdev10
0
150
RelayerというPHPのフレームワークを作った
polidog
PRO
0
140
RapidCopy2 Matrix I/Oエンジンによるファイルコピーソフトウェアの設計と実装
kengosawa2
1
420
Android skills に学ぶ
kokiko
0
190
カーネルまで探検して理解するふたつの自動計装
sumiyae
0
320
IHV like なユースケースへのOpenID Connect 関連仕様の適用事例
optim
0
290
形式手法特論:Hyperproperty とモデル検査 #kernelvm / Kernel VM Study Tokyo 19th
ytaka23
0
810
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
250
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
580
The Mindset for Success: Future Career Progression
greggifford
PRO
0
480
The Cost Of JavaScript in 2023
addyosmani
55
10k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
310
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
430
Designing for Performance
lara
611
70k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
The Pragmatic Product Professional
lauravandoore
37
7.4k
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