SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler 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

Mais conteúdo relacionado

Mais de SmartLogic

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, SmartLogicSmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichSmartLogic
 
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 LanguageSmartLogic
 
Effective ActiveRecord
Effective ActiveRecordEffective ActiveRecord
Effective ActiveRecordSmartLogic
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
iOS Development Methodology
iOS Development MethodologyiOS Development Methodology
iOS Development MethodologySmartLogic
 
CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!SmartLogic
 
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 CapistranoSmartLogic
 
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 CodeSmartLogic
 
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 DevelopmentSmartLogic
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An OverviewSmartLogic
 
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 DevelopmentSmartLogic
 
Logstash: Get to know your logs
Logstash: Get to know your logsLogstash: Get to know your logs
Logstash: Get to know your logsSmartLogic
 
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...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.rbSmartLogic
 
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 AppSmartLogic
 
Managing complexity
Managing complexityManaging complexity
Managing complexitySmartLogic
 
ncurses in your hobostove
ncurses in your hobostovencurses in your hobostove
ncurses in your hobostoveSmartLogic
 
A Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIsA Practical Guide to Hypermedia APIs
A Practical Guide to Hypermedia APIsSmartLogic
 
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 RORSmartLogic
 

Mais 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

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Último (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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