ebook img

Practical Vim: Edit Text at the Speed of Thought PDF

329 Pages·2012·8.064 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Practical Vim: Edit Text at the Speed of Thought

www.it-ebooks.info www.it-ebooks.info What readers are saying about Practical Vim I’ve learned more about Vim by reading this book than I have from any other resource. ➤ Robert Evans Software Engineer, Code Wranglers After reading a couple of chapters of Practical Vim, I realized how little I knew. From intermediate to beginner in thirty minutes! ➤ Henrik Nyh Software Engineer Practical Vim continues to change what I believe a text editor can do. ➤ John P. Daigle Developer, ThoughtWorks, Inc. Drew has continued the wonderful work he has done with Vimcasts in this book, a must-read for anyone serious about Vim. ➤ Anders Janmyr Developer, Jayway Practical Vim bridges the gap between the official documentation and how to really use Vim. After reading a few chapters, I switched to using Vim as my default editor. I’ve never looked back. ➤ Javier Collado QA Automation Engineer, Canonical Ltd. www.it-ebooks.info Drew Neil does more than show the right tool for the job. He paces the narrative, laying out the philosophy behind each decision. Instead of expecting you to memorize everything, Practical Vim teaches you to think with Vim under your fingertips. ➤ Mislav Marohnic Consultant I’ve been using Vim for server maintenance for more than fifteen years now, but I’ve only recently started using it for software development. I thought I knew Vim, but Practical Vim has massively improved my code-wrangling productivity. ➤ Graeme Mathieson Software Engineer, Rubaidh Ltd. Practical Vim made me realize how much there is still to learn about Vim. Every single tip can be easily and immediately applied to your workflow and will improve your productivity manifold. ➤ Mathias Meyer Author, Riak Handbook Practical Vim is the ultimate treasure chest when it comes to Vim knowledge. I’ve used Vim daily for over two years now, and this book has been nothing short of a revelation for me. ➤ Felix Geisendörfer Cofounder, Transloadit www.it-ebooks.info Practical Vim Edit Text at the Speed of Thought Drew Neil The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina www.it-ebooks.info Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com. The team that produced this book includes: Kay Keppler (editor) Potomac Indexing, LLC (indexer) Molly McBeath (copyeditor) David J. Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2012 The Pragmatic Bookshelf. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-934356-98-2 Encoded using the finest acid-free high-entropy binary digits. Book version: P1.0—September 2012 www.it-ebooks.info Contents Acknowledgments . . . . . . . . . . . xi Foreword . . . . . . . . . . . . . xiii Read Me . . . . . . . . . . . . . . xv Read the Forgotten Manual . . . . . . . . . xvii 1. The Vim Way . . . . . . . . . . . . . 1 Tip 1. Meet the Dot Command 1 Tip 2. Don’t Repeat Yourself 4 Tip 3. Take One Step Back, Then Three Forward 6 Tip 4. Act, Repeat, Reverse 8 Tip 5. Find and Replace by Hand 9 Tip 6. Meet the Dot Formula 11 Part I — Modes 2. Normal Mode . . . . . . . . . . . . 15 Tip 7. Pause with Your Brush Off the Page 15 Tip 8. Chunk Your Undos 16 Tip 9. Compose Repeatable Changes 17 Tip 10. Use Counts to Do Simple Arithmetic 20 Tip 11. Don’t Count If You Can Repeat 22 Tip 12. Combine and Conquer 24 3. Insert Mode . . . . . . . . . . . . . 27 Tip 13. Make Corrections Instantly from Insert Mode 27 Tip 14. Get Back to Normal Mode 28 Tip 15. Paste from a Register Without Leaving Insert Mode 29 Tip 16. Do Back-of-the-Envelope Calculations in Place 31 Tip 17. Insert Unusual Characters by Character Code 32 www.it-ebooks.info Contents • vi Tip 18. Insert Unusual Characters by Digraph 33 Tip 19. Overwrite Existing Text with Replace Mode 34 4. Visual Mode . . . . . . . . . . . . . 37 Tip 20. Grok Visual Mode 37 Tip 21. Define a Visual Selection 39 Tip 22. Repeat Line-Wise Visual Commands 41 Tip 23. Prefer Operators to Visual Commands Where Possible 43 Tip 24. Edit Tabular Data with Visual-Block Mode 45 Tip 25. Change Columns of Text 47 Tip 26. Append After a Ragged Visual Block 48 5. Command-Line Mode . . . . . . . . . . 51 Tip 27. Meet Vim’s Command Line 51 Tip 28. Execute a Command on One or More Consecutive Lines 54 Tip 29. Duplicate or Move Lines Using ‘:t’ and ‘:m’ Commands 59 Tip 30. Run Normal Mode Commands Across a Range 61 Tip 31. Repeat the Last Ex Command 63 Tip 32. Tab-Complete Your Ex Commands 65 Tip 33. Insert the Current Word at the Command Prompt 66 Tip 34. Recall Commands from History 68 Tip 35. Run Commands in the Shell 71 Part II — Files 6. Manage Multiple Files . . . . . . . . . . 77 Tip 36. Track Open Files with the Buffer List 77 Tip 37. Group Buffers into a Collection with the Argument List 80 Tip 38. Manage Hidden Files 83 Tip 39. Divide Your Workspace into Split Windows 85 Tip 40. Organize Your Window Layouts with Tab Pages 89 7. Open Files and Save Them to Disk . . . . . . . 93 Tip 41. Open a File by Its Filepath Using ‘:edit’ 93 Tip 42. Open a File by Its Filename Using ‘:find’ 96 Tip 43. Explore the File System with netrw 98 Tip 44. Save Files to Nonexistent Directories 101 Tip 45. Save a File as the Super User 102 www.it-ebooks.info Contents • vii Part III — Getting Around Faster 8. Navigate Inside Files with Motions . . . . . . . 107 Tip 46. Keep Your Fingers on the Home Row 108 Tip 47. Distinguish Between Real Lines and Display Lines 110 Tip 48. Move Word-Wise 112 Tip 49. Find by Character 114 Tip 50. Search to Navigate 118 Tip 51. Trace Your Selection with Precision Text Objects 120 Tip 52. Delete Around, or Change Inside 124 Tip 53. Mark Your Place and Snap Back to It 126 Tip 54. Jump Between Matching Parentheses 127 9. Navigate Between Files with Jumps . . . . . . . 131 Tip 55. Traverse the Jump List 131 Tip 56. Traverse the Change List 133 Tip 57. Jump to the Filename Under the Cursor 134 Tip 58. Snap Between Files Using Global Marks 137 Part IV — Registers 10. Copy and Paste . . . . . . . . . . . . 141 Tip 59. Delete, Yank, and Put with Vim’s Unnamed Register 141 Tip 60. Grok Vim’s Registers 144 Tip 61. Replace a Visual Selection with a Register 149 Tip 62. Paste from a Register 151 Tip 63. Interact with the System Clipboard 154 11. Macros . . . . . . . . . . . . . . 157 Tip 64. Record and Execute a Macro 158 Tip 65. Normalize, Strike, Abort 161 Tip 66. Play Back with a Count 163 Tip 67. Repeat a Change on Contiguous Lines 164 Tip 68. Append Commands to a Macro 168 Tip 69. Act Upon a Collection of Files 169 Tip 70. Evaluate an Iterator to Number Items in a List 174 Tip 71. Edit the Contents of a Macro 176 www.it-ebooks.info Contents • viii Part V — Patterns 12. Matching Patterns and Literals . . . . . . . . 183 Tip 72. Tune the Case Sensitivity of Search Patterns 183 Tip 73. Use the \v Pattern Switch for Regex Searches 184 Tip 74. Use the \V Literal Switch for Verbatim Searches 187 Tip 75. Use Parentheses to Capture Submatches 189 Tip 76. Stake the Boundaries of a Word 190 Tip 77. Stake the Boundaries of a Match 192 Tip 78. Escape Problem Characters 193 13. Search . . . . . . . . . . . . . . 199 Tip 79. Meet the Search Command 199 Tip 80. Highlight Search Matches 201 Tip 81. Preview the First Match Before Execution 202 Tip 82. Count the Matches for the Current Pattern 204 Tip 83. Offset the Cursor to the End of a Search Match 204 Tip 84. Operate on a Complete Search Match 206 Tip 85. Create Complex Patterns by Iterating upon Search History 209 Tip 86. Search for the Current Visual Selection 212 14. Substitution . . . . . . . . . . . . 215 Tip 87. Meet the Substitute Command 216 Tip 88. Find and Replace Every Match in a File 217 Tip 89. Eyeball Each Substitution 219 Tip 90. Reuse the Last Search Pattern 220 Tip 91. Replace with the Contents of a Register 222 Tip 92. Repeat the Previous Substitute Command 224 Tip 93. Rearrange CSV Fields Using Submatches 228 Tip 94. Perform Arithmetic on the Replacement 229 Tip 95. Swap Two or More Words 230 Tip 96. Find and Replace Across Multiple Files 233 15. Global Commands . . . . . . . . . . . 237 Tip 97. Meet the Global Command 237 Tip 98. Delete Lines Containing a Pattern 238 Tip 99. Collect TODO Items in a Register 240 Tip 100. Alphabetize the Properties of Each Rule in a CSS File 242 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.