SlideShare una empresa de Scribd logo
1 de 13
Descargar para leer sin conexión
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

Más contenido relacionado

Más de 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
 

Más de 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
 

Último

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
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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, ...
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
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
 

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