O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Practical Vim, 2nd Edition

Book Description

Vim is a fast and efficient text editor that will make you a faster and more efficient developer. It's available on almost every OS, and if you master the techniques in this book, you'll never need another text editor. In more than 120 Vim tips, you'll quickly learn the editor's core functionality and tackle your trickiest editing and writing tasks. This beloved bestseller has been revised and updated to Vim 7.4 and includes three brand-new tips and five fully revised tips.

Table of Contents

  1.  Acknowledgments
  2.  Foreword to the First Edition
  3.  Read Me
    1. How This Book Is Structured
    2. A Note on the Examples
    3. Learn to Touch Type, Then Learn Vim
  4.  Read the Forgotten Manual
    1. Get to Know Vim’s Built-in Documentation
    2. Notation for Simulating Vim on the Page
    3. Downloading the Examples
    4. Use Vim’s Factory Settings
    5. On the Role of Vim Script
    6. On Vim Versions
  5. 1. The Vim Way
    1. Tip 1. Meet the Dot Command
    2. Tip 2. Don’t Repeat YourselfDon’t Repeat Yourself
    3. Tip 3. Take One Step Back, Then Three Forward
    4. Tip 4. Act, Repeat, Reverse
    5. Tip 5. Find and Replace by Hand
    6. Tip 6. Meet the Dot Formula
  6. Part I. Modes
    1. 2. Normal Mode
      1. Tip 7. Pause with Your Brush Off the Page
      2. Tip 8. Chunk Your Undos
      3. Tip 9. Compose Repeatable Changes
      4. Tip 10. Use Counts to Do Simple Arithmetic
      5. Tip 11. Don’t Count If You Can RepeatDon’t Count If You Can Repeat
      6. Tip 12. Combine and Conquer
    2. 3. Insert Mode
      1. Tip 13. Make Corrections Instantly from Insert Mode
      2. Tip 14. Get Back to Normal Mode
      3. Tip 15. Paste from a Register Without Leaving Insert Mode
      4. Tip 16. Do Back-of-the-Envelope Calculations in Place
      5. Tip 17. Insert Unusual Characters by Character Code
      6. Tip 18. Insert Unusual Characters by Digraph
      7. Tip 19. Overwrite Existing Text with Replace Mode
    3. 4. Visual Mode
      1. Tip 20. Grok Visual Mode
      2. Tip 21. Define a Visual Selection
      3. Tip 22. Repeat Line-Wise Visual Commands
      4. Tip 23. Prefer Operators to Visual Commands Where Possible
      5. Tip 24. Edit Tabular Data with Visual-Block Mode
      6. Tip 25. Change Columns of Text
      7. Tip 26. Append After a Ragged Visual Block
    4. 5. Command-Line Mode
      1. Tip 27. Meet Vim’s Command LineMeet Vim’s Command Line
      2. Tip 28. Execute a Command on One or More Consecutive Lines
      3. Tip 29. Duplicate or Move Lines Using ‘:t’ and ‘:m’ CommandsDuplicate or Move Lines Using ‘:t’ and ‘:m’ Commands
      4. Tip 30. Run Normal Mode Commands Across a Range
      5. Tip 31. Repeat the Last Ex Command
      6. Tip 32. Tab-Complete Your Ex Commands
      7. Tip 33. Insert the Current Word at the Command Prompt
      8. Tip 34. Recall Commands from History
      9. Tip 35. Run Commands in the Shell
      10. Tip 36. Run Multiple Ex Commands as a Batch
  7. Part II. Files
    1. 6. Manage Multiple Files
      1. Tip 37. Track Open Files with the Buffer List
      2. Tip 38. Group Buffers into a Collection with the Argument List
      3. Tip 39. Manage Hidden Files
      4. Tip 40. Divide Your Workspace into Split Windows
      5. Tip 41. Organize Your Window Layouts with Tab Pages
    2. 7. Open Files and Save Them to Disk
      1. Tip 42. Open a File by Its Filepath Using ‘:edit’Open a File by Its Filepath Using ‘:edit’
      2. Tip 43. Open a File by Its Filename Using ‘:find’Open a File by Its Filename Using ‘:find’
      3. Tip 44. Explore the File System with netrw
      4. Tip 45. Save Files to Nonexistent Directories
      5. Tip 46. Save a File as the Super User
  8. Part III. Getting Around Faster
    1. 8. Navigate Inside Files with Motions
      1. Tip 47. Keep Your Fingers on the Home Row
      2. Tip 48. Distinguish Between Real Lines and Display Lines
      3. Tip 49. Move Word-Wise
      4. Tip 50. Find by Character
      5. Tip 51. Search to Navigate
      6. Tip 52. Trace Your Selection with Precision Text Objects
      7. Tip 53. Delete Around, or Change Inside
      8. Tip 54. Mark Your Place and Snap Back to It
      9. Tip 55. Jump Between Matching Parentheses
    2. 9. Navigate Between Files with Jumps
      1. Tip 56. Traverse the Jump List
      2. Tip 57. Traverse the Change List
      3. Tip 58. Jump to the Filename Under the Cursor
      4. Tip 59. Snap Between Files Using Global Marks
  9. Part IV. Registers
    1. 10. Copy and Paste
      1. Tip 60. Delete, Yank, and Put with Vim’s Unnamed RegisterDelete, Yank, and Put with Vim’s Unnamed Register
      2. Tip 61. Grok Vim’s RegistersGrok Vim’s Registers
      3. Tip 62. Replace a Visual Selection with a Register
      4. Tip 63. Paste from a Register
      5. Tip 64. Interact with the System Clipboard
    2. 11. Macros
      1. Tip 65. Record and Execute a Macro
      2. Tip 66. Normalize, Strike, Abort
      3. Tip 67. Play Back with a Count
      4. Tip 68. Repeat a Change on Contiguous Lines
      5. Tip 69. Append Commands to a Macro
      6. Tip 70. Act Upon a Collection of Files
      7. Tip 71. Evaluate an Iterator to Number Items in a List
      8. Tip 72. Edit the Contents of a Macro
  10. Part V. Patterns
    1. 12. Matching Patterns and Literals
      1. Tip 73. Tune the Case Sensitivity of Search Patterns
      2. Tip 74. Use the \v Pattern Switch for Regex Searches
      3. Tip 75. Use the \V Literal Switch for Verbatim Searches
      4. Tip 76. Use Parentheses to Capture Submatches
      5. Tip 77. Stake the Boundaries of a Word
      6. Tip 78. Stake the Boundaries of a Match
      7. Tip 79. Escape Problem Characters
    2. 13. Search
      1. Tip 80. Meet the Search Command
      2. Tip 81. Highlight Search Matches
      3. Tip 82. Preview the First Match Before Execution
      4. Tip 83. Offset the Cursor to the End of a Search Match
      5. Tip 84. Operate on a Complete Search Match
      6. Tip 85. Create Complex Patterns by Iterating upon Search History
      7. Tip 86. Count the Matches for the Current Pattern
      8. Tip 87. Search for the Current Visual Selection
    3. 14. Substitution
      1. Tip 88. Meet the Substitute Command
      2. Tip 89. Find and Replace Every Match in a File
      3. Tip 90. Eyeball Each Substitution
      4. Tip 91. Reuse the Last Search Pattern
      5. Tip 92. Replace with the Contents of a Register
      6. Tip 93. Repeat the Previous Substitute Command
      7. Tip 94. Rearrange CSV Fields Using Submatches
      8. Tip 95. Perform Arithmetic on the Replacement
      9. Tip 96. Swap Two or More Words
      10. Tip 97. Find and Replace Across Multiple Files
    4. 15. Global Commands
      1. Tip 98. Meet the Global Command
      2. Tip 99. Delete Lines Containing a Pattern
      3. Tip 100. Collect TODO Items in a Register
      4. Tip 101. Alphabetize the Properties of Each Rule in a CSS File
  11. Part VI. Tools
    1. 16. Index and Navigate Source Code with ctags
      1. Tip 102. Meet ctags
      2. Tip 103. Configure Vim to Work with ctags
      3. Tip 104. Navigate Keyword Definitions with Vim’s Tag Navigation CommandsNavigate Keyword Definitions with Vim’s Tag Navigation Commands
    2. 17. Compile Code and Navigate Errors with the Quickfix List
      1. Tip 105. Compile Code Without Leaving Vim
      2. Tip 106. Browse the Quickfix List
      3. Tip 107. Recall Results from a Previous Quickfix List
      4. Tip 108. Customize the External Compiler
    3. 18. Search Project-Wide with grep, vimgrep, and Others
      1. Tip 109. Call grep Without Leaving Vim
      2. Tip 110. Customize the grep Program
      3. Tip 111. Grep with Vim’s Internal Search EngineGrep with Vim’s Internal Search Engine
    4. 19. Dial X for Autocompletion
      1. Tip 112. Meet Vim’s Keyword AutocompletionMeet Vim’s Keyword Autocompletion
      2. Tip 113. Work with the Autocomplete Pop-Up Menu
      3. Tip 114. Understand the Source of Keywords
      4. Tip 115. Autocomplete Words from the Dictionary
      5. Tip 116. Autocomplete Entire Lines
      6. Tip 117. Autocomplete Sequences of Words
      7. Tip 118. Autocomplete Filenames
      8. Tip 119. Autocomplete with Context Awareness
    5. 20. Find and Fix Typos with Vim’s Spell CheckerFind and Fix Typos with Vim’s Spell Checker
      1. Tip 120. Spell Check Your Work
      2. Tip 121. Use Alternate Spelling Dictionaries
      3. Tip 122. Add Words to the Spell File
      4. Tip 123. Fix Spelling Errors from Insert Mode
  12. 21. Now What?
    1. Keep Practicing!
    2. Make Vim Your Own
    3. Know the Saw, Then Sharpen It
  13. A1. Customize Vim to Suit Your Preferences
    1. Change Vim’s Settings on the Fly
    2. Save Your Configuration in a vimrc File
    3. Apply Customizations to Certain Types of Files