SlideShare uma empresa Scribd logo
1 de 70
Baixar para ler offline
Effective Text Editing
With Vim
by Kentwang
Effective text editing


“Seven habits of effective
text editing”

  - Bram Moolenaar
Problem
Got lots of text to edit
-   source code
-   config file
-   log
-   etc.
Problem
Got lots of text to edit
-   source code
                                                e!
-   config file
                                         gh
                                            tim
                                       ou
-   log
                              have
                                     en
                           ’t
-   etc.
                  Bu
                       td
                         on
Tool


• Selecting a good editor is the first step
  towards effective text editing
• Obviously, Vim is used here
What is vim
Comments
Lots of people said like this
...
TMD
But, some in other way
Why
Different view
Different view
Different view
Vim is a tool, the use of
which must be learned
How to improve
Basic steps

1. Detect inefficiency
2. Find a quicker way
3. Make it a habit
Habit 1:
Moving around quickly
Feature
Feature


  VS
Feature


         VS


Who moved my mouse !
Detect ineffeciency
• Depend on mouse
• Use direction keys
• One line/column each time
• Hard to find match things
Find a quicker way
• Edit without mouse
• Use ‘h j k l’ instead of direction keys
• Move multi-line each time
• Use ‘%’ to find match things
Find a quicker way
• Edit without mouse
• Use ‘h j k l’ instead of direction keys
• Move multi-line each time
• Use ‘%’ to find match things
 Samples:
       20G   jump   to   line 20
       ^     jump   to   first non blank of line
       $     jump   to   end of line
       %     jump   to   match ( #if #endif etc.)
       10j   jump   to   10 lines below
       5w    jump   to   5 words after
Detect ineffeciency

• Typical you search like this
Detect ineffeciency

• Typical you search like this
  /FuncName
Detect ineffeciency

• Typical you search like this
  /FuncName
  n
  n
  n
  n
  ...
Find a quicker way

• The hlsearch option
• The * command
• Folding with ‘zf’ , ‘zo’ and ‘zc’
Make it a habit

• Put this in your vimrc file
     set hlsearch

• Use * again and again
• Use command completion (using <tab>)
• Use fold when needed
Habit 2:
Don’t type it twice
Detect ineffeciency

• Long class names
 - TiXmlAttributeSet
• Long function names
 - QueryDoubleAttribute
• Hard to type and often type it wrong
• Lots of time on indenting and code style
Find a quicker way

• Insert mode completion
• Ctrl - N & Ctrl -P
• Omni-completion
• Automatic indenting
Find a quicker way
Make it a habit

• Use Ctrl + P and Ctrl + N again and again
• Use omni-completion if needed
• Add these lines in vimrc:
  filetype plugin on
  filetype indent on
  “ auto indent
  set ai
  set smarttab
Habit 3:
Fix it when it’s wrong
Detect ineffeciency

• Often misspell English words
• Have to check text carefully
• Need a sequence of actions to correct tem
• After correct you misspell again and again
Find a quicker way

• Spell correction macros
  :iabbrev accnt account
  :syntax keyword WordError accnt
Make it a habit
• Add new words if you see them
Habit 4:
A file seldom comes
       alone
Detect ineffeciency

• When working on a new project you have a
  hard time finding your way in the files
• You have to jump between files all the time
• Edit in an editor but compile in terminal
• Hard to find declaration of symbol
A quicker way


• Find & grep
• ctags & taglist
• Quickfix
Many other ways


• use ‘gf’ to goto header file
• Use ‘[I’ to find the word under the cursor
  in include files. Or ‘[<Tab>’ to jump there
• Use a.vim to switch between .c and .h
Make it a habit

• Use quickfix as often as possible
• Drop ‘a.vim’ to your plugin directory
• Remember to use ‘ctags’ and ‘taglist’
Habit 5:
Let’s work together
Detect ineffeciency
• Often need to compare files
• Switch out of terminal and use windows
  compare tools
• Sometimes have to transfer file from IDC
  server to local first, just because can’t use
  windows compare tools there and diff
  command is not so readable
A quicker way

• vimdiff or vim -d
• Works well in both terminal and GUI
• Pretty result and convenient interactive
• Use ‘[c’ ‘]c’ to jump to changes, ‘do’ ‘dg’ to
  copy text from one to another
A quicker way
More Effective

• Integrate with SVN
• SVN_EDITOR environment variable
• Set vim as diff program for svn diff
Make it a habit
• Use vimdiff instead of windows compare
  tools
• Add this line to your bashrc:
     export SVN_EDITOR=vim

• Edit ~/.subversion/config, set vim as the
  diff-cmd
• If you are a big fan, try Vimperator / Vimium
Habit 6:
Sharpen the saw
Sharpen the saw

• Keep on tuning the set of commands you
  use for your needs
• Learn from what you did
• Type :help command when you need help
Sharpen the saw

• Replacing
• automatic indenting
• quickfix
• plugins
• key-mapping
Replacing

• Replace a word
• Use < and > to match the start/end of
  word


   Samples:
     10, 20s/Old/New/g
     %s/Old/New/g
     %s/<Old/New/g
     %s/<Old>/New/g
Replacing

• Replacing in several files
• Record / Execute register
Sample:
  vim *.cpp                    // start vim
  qq                           // start recording into the q register
  :%s/<OldFunc>/NewFunc/ge   // replacing
  :wnext                       // write and goto next file
  q                            // stop recording
  @q                           // execute
Encoding

• fileencoding
• encoding
• LC_CTYPE
Summary
•   Step 1: Detect inefficiency
    -   Find out what you waste time on
•   Step 2: Find a quicker way
    -   read the online help & quick reference
    -   ask friends & google
    -   do it yourself
•   Step 3: Make it a habit
    -   do it
    -   keep on improving
How NOT to effectively

• No time to read documents or new
  commands. keep on using primitive
  commands.
• Want to learn every feature and use the
  most efficient command all the time.
How NOT to effectively

• No time to read documents or new
  commands. keep on using primitive
  commands.
• Want to learn every feature and use the
  most efficient command all the time.
Learn it, time rewarded.
One more thing
:help user-manual
Questions?
The End

Mais conteúdo relacionado

Semelhante a Effective text editing with vim

2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
How to become a practical Vim user
How to become a practical Vim userHow to become a practical Vim user
How to become a practical Vim userKana Natsuno
 
Habits 2007
Habits 2007Habits 2007
Habits 2007Dang Tan
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleMike Willbanks
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Danny Mulligan
 
Maintainability of Configuration Management Code
Maintainability of Configuration Management CodeMaintainability of Configuration Management Code
Maintainability of Configuration Management CodeClinton Wolfe
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Mozaic Works
 
Pipeline 101 Lorelei Mccollum
Pipeline 101 Lorelei MccollumPipeline 101 Lorelei Mccollum
Pipeline 101 Lorelei MccollumLorelei McCollum
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystackssnyff
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Introducing Pair Programming
Introducing Pair ProgrammingIntroducing Pair Programming
Introducing Pair ProgrammingSteven Smith
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systemsBill Buchan
 

Semelhante a Effective text editing with vim (20)

Tweakers Anonymous
Tweakers AnonymousTweakers Anonymous
Tweakers Anonymous
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
Tweakers Anonymous
Tweakers AnonymousTweakers Anonymous
Tweakers Anonymous
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
How to become a practical Vim user
How to become a practical Vim userHow to become a practical Vim user
How to become a practical Vim user
 
Habits 2007
Habits 2007Habits 2007
Habits 2007
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
ACM Init() lesson 1
ACM Init() lesson 1ACM Init() lesson 1
ACM Init() lesson 1
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
 
Maintainability of Configuration Management Code
Maintainability of Configuration Management CodeMaintainability of Configuration Management Code
Maintainability of Configuration Management Code
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Pipeline 101 Lorelei Mccollum
Pipeline 101 Lorelei MccollumPipeline 101 Lorelei Mccollum
Pipeline 101 Lorelei Mccollum
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Introducing Pair Programming
Introducing Pair ProgrammingIntroducing Pair Programming
Introducing Pair Programming
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Effective text editing with vim

  • 1. Effective Text Editing With Vim by Kentwang
  • 2. Effective text editing “Seven habits of effective text editing” - Bram Moolenaar
  • 3. Problem Got lots of text to edit - source code - config file - log - etc.
  • 4. Problem Got lots of text to edit - source code e! - config file gh tim ou - log have en ’t - etc. Bu td on
  • 5. Tool • Selecting a good editor is the first step towards effective text editing • Obviously, Vim is used here
  • 8. Lots of people said like this
  • 9.
  • 10.
  • 11. ...
  • 12.
  • 13. TMD
  • 14. But, some in other way
  • 15.
  • 16.
  • 17.
  • 18. Why
  • 22. Vim is a tool, the use of which must be learned
  • 24. Basic steps 1. Detect inefficiency 2. Find a quicker way 3. Make it a habit
  • 28. Feature VS Who moved my mouse !
  • 29. Detect ineffeciency • Depend on mouse • Use direction keys • One line/column each time • Hard to find match things
  • 30. Find a quicker way • Edit without mouse • Use ‘h j k l’ instead of direction keys • Move multi-line each time • Use ‘%’ to find match things
  • 31. Find a quicker way • Edit without mouse • Use ‘h j k l’ instead of direction keys • Move multi-line each time • Use ‘%’ to find match things Samples: 20G jump to line 20 ^ jump to first non blank of line $ jump to end of line % jump to match ( #if #endif etc.) 10j jump to 10 lines below 5w jump to 5 words after
  • 32. Detect ineffeciency • Typical you search like this
  • 33. Detect ineffeciency • Typical you search like this /FuncName
  • 34. Detect ineffeciency • Typical you search like this /FuncName n n n n ...
  • 35. Find a quicker way • The hlsearch option • The * command • Folding with ‘zf’ , ‘zo’ and ‘zc’
  • 36. Make it a habit • Put this in your vimrc file set hlsearch • Use * again and again • Use command completion (using <tab>) • Use fold when needed
  • 38. Detect ineffeciency • Long class names - TiXmlAttributeSet • Long function names - QueryDoubleAttribute • Hard to type and often type it wrong • Lots of time on indenting and code style
  • 39. Find a quicker way • Insert mode completion • Ctrl - N & Ctrl -P • Omni-completion • Automatic indenting
  • 41. Make it a habit • Use Ctrl + P and Ctrl + N again and again • Use omni-completion if needed • Add these lines in vimrc: filetype plugin on filetype indent on “ auto indent set ai set smarttab
  • 42. Habit 3: Fix it when it’s wrong
  • 43. Detect ineffeciency • Often misspell English words • Have to check text carefully • Need a sequence of actions to correct tem • After correct you misspell again and again
  • 44. Find a quicker way • Spell correction macros :iabbrev accnt account :syntax keyword WordError accnt
  • 45. Make it a habit • Add new words if you see them
  • 46. Habit 4: A file seldom comes alone
  • 47. Detect ineffeciency • When working on a new project you have a hard time finding your way in the files • You have to jump between files all the time • Edit in an editor but compile in terminal • Hard to find declaration of symbol
  • 48. A quicker way • Find & grep • ctags & taglist • Quickfix
  • 49. Many other ways • use ‘gf’ to goto header file • Use ‘[I’ to find the word under the cursor in include files. Or ‘[<Tab>’ to jump there • Use a.vim to switch between .c and .h
  • 50. Make it a habit • Use quickfix as often as possible • Drop ‘a.vim’ to your plugin directory • Remember to use ‘ctags’ and ‘taglist’
  • 52. Detect ineffeciency • Often need to compare files • Switch out of terminal and use windows compare tools • Sometimes have to transfer file from IDC server to local first, just because can’t use windows compare tools there and diff command is not so readable
  • 53. A quicker way • vimdiff or vim -d • Works well in both terminal and GUI • Pretty result and convenient interactive • Use ‘[c’ ‘]c’ to jump to changes, ‘do’ ‘dg’ to copy text from one to another
  • 55. More Effective • Integrate with SVN • SVN_EDITOR environment variable • Set vim as diff program for svn diff
  • 56. Make it a habit • Use vimdiff instead of windows compare tools • Add this line to your bashrc: export SVN_EDITOR=vim • Edit ~/.subversion/config, set vim as the diff-cmd • If you are a big fan, try Vimperator / Vimium
  • 58. Sharpen the saw • Keep on tuning the set of commands you use for your needs • Learn from what you did • Type :help command when you need help
  • 59. Sharpen the saw • Replacing • automatic indenting • quickfix • plugins • key-mapping
  • 60. Replacing • Replace a word • Use < and > to match the start/end of word Samples: 10, 20s/Old/New/g %s/Old/New/g %s/<Old/New/g %s/<Old>/New/g
  • 61. Replacing • Replacing in several files • Record / Execute register Sample: vim *.cpp // start vim qq // start recording into the q register :%s/<OldFunc>/NewFunc/ge // replacing :wnext // write and goto next file q // stop recording @q // execute
  • 63. Summary • Step 1: Detect inefficiency - Find out what you waste time on • Step 2: Find a quicker way - read the online help & quick reference - ask friends & google - do it yourself • Step 3: Make it a habit - do it - keep on improving
  • 64. How NOT to effectively • No time to read documents or new commands. keep on using primitive commands. • Want to learn every feature and use the most efficient command all the time.
  • 65. How NOT to effectively • No time to read documents or new commands. keep on using primitive commands. • Want to learn every feature and use the most efficient command all the time.
  • 66. Learn it, time rewarded.