SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

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