hacking vim 7.2

244 200 0
hacking vim 7.2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Hacking Vim 7.2 Ready-to-use hacks with solutions for common situations encountered by users of the Vim editor Kim Schulz BIRMINGHAM - MUMBAI www.it-ebooks.info Hacking Vim 7.2 Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2010 Production Reference: 1230410 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849510-50-9 www.packtpub.com Cover Image by Asher Wishkerman (a.wishkerman@mpic.de) www.it-ebooks.info Credits Author Kim Schulz Reviewers Boris Fersing Thomas Moyer Development Editors Darshana D. Shinde Amey Kanse Technical Editors Madhumita Singh Conrad Sardinha Copy Editor Sneha Kulkarni Indexer Hemangini Bari Editorial Team Leader Mithun Sehgal Project Team Leader Lata Basantani Project Coordinator Shubhanjan Chatterjee Proofreader Lynda Silwoski Production Coordinator Adline Swetha Jesuthas Cover Work Adline Swetha Jesuthas www.it-ebooks.info About the Author Kim Schulz has an M.Sc. in Software Engineering from Aalborg University in Denmark. He has been an active developer in the Linux and open source communities since 1997, and has worked with everything from translation and bug xing to producing a full-blown software system. Throughout this entire time, Vim has been Kim's "weapon" of choice and it is the rst program he installs whenever he sits by a new computer. Today Kim works as a Software engineer at CSR Plc, developing software for the next generation mobile and wireless technologies. Kim is also the owner of a web hosting and development company, Devteam Denmark, that specializes in hosting of websites developed using the Fundanemt Content Management System—a CMS that Kim is a co-developer of. I would like to thank my wife, Line, for letting me take the time to write this book. Without her positive attitude and help, I would never have gotten this book ready. I would also like to add a great thank you to Bram Moolenaar for developing the Vim Editor—I appreciate the fruits of your work every day. www.it-ebooks.info About the Reviewers Boris Fersing is an amateur photographer and student in computational linguistics at the University of Saarland, Germany. For his studies, he participated in many projects and used many programming languages (SML, C/C++, Java, Ruby, Prolog) and Vim was always his editor of choice. He also worked as system administrator for a department of the University of Saarland. With this job he learned how to use some Unix tools and improved his knowledge about the Vim editor. I really would like to thank the author for writing such a nice book. It was a pleasure to review it. The information it contains is really interesting. I recommend this book to everyone who wants to learn more about Vim. Thomas Moyer is a graduate student in Computer Science and Engineering at Pennsylvania State University. He is currently looking at areas of Computer Security including trusted computing hardware and Web 2.0 security. He spends a great deal of time using Vim for editing both code and also writing papers. He has completed a Master's degree from Penn State and is currently working on his Ph.D. I would like to thank my wife and daughter for all of their support, and also the rest of my family. I would also like to thank the members of the Systems and Internet Infrastructure Security Lab at Penn State for their continued support. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Getting Started with Vim 7 Getting Vim 8 vi, Vim, and friends 8 vi 9 STEVIE 9 Elvis 10 nvi 10 Vim 11 Vile 13 Compatibility 14 Vim is charityware 15 Common terminology 15 Summary 16 Chapter 2: Personalizing Vim 17 Where are the conguration les? 18 Changing the fonts 20 Changing color scheme 21 Personal highlighting 22 Example 1: Mark color characters after a certain column 24 Example 2: Mark tabs not used for indentation in code 25 Example 3: Preventing errors caused by IP addresses 26 A more informative status line 26 Toggle menu and toolbar 28 Adding your own menu and toolbar buttons 29 Adding a menu 29 Adding toolbar icons 32 www.it-ebooks.info Table of Contents [ ii ] Modifying tabs 33 Work area personalization 37 Adding a more visual cursor 37 Adding line numbers 39 Spell checking your language 40 Adding helpful tool tips 43 Using abbreviations 46 Example 1: Using abbreviations for quick address insertion 47 Modifying key bindings 49 Summary 52 Chapter 3: Better Navigation 53 Faster navigation in a le 54 Context-aware navigation 54 Moving around within a code le 54 Moving in a code le 56 Navigating long lines 59 Faster navigation in Vim help 60 Faster navigation in multiple buffers 61 Open referenced les faster 62 Search and you will nd 63 Search the current le 64 Example 1: Find the next occurrence of a word 64 Example 2: Search for a word under the cursor 65 Search in multiple les 65 Search the help system 67 X marks the spot 68 Visible markers—using signs 68 Hidden markers—using marks 71 Summary 72 Chapter 4: Production Boosters 73 Using templates 74 Using template les 74 Abbreviations as templates 76 Snippets with the snipMate script 78 Using tag lists 80 Easier taglist navigation 83 Other usages of taglists 83 Using autocompletion 84 Autocompletion with known words 84 Autocompletion using dictionary lookup 85 www.it-ebooks.info Table of Contents [ iii ] Omnicompletion 86 All-in-one completion 89 Using macro recording 90 Using sessions 93 Simple session usage 93 Satisfy your own session needs 96 Sessions as a project manager 97 Registers and undo branching 98 Using registers 99 The unnamed register 100 The small delete register 100 The numbered registers 100 The named registers 101 The read-only registers 101 The selection and drop registers 102 The black hole register 102 Search pattern register 102 The expression register 103 Using undo branching 103 Folding 107 Simple text le outlining 110 Using vimdiff to track the changes 111 Navigation in vimdiff 113 Using diff to track changes 114 Open les anywhere 115 Faster remote le editing 117 Summary 118 Chapter 5: Advanced Formatting 121 Formatting text 121 Putting text into paragraphs 122 Aligning text 124 Marking headlines 125 Creating lists 127 Formatting code 129 Autoindent 130 Smartindent 130 Cindent 131 Indentexpr 132 Fast code-block formatting 132 Auto format pasted code 135 www.it-ebooks.info [...]... interpreters Vim scripting in Perl Vim scripting in Python Vim scripting in Ruby Summary 191 194 195 196 198 199 Appendix A: Vim Can Do Everything 201 Appendix B: Vim Configuration Alternatives 215 Index 223 Vim games Game of Life Nibbles Rubik's cube Tic-Tac-Toe Mines Sokoban Tetris Programmers IDE Mail program Chat with Vim Using Vim as a Twitter client Tips for keeping your vimrc file clean A vimrc setup... location of this folder by opening Vim and executing the following command in normal mode: :echo $VIM The examples could be: • Linux: /usr/share /vim/ vimrc • Windows: c:\program files \vim\ vimrc The personal vimrc file is placed in your home directory The location of the home directory is dependent on your operating system Vim was originally meant for Unixes, so the personal vimrc file is set to be hidden... configuration file specifically for Gvim It resembles the vimrc file previously described, and is placed in the same location as a personal version as well as a global version For example: • Linux: /home/kim/.gvimrc and /usr/share /vim/ gvimrc • Windows: c:\documents and settings\kim\_gvimrc and c:\program files \vim\ gvimrc This file is used for GUI-specific settings that only Gvim will be able to use In the... the Vim setup In the rest of the book, this file is just called vimrc Your vimrc can use other files as an external source for configurations In the vimrc file, you use the source command like this: source /path/to/external/file Use this to keep the vimrc file clean, and your settings more structured (Learn more about how to keep your vimrc clean in Appendix B, Vim Configuration Alternatives) The gvimrc... is dependent on where you have installed Vim and the operating system that you are using In general, there are three configuration files that you must know where to find: • • • vimrc gvimrc exrc The vimrc file is the main configuration file for Vim It exists in two versions—global and personal The global vimrc file is placed in the folder where all of your Vim system files are installed You can find... Creating functions 152 153 157 159 164 168 Chapter 7: Extended Vim Scripting Script structure Script header Script-loaded check Script configuration Key mappings Functions Putting it all together Scripting tips Gvim or Vim? Which operating system? Which version of Vim? Printing longer lines Debugging Vim scripts Distributing Vim scripts Making Vimballs [ iv ] www.it-ebooks.info 175 175 176 176 177 178... would recommend that you try out the Vimtutor that is included with your Vim installation Simply execute the Vimtutor program (placed together with your Vim installation) on your computer and it will then guide you through a range of practical lessons that teach you the Vim basics Expect that it will take around 30 minutes to complete the entire Vimtutor tutorial The Vimtutor is available in many different... • • How to get and install the vim editor The vim family of editors The license that vim is released under Common terminology used throughout the book So, let's get started with this book www.it-ebooks.info Getting Started with Vim Getting Vim You might already be familiar with the Vim editor and have used it for a long time If, however, you haven't played around with Vim yet, this is the right time... will also be given in this chapter Appendix A, Vim Can Do Everything, has a listing of games that have been implemented with Vim scripting; it also provides an overview of chat and mail scripts and has a section on using Vim as an IDE Appendix B, Vim Configuration Alternatives, shows how to keep your Vim configuration files well-organized and retain your Vim configuration across computers by storing... for If you are a Vim user who wants to get more out of this legendary text editor, this book is for you It focuses on making life easier for the intermediate to experienced Vim users New to Vim? Even though this book is written assuming that the reader is already be familiar with Vim basics, it can still be used by newcomers to Vim If you are unsure about your extent of knowledge about Vim in order to . 20 4 Mines 20 4 Sokoban 20 5 Tetris 20 6 Programmers IDE 20 6 Mail program 21 0 Chat with Vim 21 1 Using Vim as a Twitter client 21 2 Appendix B: Vim Conguration Alternatives 21 5 Tips for keeping your vimrc. Perl 195 Vim scripting in Python 196 Vim scripting in Ruby 198 Summary 199 Appendix A: Vim Can Do Everything 20 1 Vim games 20 1 Game of Life 20 2 Nibbles 20 2 Rubik's cube 20 3 Tic-Tac-Toe 20 4 Mines. paragraphs 122 Aligning text 124 Marking headlines 125 Creating lists 1 27 Formatting code 129 Autoindent 130 Smartindent 130 Cindent 131 Indentexpr 1 32 Fast code-block formatting 1 32 Auto format

Ngày đăng: 01/08/2014, 17:13

Mục lục

  • Chapter 1: Getting Started with Vim

    • Getting Vim

    • vi, Vim, and friends

      • vi

      • Chapter 2: Personalizing Vim

        • Where are the configuration files?

        • Changing color scheme

          • Personal highlighting

            • Example 1: Mark color characters after a certain column

            • Example 2: Mark tabs not used for indentation in code

            • Example 3: Preventing errors caused by IP addresses

            • A more informative status line

            • Toggle menu and toolbar

            • Work area personalization

              • Adding a more visual cursor

              • Spell checking your language

              • Adding helpful tool tips

              • Using abbreviations

                • Example 1: Using abbreviations for quick address insertion

                • Chapter 3: Better Navigation

                  • Faster navigation in a file

                    • Context-aware navigation

                      • Moving around within a code file

                      • Moving in a code file

                      • Faster navigation in Vim help

                        • Faster navigation in multiple buffers

                        • Open referenced files faster

                        • Search and you will find

                          • Search the current file

                            • Example 1: Find the next occurrence of a word

                            • Example 2: Search for a word under the cursor

                            • Search in multiple files

                            • Search the help system

Tài liệu cùng người dùng

Tài liệu liên quan