Pro Vim

Book description

Pro Vim teaches you the real-world workflows, tips, and tricks of this powerful, terminal-based text editor. This book covers all the essentials, as well as lesser-known but equally powerful features that will ensure you become a top-level performant and professional user, able to jump between multiple sessions while manipulating and controlling with ease many different documents and programming files. With easy-to-digest chapters on all the areas you need to learn, this book is a key addition to your library that will enable you to become a fast, efficient user of Vim.

Using this book, you will learn how to properly configure your terminal environment and work without even touching the mouse. You will become an expert in how Vim actually works: how buffers and sessions work, automation through Macros and shell scripting, real-world workflows, and how to work efficiently and fast with plugins and different themes. You will also learn practical, real-world tips on how to best utilize Vim alongside the terminal multiplexer tmux; helping you to manage files across multiple servers and terminal sessions. Avoid common pitfalls and work with best practice ways to efficiently edit and control your files and sessions from the terminal interface.

Vim is an advanced power tool that is commonly recognized as being difficult to learn, even for experienced developers. This book shows you how to become an expert by focusing on not only the fundamentals of how Vim works, but also by distilling the author's own experiences learning Vim into an easy-to-understand and follow guide. It's time to bring your programming, editing, and workflow skills up to the professional level - use Pro Vim today.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewers
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Vim Primer
    1. What Is Vim?
      1. Modern Editors?
      2. Emacs?
    2. How Do You Become Good at Vim?
      1. Mac, Linux, Windows?
      2. Visualizing the Outcome
    3. Summary
  12. Chapter 2: Installation and Configuration
    1. What We’ll Cover
    2. Terminal Emulators and Shell Environments
    3. Shell Commands
    4. Configuring Your Terminal
    5. Changing Shells
    6. Dotfiles
    7. Editing .zshrc
      1. Restart Your Engines!
    8. Choosing a New Theme for Your Terminal
      1. Two Types of Themes
    9. Installing Vim
      1. Mac
      2. Using Homebrew
      3. Linux
      4. Windows
    10. Installing Git
      1. Mac
      2. Linux
      3. Windows
    11. Configuring Vim
      1. Copying the .vim Folder
      2. Copying the .vimrc File
      3. Dynamic Loading
    12. Opening Vim
    13. Summary
  13. Chapter 3: Fundamentals
    1. How Vim Works
      1. Commands
      2. Buffers
      3. Windows
      4. Tabs
      5. Modes
    2. Getting Help
      1. Documentation
      2. Vim’s Wiki
      3. IRC
      4. Mailing Lists
      5. Online Communities
    3. Key Bindings (Revisited)
      1. What About All the Default Vim Bindings?
      2. Key Binding Debug Example
    4. Summary
  14. Chapter 4: Files
    1. Opening Files
    2. File Formats
    3. Inserting Files
    4. Moving Between Files
    5. Saving Files
    6. Creating New Files
      1. new
      2. enew
      3. vnew
      4. tabnew
    7. Creating New Files from a Template
    8. Creating a Scratch Buffer
    9. File Name Modifiers
      1. Previewing Files
      2. Switching Working Directories
    10. Summary
  15. Chapter 5: Commands
    1. Editing Commands
    2. Operators
      1. Examples: Operators
    3. Motions
      1. Examples: Motions
      2. Examples: Operators That Require Motions or Other Commands
      3. Examples: Operators Combined with Motions
    4. There’s More Than One Way to Skin a Cat
    5. Command Inversion
    6. Cursor Movement
    7. Page Movement
    8. Text Objects
      1. Examples: Text Objects
      2. Programming Constructs
      3. Plug-ins
    9. Executing Commands Within INSERT Mode
    10. Summary
  16. Chapter 6: Registers
    1. Accessing a Specific Register
    2. Unnamed Register
    3. Numbered Register
    4. Small Delete Register
      1. Named Register
    5. Read-Only Register
    6. Expression Register
      1. Basic Example
      2. Advanced Example
    7. Selection/Drop Register
    8. Blackhole Register
    9. Last Search Register
    10. Clearing Your Registers
    11. Summary
  17. Chapter 7: Folding
    1. Fold Options
      1. Manual
    2. Creating Folds
    3. Opening/Closing/Toggling Folds
    4. Open/Close All Folds
    5. Marker
    6. Automatically Closing Folds
    7. Folding by Indentation
    8. Nested Folds
    9. Folding by Syntax
    10. Folding Content Dynamically
    11. Folding Unchanged Lines
    12. Summary
  18. Chapter 8: VISUAL-BLOCK Mode
    1. Simple Example
    2. Entering VISUAL-BLOCK Mode
    3. Canceling
    4. Adding Additional Content in Block Format
    5. Complex Example
    6. End-of-Line Concerns
    7. Better Selection Capabilities
    8. Summary
  19. Chapter 9: Bulk Command Processing
    1. bufdo
      1. Simple Example
      2. Complex Example
    2. windo
    3. tabdo
    4. argdo
      1. Modifying the Arguments List
      2. Simple Example
    5. Summary
  20. Chapter 10: Editing Workflow
    1. Practical Examples
      1. Moving Around a Single File
      2. Moving Around on a Single Line
      3. Moving Around Long Files
      4. Moving Between Blocks
      5. Complex Syntax
      6. Text Objects
      7. Find and Replace
    2. Workflow Management
      1. Vim’s Multiverse
      2. Saving State
      3. Sorting Out How to Paste
      4. Alternative Options for Vim Self-Improvement
    3. Summary
  21. Chapter 11: Search and Replace
    1. Finding Files
      1. Paths
    2. Searching for Content
      1. Searching Within the Current Buffer
      2. Searching Within Multiple Buffers
      3. Multiple Search History
    3. Search and Replace
      1. Search and Replace Within the Current Buffer
      2. Search and Replace Within VISUAL-BLOCK Selection
      3. Search and Replace Within Multiple Buffers
    4. Global Command
    5. Expression Replacements
    6. Summary
  22. Chapter 12: Buffer/Window/Tab Management
    1. Buffer Management
      1. Viewing All Buffers
      2. Splitting Buffers into Windows
      3. Different Ways to Close Buffers
    2. Window Management
      1. Opening Split Windows
      2. Closing All Windows Except the Current One
      3. Changing Window Layout
      4. Resizing Windows
      5. Moving a Window to a Tab
    3. Tab Management
      1. Creating and Navigating Tabs
      2. Closing Tabs
      3. Rearranging Tabs
      4. Tabs As a Scratch Pad
    4. Summary
  23. Chapter 13: Automation
    1. Automation Through Ex Mode
    2. Automation Through Macros
      1. Recording Macros
      2. Executing Macros
    3. Real-World Example
    4. Applying Macros Across Multiple Files
    5. More Dynamic Macros Using the Expression Register
    6. Editing Macros
      1. Appending
      2. Editing
    7. Summary
  24. Chapter 14: Lists
    1. Change Lists
      1. Move Back Through Our Change Positions
    2. Jump Lists
      1. Practical Example: Generating a Table of Contents
      2. Ignoring Jumps
    3. Summary
  25. Chapter 15: Marks
    1. Creating Marks
    2. Viewing Marks
    3. Local and Global Marks
    4. Navigating Marks
    5. Moving to Specific Marks
    6. How to Avoid Modifying the Jump List
    7. Deleting Marks
    8. Manipulating Content with Marks
    9. Example: Moving a Visual Selection
    10. Plug-ins
    11. Summary
  26. Chapter 16: Sessions
    1. Views and Sessions
      1. Creating a View
      2. Creating a Session
      3. Issues
      4. Plug-ins
    2. Summary
  27. Chapter 17: Plug-ins
    1. How Do Plug-ins Work?
    2. Vimball
    3. Pathogen: A Plug-in Manager
      1. Installation
      2. Vimball Support
    4. Writing Plug-ins
    5. Generating Help Tags
    6. Exploring Useful Plug-ins
      1. Ack/Ag (Silver Searcher)
      2. Commentary
      3. CtrlP
      4. NERDTree
      5. Surround
      6. EndWise
      7. Tabular
      8. Syntastic
      9. SuperTab
      10. Gist
      11. Fugative
      12. Dispatch
      13. Others . . .
    7. Summary
  28. Chapter 18: Diffing
    1. Two-Way Diff
      1. Moving Between Changes
    2. diffget and diffput
      1. Simple Example
      2. Specifying a Range
      3. Diff Highlighting Breaks After Making a Change?
    3. Diff to HTML
    4. Three-Way Diff (Resolving Git Merge Conflicts)
      1. Git mergetool
      2. Complex Conflicts?
    5. Changing the Diff Theme
    6. Summary
  29. Chapter 19: Custom Commands and Bindings
    1. Creating Your Own Mappings
      1. map vs. noremap
    2. Mapping Keys in Specific Modes
    3. My Own Mappings
      1. CtrlP
      2. NERDTree
      3. Tabularize
      4. ChooseWin
      5. Turn Off Current Search Match Highlights
      6. File System Explorer
      7. Buffers
      8. Windows
    4. Tests
    5. Custom Commands
      1. Practical Example
    6. Summary
  30. Chapter 20: Terminal Integration
    1. Suspending Vim
    2. Executing Terminal Commands
    3. Filtering Content via External Commands
    4. Redirect the Shell into Vim
    5. CTags
      1. Example
      2. Installation
      3. Usage
      4. Tag Stacks
    6. Summary
  31. Chapter 21: Working with Code
    1. Auto-indenting
      1. Indentation with =
    2. Syntax Formatting
      1. Forcing a Different Syntax Format
    3. Ruby
      1. vim-endwise
      2. vim-ruby
      3. vim-cucumber
      4. vim-ruby-refactoring
      5. vim-vroom
    4. Clojure
      1. Rainbow Parentheses
      2. sexp
      3. Fireplace
    5. PHP
      1. PIV
      2. vim-phpqa
      3. Vdebug
    6. Node
      1. vim-node
      2. node-vim-debugger
    7. Summary
  32. Chapter 22: Practical Tips and Tricks
    1. Built-in File System Explorer
      1. Navigating
      2. Other Features
      3. Configuration
    2. Glob-Based Searching
    3. Moving Around Code
    4. Deleting via Search Patterns
    5. Duplicating Lines
    6. Moving Lines
    7. Increment/Decrement Numerical Values
    8. Removing Line Breaks
    9. Ranges
      1. Copy and Paste
      2. Deleting
    10. Character-Level Edits
    11. Loading External Content
    12. Partial File Writing
    13. Pasting from Within INSERT Mode
    14. Pasting Without Affecting the Register
    15. Moving Between Found Items
    16. Sorting
    17. NORMAL Mode Commands in the Command Prompt
      1. Repeat NORMAL Commands
    18. Time-Based Undo
    19. Simultaneous Scrolling
    20. Spell-Checking
      1. Spelling Mistake Indicators
      2. Spelling Suggestions
      3. Auto-complete Spelling Suggestions
      4. Searching for Spelling Mistakes
      5. Repeating Spelling Corrections
      6. . . . and the Rest?
    21. Renaming Multiple Files Inside Vim
      1. Expressions Inside a Substitution
      2. Sample Process
    22. Folder-Specific Custom Configuration
    23. Summary
  33. Chapter 23: Terminal Multiplexer
    1. tmux
    2. Terminology
      1. Prefix Command
    3. Help?
      1. Command and Key Binding References
      2. Manual
      3. Message Feedback
    4. Installation and Configuration
      1. Mac
      2. Linux
      3. Windows
    5. Configuring tmux
      1. Change the Default Prefix
      2. Quick Access to Last Window
      3. Vim Style Movements
      4. Arrow Movements
      5. Simpler Pane Creation
      6. Source .tmux.conf
      7. Clear Pane History
      8. Easier Pane Management
      9. Color Correction
      10. Enable utf8
      11. Command Prompt Movements
      12. Cancel Immediately
      13. Prevent Program Window Renaming Trigger
      14. Change the Default Shell
      15. Human Numbering
      16. Increase Scroll-back
      17. Automatic Window Renumbering
      18. Change the Status Bar Appearing
    6. Summary
  34. Chapter 24: Fundamentals
    1. Sessions
      1. Creating a Session
      2. Listing Sessions
      3. Selecting a Session
      4. Renaming Sessions
      5. Closing vs. Detaching
      6. Application Bootstrap
    2. Buffers
      1. Scrolling the Buffer
      2. Navigating Copy Mode
    3. Panes
      1. Differences Between Vim and tmux
      2. Closing
      3. Navigating
      4. Resizing
      5. Balancing
    4. Windows
      1. Summary
  35. Chapter 25: Modifications
    1. Abstractions
      1. Creating New Sessions
      2. Attaching to Sessions
      3. Destroying Sessions
    2. Extending the Message Display Time
    3. Repeatable Keys
    4. Restoring Broken Commands
    5. Summary
  36. Chapter 26: Copy and Paste
    1. Copy Mode
    2. Paste Buffer
    3. Pasting Between Programs
      1. Plug-in Solution
      2. Mac OS X
      3. Linux
      4. Working from a VM
    4. Summary
  37. Chapter 27: Pane/Window Management
    1. Pane Management
      1. Moving Between Two Commonly Used Panes
      2. Full-Screen Current Pane
      3. Break a Pane Out into a Separate Window
      4. Convert a Window into a Pane (Within Another Window)
      5. Rotate Panes Within Current Window
      6. Changing Pane Layouts
      7. Synchronizing Pane Input
    2. Window Management
      1. Navigating Windows
      2. Closing Windows
      3. Finding Windows by Search Phrase
      4. Moving and Switching Windows Within the Current Session
      5. Moving Windows Between Different Sessions
      6. Sharing Windows Between Sessions
    3. Summary
  38. Chapter 28: Scripting and Automation
    1. Example 1: Automation
      1. Simple Example
      2. Advanced
    2. Example 2: Shell Commands
      1. Conditional Key Bindings
    3. Example 3: tmuxinator
    4. Restoration
      1. Attaching Processes
      2. Restoring State
    5. Summary
  39. Chapter 29: Pair Programming
    1. The Simple Route
    2. The Custom Route
      1. Vagrant Setup
      2. Share Session via Single-User Account
      3. Individual User Control
      4. Remotely Accessing a Local VM
    3. Summary
  40. Chapter 30: Workflow Management
    1. Example Repository
    2. Reptyr
    3. tmux-resurrect
      1. Installation
      2. Sample Usage
    4. Summary
  41. Index

Product information

  • Title: Pro Vim
  • Author(s):
  • Release date: December 2014
  • Publisher(s): Apress
  • ISBN: 9781484202500