You are previewing Hacking Vim 7.2.

Hacking Vim 7.2

Cover of Hacking Vim 7.2 by Kim Schulz Published by Packt Publishing
  1. Hacking Vim 7.2
    1. Table of Contents
    2. Hacking Vim 7.2
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. New to Vim?
      5. Conventions
      6. Reader feedback
      7. Customer support
    7. 1. Getting Started with Vim
      1. Getting Vim
      2. vi, Vim, and friends
      3. Vim is charityware
      4. Common terminology
      5. Summary
    8. 2. Personalizing Vim
      1. Where are the configuration files?
      2. Changing the fonts
      3. Changing color scheme
      4. A more informative status line
      5. Toggle menu and toolbar
      6. Adding your own menu and toolbar buttons
      7. Modifying tabs
      8. Work area personalization
      9. Summary
    9. 3. Better Navigation
      1. Faster navigation in a file
      2. Faster navigation in Vim help
      3. Search and you will find
      4. X marks the spot
      5. Summary
    10. 4. Production Boosters
      1. Using templates
      2. Using tag lists
      3. Using autocompletion
      4. Using macro recording
      5. Using sessions
      6. Registers and undo branching
      7. Using undo branching
      8. Folding
      9. Open files anywhere
      10. Summary
    11. 5. Advanced Formatting
      1. Formatting text
      2. Formatting code
      3. Using external formatting tools
      4. Summary
    12. 6. Basic Vim Scripting
      1. Syntax-color schemes
      2. Syntax regions
      3. Using scripts
      4. Script development
      5. Summary
    13. 7. Extended Vim Scripting
      1. Script structure
      2. Scripting tips
      3. Debugging Vim scripts
      4. Distributing Vim scripts
      5. Remember the documentation
      6. Using external interpreters
      7. Summary
    14. A. Vim Can Do Everything
      1. Vim games
      2. Programmers IDE
      3. Mail program
      4. Chat with Vim
      5. Using Vim as a Twitter client
    15. B. Vim Configuration Alternatives
      1. Tips for keeping your vimrc file clean
      2. A vimrc setup system
      3. Storing vimrc online
    16. Index
O'Reilly logo

Folding

Often, when you work with large files, especially code, it can be hard to get a good overview. In Vim, there is a special feature that helps you get around this—folding text blocks into folds. In this recipe, we will look at how to use folds to make your code easier to overview.

A fold is a way of folding a range of lines (for example, a function scope) into one single line without losing the contents. An example could be the following code:

function myFunction(){
   var a = 1;
   var b = 0;
   var c = a+b;
   return c;
}

If this is folded, then it could be set to look like this:

+-- 6 lines: function myFunction(){ ------------------------------

In this case, the folding follows the syntax of the code and uses the { } to figure out where to do the folding. ...

The best content for your career. Discover unlimited learning on demand for around $1/day.