SlideShare a Scribd company logo
1 of 13
Download to read offline
Vim Registers & Macros
A few mildly clever things that make vim the best
                                text editor around
The "default" register
You use one of them all the time
● The 'unnamed' register " is used for
  every* delete, yank, change, substitute
  and put
● AKA: The " register




             * Except for those that are smaller than a line, but we'll fix that
Numbered Registers
A stack of previous yanks and deletes
● "0 is usually the same as ""
● Each yank or delete pushes a new "0 onto
   the stack, thereby incrementing the "1
   through "9
The only catch
"Small" deletes, namely those less than one
line in size, skip the numbered registers.
● I find this to be a pain in the ass
● :set clipboard=unnamed
  ○ This is the only change I'll ask you to make
  ○ This can run into a problem when running
    vim inside tmux on OSX (see https://github.
    com/ChrisJohnsen/tmux-MacOSX-
    pasteboard)
  ○ This will replace your system clipboard's
    contents
Letter registers
● Only used explicitly
● "fyy will yank the current line into the y
  register
● "fp will paste that line
● These are also the registers used for
  macros
The expression register
● "=
  ○ An embedded calculator
  ○ Usually accessed via Ctrl-r = when in insert
    mode
The unloved rest
●   "% Name of current file (Readonly)
●   "# Name of alternate file (Readonly)
●   ". Same text as the '.' command (Readonly)
●   ": Text of last command-mode (Readonly)
●   "* System clipboard - Only sometimes unloved
●   "_ The black hole
●   "/ Text of last search pattern
Macros
● When the '.' command isn't enough
● Can be a sign that code should be
  refactored & simplified
● Useful on large swaths of copy needing
  tedious and repetitive changes
● Can be useful in repetitive cucumber
  features
Creating macros
●    Start with q#{register}
●    make appropriate changes
●    end with q
--   OR --
●    Put your sequence on a line and yank it
     into the register
     ○ Prefer ^y$ over yy for this yank - avoid
       extra ^J
Playing back macros
● @#{register} to replay macro stored in
  register
● @@ to repeat last macro
● Can also prefix with a count
Examples
● <p><b>Something</b></p> into
  <h4>Something</h4>
● Reorder method parameters
● Change YOB to current age
Best practices
● Recursion
  ○ Standard cautions
  ○ Start with qxqqx to clear register first
  ○ Once you have the base case working,
    qX@xq will (usually) make it recursive
● Strive for single-line macros
  ○ Start with a search
  ○ End with j0 or j^
● :% normal @x is an alternative to
  recursion
● Debug macros from registers
Questions?
● Paul Ostazeski, Developer at SmartLogic
  Solutions
● @paulostazeski

More Related Content

More from SmartLogic

How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan Ivovich
SmartLogic
 
A Practical Guide To Hypermedia APIs - Philly.rb
A Practical Guide To Hypermedia APIs - Philly.rbA Practical Guide To Hypermedia APIs - Philly.rb
A Practical Guide To Hypermedia APIs - Philly.rb
SmartLogic
 
Managing complexity
Managing complexityManaging complexity
Managing complexity
SmartLogic
 
ncurses in your hobostove
ncurses in your hobostovencurses in your hobostove
ncurses in your hobostove
SmartLogic
 
A Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIsA Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIs
SmartLogic
 

More from SmartLogic (20)

Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan Ivovich
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Effective ActiveRecord
Effective ActiveRecordEffective ActiveRecord
Effective ActiveRecord
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
iOS Development Methodology
iOS Development MethodologyiOS Development Methodology
iOS Development Methodology
 
CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!
 
Deploying Rails Apps with Chef and Capistrano
 Deploying Rails Apps with Chef and Capistrano Deploying Rails Apps with Chef and Capistrano
Deploying Rails Apps with Chef and Capistrano
 
From Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to CodeFrom Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to Code
 
The Language of Abstraction in Software Development
The Language of Abstraction in Software DevelopmentThe Language of Abstraction in Software Development
The Language of Abstraction in Software Development
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An Overview
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS DevelopmentIntro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS Development
 
Logstash: Get to know your logs
Logstash: Get to know your logsLogstash: Get to know your logs
Logstash: Get to know your logs
 
Intro to Accounting with QuickBooks for Startups, Software Development Compan...
Intro to Accounting with QuickBooks for Startups, Software Development Compan...Intro to Accounting with QuickBooks for Startups, Software Development Compan...
Intro to Accounting with QuickBooks for Startups, Software Development Compan...
 
A Practical Guide To Hypermedia APIs - Philly.rb
A Practical Guide To Hypermedia APIs - Philly.rbA Practical Guide To Hypermedia APIs - Philly.rb
A Practical Guide To Hypermedia APIs - Philly.rb
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Managing complexity
Managing complexityManaging complexity
Managing complexity
 
ncurses in your hobostove
ncurses in your hobostovencurses in your hobostove
ncurses in your hobostove
 
A Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIsA Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIs
 
Behavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning RORBehavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning ROR
 

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Recently uploaded (20)

TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 

Vim Registers & Macros

  • 1. Vim Registers & Macros A few mildly clever things that make vim the best text editor around
  • 2. The "default" register You use one of them all the time ● The 'unnamed' register " is used for every* delete, yank, change, substitute and put ● AKA: The " register * Except for those that are smaller than a line, but we'll fix that
  • 3. Numbered Registers A stack of previous yanks and deletes ● "0 is usually the same as "" ● Each yank or delete pushes a new "0 onto the stack, thereby incrementing the "1 through "9
  • 4. The only catch "Small" deletes, namely those less than one line in size, skip the numbered registers. ● I find this to be a pain in the ass ● :set clipboard=unnamed ○ This is the only change I'll ask you to make ○ This can run into a problem when running vim inside tmux on OSX (see https://github. com/ChrisJohnsen/tmux-MacOSX- pasteboard) ○ This will replace your system clipboard's contents
  • 5. Letter registers ● Only used explicitly ● "fyy will yank the current line into the y register ● "fp will paste that line ● These are also the registers used for macros
  • 6. The expression register ● "= ○ An embedded calculator ○ Usually accessed via Ctrl-r = when in insert mode
  • 7. The unloved rest ● "% Name of current file (Readonly) ● "# Name of alternate file (Readonly) ● ". Same text as the '.' command (Readonly) ● ": Text of last command-mode (Readonly) ● "* System clipboard - Only sometimes unloved ● "_ The black hole ● "/ Text of last search pattern
  • 8. Macros ● When the '.' command isn't enough ● Can be a sign that code should be refactored & simplified ● Useful on large swaths of copy needing tedious and repetitive changes ● Can be useful in repetitive cucumber features
  • 9. Creating macros ● Start with q#{register} ● make appropriate changes ● end with q -- OR -- ● Put your sequence on a line and yank it into the register ○ Prefer ^y$ over yy for this yank - avoid extra ^J
  • 10. Playing back macros ● @#{register} to replay macro stored in register ● @@ to repeat last macro ● Can also prefix with a count
  • 11. Examples ● <p><b>Something</b></p> into <h4>Something</h4> ● Reorder method parameters ● Change YOB to current age
  • 12. Best practices ● Recursion ○ Standard cautions ○ Start with qxqqx to clear register first ○ Once you have the base case working, qX@xq will (usually) make it recursive ● Strive for single-line macros ○ Start with a search ○ End with j0 or j^ ● :% normal @x is an alternative to recursion ● Debug macros from registers
  • 13. Questions? ● Paul Ostazeski, Developer at SmartLogic Solutions ● @paulostazeski