Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor

Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 45%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Create, install, and use Vim scripts
  • Personalize your work-area
  • Optimize your Vim editor to be faster and more responsive


Book Details

Language : English
Paperback : 228 pages [ 235mm x 191mm ]
Release Date : May 2007
ISBN : 1847190936
ISBN 13 : 9781847190932
Author(s) : Kim Schulz
Topics and Technologies : All Books, Application Development, Linux Servers, Open Source

Table of Contents

Chapter 1: Introduction
Chapter 2: Personalizing Vim
Chapter 3: Better Navigation
Chapter 4: Production Boosters
Chapter 5: Advanced Formatting
Chapter 6: Vim Scripting
Appendix A: Vim Can Do Everything
Appendix B: Vim Configuration Alternatives
  • Chapter 1: Introduction
    • Vi, Vim, and Friends
      • vi
      • STEVIE
      • Elvis
      • Nvi
      • Vim
      • Vile
      • Compatibility
    • Vim is Charityware
    • Summary
  • Chapter 2: Personalizing Vim
    • Where are the Config Files?
      • vimrc
      • gvimrc
      • exrc
    • Changing the Fonts
    • Changing Color Scheme
    • Personal Highlighting
    • A More Informative Status Line
    • Toggle Menu and Toolbar
    • Adding Your Own Menu and Toolbar Buttons
      • Adding a Menu
      • Adding Toolbar Icons
    • Modifying Tabs
    • Work Area Personalization
      • Adding a More Visual Cursor
      • Adding Line Numbers
      • Spell Checking Your Language
      • Adding Helpful Tool Tips
      • Using Abbreviations
      • Modifying Key Bindings
    • Summary
  • Faster Navigation in Vim Help
    • Faster Navigation in Multiple Buffers
    • Open Referenced Files Faster
  • Search and You Will Find
    • Search the Current File
    • Search in Multiple Files
    • Search the Help System
  • X Marks the Spot
    • Visible Markers—Using Signs
    • Hidden Markers—Using Marks
  • Summary
  • Chapter 4: Production Boosters
    • Using Templates
      • Using Template Files
      • Abbreviations as Templates
    • Using Tag Lists
      • Easier Taglist Navigation
      • Other Usages of Taglists
    • Using Auto-Completion
      • Auto-Completion with Known Words
      • Auto-Completion using Dictionary Lookup
      • Omni-Completion
      • All-in-One Completion
    • Using Macro Recording
    • Using Sessions
      • Simple Session Usage
        • Satisfy your own Session Needs
      • Sessions as a Project Manager
    • Registers and Undo Branching
      • Using Registers
        • The Unnamed Register
        • The Small Delete Register
        • The Numbered Registers
        • The Named Registers
        • The Read-Only Registers
        • The Selection and Drop Registers
        • The Black Hole Register
        • Search Pattern Register
        • The Expression Register
      • Using Undo Branching
    • Folding
      • Simple Text File Outlining
    • Using vimdiff to Track the Changes
    • Navigation in vimdiff
    • Using Diff to Track Changes
  • Open Files Anywhere
    • Faster Remote File Editing
  • Summary
  • Chapter 5: Advanced Formatting
    • Formatting Text
      • Putting Text into Paragraphs
      • Aligning Text
      • Marking Headlines
      • Creating Lists
    • Formatting Code
      • Autoindent
      • Smartindent
      • Cindent
      • Indentexpr
      • Fast Code Block Formatting
    • Auto Format Pasted Code
  • Using External Formatting Tools
    • Indent
    • Berkeley Par
    • Tidy
  • Summary
  • Chapter 6: Vim Scripting
    • Syntax-Color Schemes
      • Your First Syntax-Color File
      • Syntax Regions
      • Color Scheme and Syntax Coloring
    • Using Scripts
      • Script Types
      • Installing Scripts
        • Uninstalling Scripts
    • Script Development
      • Scripting Basics
        • Types
        • Variables
        • Conditions
        • Lists and Dictionaries
        • Loops
        • Creating Functions
      • Script Structure
      • Scripting Tips
        • Gvim or Vim?
        • Which Operating System?
        • Which Version of Vim?
        • Printing Longer Lines
      • Debugging Vim Scripts
      • Distributing Vim Scripts
      • Making Vimballs
        • Remember the Documentation
      • Using External Interpreters
        • Vim Scripting in Perl
        • Vim Scripting in Python
        • Vim Scripting in Ruby
    • Summary

Kim Schulz

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 fixing to producing full-blown software systems. This entire time, Vim has been Kim's editor of choice and it has been the first thing he installs whenever he sits by a new computer. Today Kim works as a full-time software engineer at CSR Plc. developing software for the next generation wireless technologies. A lot of Kim's spare time has been spent on developing the open-source CMS Fundanemt. This has lead to him now owning the web-hosting company Devteam Denmark that specializes in hosting and development of Fundanemt-based websites.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 10 submitted: last submission 11 Nov 2013

Errata type: Typo | Page number: 93

In the paragraph following the '"x d' command, the second sentence has the usage of 'p' and 'P' the wrong way around: 'p' pastes after the cursor, whereas 'P' pastes before it.


Errata type: Code | Page number: 56

:map :exec "help".expand("") doesn't work untill It is changed to :map :exec "help ".expand("") since there was no space after help in "help" then "helpword" was shown instead of "help word".


Errata type: Code | Page number: 21

:highlight [...] gctermfg=yellow [...] should be ................. ctermfg=yellow......


Errata type: Typo | Page number: 110

Half way through the third paragraph, it mentions "Mircosoft Windows" [sic]. This should be "Microsoft Windows".


Errata type: Typo | Page number: 2

Paragraph five: "how external tool can be used" - "tool" should be plural. Paragraph ten: "not all recipes might work on all platforms" - it'd read better if "might" was replaced with "will". Paragraph eleven: "onother" should be two words.


Errata type: Typo | Page number: 61

In the first paragraph of the "Search in Multiple Files" section, the word "patters" appears (fourth line down, five words from the left) instead of "patterns".


Errata type: Typo | Page number: 19

"where mycolors is the name of one of the installed color schemes. If you don't know the names of the installed color schemes, you can place the cursor after writing: :colorscheme and shift through the names by pressing the tab-key. When you find the color scheme you want, you can press the enter key to apply it." it should read... and sift through it, not shift through it.


Errata type: Code | Page number: 25

Replace "set statusline=[%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]" with "set statusline=[%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v]\ [%p%%]\ [LEN=%L]"


Errata type: Typo | Page number: 2

A lot of Kim's spare time has been spent on developing the open-source CMS Fundament. should be A lot of Kim's spare time has been spent on developing the open-source CMS Fundanemt.


Errata type: code | Page number: 19

in the Function FoldSpellBallon

let foldStart = foldclosed(v:beval_ lnum ) let foldEnd = foldclosedend(v:beval_ lnum) ... let lines = spellsuggest( spellbadword(v:beval_ text)[ 0 ], 5, 0 )

should be

  let foldStart = foldclosed(v:beval_lnum ) let foldEnd = foldclosedend(v:beval_lnum) ... let lines = spellsuggest( spellbadword(v:beval_text)[ 0 ], 5, 0 )



Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor +    Oracle Application Express 4.0 with Ext JS =
50% Off
the second eBook
Price for both: £25.35

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

Chapter 1 introduces Vim and a few well-known relatives; their history and relation to vi is briefly described.

Chapter 2 introduces how to make Vim a better editor for you by modifying it for your personal needs. It shows us ways of modifying fonts, the color scheme, the status line, menus, and toolbar.

Chapter 3 introduces some of the ways in which Vim helps us to navigate through files easily. It explains an alternative way for boosting navigation through files and buffers in Vim.

Chapter 4 introduces you to features in Vim. It describes how to use templates, auto-completion, folding, sessions, and registers.

Chapter 5 introduces simple tricks to format text and code. It also discusses how external tools can be used to give Vim just that extra edge it needs to be the perfect editor.  

Chapter 6 is especially for those who want to learn how to extend Vim with scripts. The chapter introduces scripting basics, how to use and install/uninstall scripts, debugging scripts, and lots more.

Appendix A 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 shows how to keep your Vim configuration files well organized and how to retain your Vim configuration across computers by storing a copy of it online

In Detail

Each chapter of this book deals with a different aspect, and provides recipes for easy-to-use hacks to customize and simplify your Vim experience. After an introduction covering the derivation of Vim and its relatives from the vi editor, the author explains basic changes that you can make to the appearance of the Vim editor. Further chapters cover improved navigation through files and buffers in Vim; speeding up your work with templates, auto-completion, folding, sessions, and registers; and formatting text and code, including using external formatting scripts. The final comprehensive chapter covers everything about using Vim scripts and scripting to extend functionality.

Vim stands for Vi IMproved and is the editor of choice for programmers looking for a highly configurable, stable, open-source, multi-platform text editor. It is included with almost every Linux distribution as the standard text editor, and can be used to work with source code from any language. A big advantage of using Vim is that it can be extensively customized; you can control the basic interface, define personalized key mappings, implement macros, and call external or user-defined scripts. Vim has its own scripting language that allows for plug-in like extensions to enable IDE behavior, syntax scripts and highlighting, color schemes, themes, and utility scripts that can add a wide range of features and functionality.
Vim 7.0, for which this book is written, includes spell-checking, code completion, document tabs, current line and column highlighting, undo branches, and more.

This book contains hacks that cover everything from personalizing Vim according to the user’s work cycle to optimizations that will boost the user’s productivity. It does not cover the basic tasks of using the editor but instead focuses on making life easier for experienced Vim users. It is written for Vim 7.0 , the latest stable version.


This is a cookbook packed with ready-to-use hacks that give solutions for some of the commonest problems users of the Vim editor encounter during their daily use. Each recipe follows a systematic approach with a self-contained description of the task it covers, how to use it, and what you gain by using it. The reader can read any of the hacks in this book without having to read any of the other hacks–where necessary they include cross-references to other relevant hacks. The minimum version of Vim required for each hack is clearly indicated.

Who this book is for

Anyone who has worked with Vim and wants to get more out of this legendary text editor can use the hacks from this book. It does not cover the basic tasks of using the editor but instead focuses on making life easier for more experienced Vim users.

Buy Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software