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
Oracle Cloud Infrastructure:2026年6月度サービス・アップデート
oracle4engineer
PRO
0
230
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
250
LayerX コーポレートエンジニアリング室におけるサプライチェーンセキュリティへの取り組み / Supply Chain Security at LayerX Corporate Engineering
yuyatakeyama
3
780
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
AIチャット検索改善の3週間
kworkdev
PRO
2
160
Comment regagner la souveraineté de vos données tout en étant payé grâce à Nostr !
rlifchitz
0
150
サイバーエージェントにおけるAI推進戦略と変革への取り組み
shotatsuge
0
420
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
180
人材育成分科会.pdf
_awache
4
310
気軽に使える"情報のハブ"としてのNotion活用 〜フロー情報の集積点 と、 Claude Code × Notion AI〜
syucream
1
170
「勝手に広まる」人気 AI エージェントを爆速で作ろう!(AWS Summit Japan 2026講演資料)
minorun365
PRO
10
2.4k
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
170
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.3k
Ethics towards AI in product and experience design
skipperchong
2
310
BBQ
matthewcrist
89
10k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
A designer walks into a library…
pauljervisheath
211
24k
Deep Space Network (abreviated)
tonyrice
0
210
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
750
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
260
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.5k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
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