<

A Byte of Vim

Table of contents
Chapter One. Installation
1.1 - Windows
1.2 - Mac OS X
1.3 - Linux / BSD
1.4 - Summary
Chapter Two. First Steps
2.1 - Starting Vim
2.2 - Graphical or Terminal?
2.3 - Introduction to Modes
2.4 - Writing a file
2.5 - Summary
Chapter Three. Modes
3.1 - Types of modes
3.2 - Normal mode
3.3 - How to use the help
3.4 - Insert mode
3.5 - Visual mode
3.6 - Summary
Chapter Four. Typing Skills
4.1 - Home Row Technique
4.2 - Vim graphical keyboard cheat sheet
4.3 - Summary
Chapter Five. Moving Around
5.1 - Move your cursor, the Vim way
5.2 - Words, sentences, paragraphs
5.3 - Make your mark
5.4 - Jump around
5.5 - Parts of the text
5.6 - Summary
Chapter Six. Help
6.1 - The :help command
6.2 - How to read the :help topic
6.3 - The :helpgrep command
6.4 - Quick help
6.5 - Mailing List
6.6 - Summary
Chapter Seven. Editing Basics
7.1 - Reading and writing files
7.2 - Cut, Copy and Paste
7.3 - Marking your territory
7.4 - Time machine using undo/redo
7.5 - A powerful search engine but not a dotcom
7.6 - Summary
Chapter Eight. Multiplicity
8.1 - Multiple Sections using Folds
8.2 - Multiple Buffers
8.3 - Multiple Windows
8.4 - Multiple Tabs
8.5 - Summary
Chapter Nine. Personal Information Management
9.1 - Installing Viki
9.2 - Get Started
9.3 - Markup language
9.4 - Disabling CamelCase
9.5 - Getting Things Done
9.6 - Summary
Chapter Ten. Scripting
10.1 - Macros
10.2 - Basics of Scripting
10.3 - Decisions
10.4 - Data Structures
10.5 - Writing a Vim script
10.6 - Using external programming languages
10.7 - Summary
Chapter Eleven. Plugins
11.1 - Customization using vimrc
11.2 - Global plugin
11.3 - Filetype plugin
Chapter Twelve. Programmers Editor
12.1 - Introduction
12.2 - Simple stuff
12.3 - Jumping around
12.4 - Browsing parts of the code
12.5 - Compiling
12.6 - Easy writing(empty)
12.7 - Omnicompletion
12.8 - Using Snippets
12.9 - Creating Snippets
12.10 - IDE
12.11 - Running code from the text
12.12 - SCM integration
12.13 - More
12.14 - Writing your own plugins
12.15 - Access Databases
12.16 - Summary
Chapter Thirteen. More
13.1 - Introduction
13.2 - Modeline
13.3 - Portable Vim
13.4 - Upgrade plugins
13.5 - Dr.Chip's plugins
13.6 - Blog from Vim
13.7 - Make Firefox work like Vim
13.8 - Bram's talk on the seven habits
13.9 - Contribute to Vim
13.10 - Community
13.11 - Summary
Chapter Fourteen. What Next
14.1 - Introduction
14.2 - Summary
Chapter Fifteen. Feedback
Chapter Sixteen. Charityware
Chapter Seventeen. Colophon
17.1 - About this book
17.2 - Creating this book
17.3 - Inspiration
17.4 - About the author
A Byte of Vim
1st Edition
Swaroop C. H.
© Swaroop C H. Available under a Creative Commons Attribution-ShareAlike 4.0 International License. (CC BY-SA 4.0)
Table Of Contents
  • Introduction - Introduction
  • Chapter One - Installation
    • 1.1 - Windows
    • 1.2 - Mac OS X
    • 1.3 - Linux / BSD
    • 1.4 - Summary
  • Chapter Two - First Steps
    • 2.1 - Starting Vim
    • 2.2 - Graphical or Terminal?
    • 2.3 - Introduction to Modes
    • 2.4 - Writing a file
    • 2.5 - Summary
  • Chapter Three - Modes
    • 3.1 - Types of modes
    • 3.2 - Normal mode
    • 3.3 - How to use the help
    • 3.4 - Insert mode
    • 3.5 - Visual mode
    • 3.6 - Summary
  • Chapter Four - Typing Skills
    • 4.1 - Home Row Technique
    • 4.2 - Vim graphical keyboard cheat sheet
    • 4.3 - Summary
  • Chapter Five - Moving Around
    • 5.1 - Move your cursor, the Vim way
    • 5.2 - Words, sentences, paragraphs
    • 5.3 - Make your mark
    • 5.4 - Jump around
    • 5.5 - Parts of the text
    • 5.6 - Summary
  • Chapter Six - Help
    • 6.1 - The :help command
    • 6.2 - How to read the :help topic
    • 6.3 - The :helpgrep command
    • 6.4 - Quick help
    • 6.5 - Mailing List
    • 6.6 - Summary
  • Chapter Seven - Editing Basics
    • 7.1 - Reading and writing files
    • 7.2 - Cut, Copy and Paste
    • 7.3 - Marking your territory
    • 7.4 - Time machine using undo/redo
    • 7.5 - A powerful search engine but not a dotcom
    • 7.6 - Summary
  • Chapter Eight - Multiplicity
    • 8.1 - Multiple Sections using Folds
    • 8.2 - Multiple Buffers
    • 8.3 - Multiple Windows
    • 8.4 - Multiple Tabs
    • 8.5 - Summary
  • Chapter Nine - Personal Information Management
    • 9.1 - Installing Viki
    • 9.2 - Get Started
    • 9.3 - Markup language
    • 9.4 - Disabling CamelCase
    • 9.5 - Getting Things Done
    • 9.6 - Summary
  • Chapter Ten - Scripting
    • 10.1 - Macros
    • 10.2 - Basics of Scripting
    • 10.3 - Decisions
    • 10.4 - Data Structures
    • 10.5 - Writing a Vim script
    • 10.6 - Using external programming languages
    • 10.7 - Summary
  • Chapter Eleven - Plugins
    • 11.1 - Customization using vimrc
    • 11.2 - Global plugin
    • 11.3 - Filetype plugin
  • Chapter Twelve - Programmers Editor
    • 12.1 - Introduction
    • 12.2 - Simple stuff
    • 12.3 - Jumping around
    • 12.4 - Browsing parts of the code
    • 12.5 - Compiling
    • 12.6 - Easy writing(empty)
    • 12.7 - Omnicompletion
    • 12.8 - Using Snippets
    • 12.9 - Creating Snippets
    • 12.10 - IDE
    • 12.11 - Running code from the text
    • 12.12 - SCM integration
    • 12.13 - More
    • 12.14 - Writing your own plugins
    • 12.15 - Access Databases
    • 12.16 - Summary
  • Chapter Thirteen - More
    • 13.1 - Introduction
    • 13.2 - Modeline
    • 13.3 - Portable Vim
    • 13.4 - Upgrade plugins
    • 13.5 - Dr.Chip's plugins
    • 13.6 - Blog from Vim
    • 13.7 - Make Firefox work like Vim
    • 13.8 - Bram's talk on the seven habits
    • 13.9 - Contribute to Vim
    • 13.10 - Community
    • 13.11 - Summary
  • Chapter Fourteen - What Next
    • 14.1 - Introduction
    • 14.2 - Summary
  • Chapter Fifteen - Feedback
  • Chapter Sixteen - Charityware
  • Chapter Seventeen - Colophon
    • 17.1 - About this book
    • 17.2 - Creating this book
    • 17.3 - Inspiration
    • 17.4 - About the author
Introduction
Introduction

A Byte of Vim

"A Byte of Vim" is a book which aims to help you to learn how to use the Vim editor (version 7), even if all you know is how to use the computer keyboard.

The first part of this book is meant for new users who want to understand what Vim is and learn how to use it.

The second part of this book is for people who already know how to use Vim and want to learn about features that make Vim so powerful, such as windows and tabs, personal information management, making it a programmer's editor, how to extend Vim with your own plugins, and more.

Status: Incomplete

Please note that the conversion of the book to this Markdown sources is incomplete!

The original PDF is at http://files.swaroopch.com/vim/byte_of_vim_v051.pdf - unfortunately the original sources are lost.

I welcome your contributions to complete the porting of text from the original PDF to this new book's sources at https://github.com/swaroopch/byte-of-vim .

Who reads A Byte of Vim?

Thanks to A Byte of Vim, I have learnt how to use vim. Thank you very much for this excellent book! ;) -- Camille L (France)

Well done!!! I've been only using vim for like 2/3 weeks now, and thus I can say that it's just perfect for beginners like me!!! -- Jay

The book is very good and fun to read too. Thank you for sharing it. -- Yosi Izaq

Your books should sell like hot cakes for their way of presentation. -- Deepak

Awesome! Thank you for all of your hard work. It is especially nice that the beginning starts the reader off gradually. After using vim for a couple of years I've forgotten how weird it seems at first, so I probably wouldn't explain it that good to someone. I will be sure to share your book to spread the vim propaganda. ;-) -- Joseph Sullivan

What I am trying to say is if you have basic computer competency you should immediately get Vim on your machine and improve your life. The best place to learn about is to read Swaroop C H's awesome eBook A Byte of Vim, it will revolutionize how you think about text editors in the future. -- "wooden nickels"

Have been thumbing through 'byte of vim'. learning a ton even having used vim for years. -- Josh Nichols

Great Book !! Although I use vim everyday as an editor as well as an ide, the book makes u realise how much more it can do. -- Raseel Bhagat

Wonderful! This was one most-required-book. I was a vim user for the past years, but never have seen these much of facilities inside that! Thanks for the Book, Swaroop! -- Hiran Venugopalan

What a nice book. I'm a long-time vim user, but never managed to get my head around vim scripting (apart from fixing some bugs in others' scripts). This is the best introduction to Vim scripting (writing plugins, syntax files, ...) I have seen so far. Thanks for putting it online! -- Anonymous (132.230.122.35)

Thank you Swaroop! I've begun reading it and must say it's very well written. And I have no doubts this great community of us vim users here will improve it through fixes, additions or small corrections. -- Eduard Fabra

I'd recommend A Byte of Vim as a good intro for new and experienced users alike. -- James Kovacs, Germany

Este libro me ayudó muchísimo a sacarle provecho a vim (This book helped me a lot to take advantage of vim) -- Antonio Touriño, Panamá

I have used vi for quite a while and am pretty comfortable with it. But all I do in vi is first get into insert mode and edit the file as if I am using notepad. I started searching for tutorials on vi and found one that is so simple yet so amazing. I thank Swaroop CH, yes the same guy who wrote the book A Byte of Python, for another amazing book A Byte of Vim. It was so amazing and I started using vi like a novice vimmer. -- Nishanth

A Byte of Vim saved my day once again... -- @reku

Also:

License

This book is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This means:

  • You are free to Share i.e. to copy, distribute and transmit this book
  • You are free to Remix i.e. to make changes to this book (especially translations)
  • You are free to use it for commercial purposes

Please note:

  • Please do not sell electronic or printed copies of the book unless you have clearly and prominently mentioned in the description that these copies are not from the original author of this book.
  • Attribution must be shown in the introductory description and front page of the document by linking back to http://vim.swaroopch.com/ and clearly indicating that the original text can be fetched from this location.
  • All the code/scripts provided in this book is licensed under the 3-clause BSD License unless otherwise noted.

Read Now

You can read it online at http://vim.swaroopch.com/

Buy The Book

A printed hardcopy of the book can be purchased at http://www.swaroopch.com/buybook/ for your offline reading pleasure, and to support the continued development and improvement of this book.

Download

Visit https://www.gitbook.com/book/swaroopch/byte-of-vim/details for the following types of downloads:

Visit https://github.com/swaroopch/byte-of-vim for the raw content (for suggesting corrections, changes, translating, etc.)

Read the book in your native language

If you are interested in reading or contributing translations of this book to other human languages, please see "Translations" chapter.

Introduction.1. Preface

About Vim

Vim is a computer program used for writing, and it provides a range of features that help you write better.

Why Vim?

Let's face it, it's very rare to produce your best work on the first attempt. Most likely, you will keep editing it frequently until it becomes 'good'.

As Louis Brandeis once said:

There is no great writing, only great rewriting.

Making these numerous rapid changes would be a lot easier if we had a capable editor to help us, and that is exactly where Vim shines, and is far better compared to most plain text editors and rich document editors.

Why Write This Book?

I have been using the Vim editor ever since I learned to use the old vi editor during Unix classes in college. Vim is one of the few pieces of software that I use for nearly 10 hours a day. I knew there were just so many features that I didn't know about but could potentially be useful to me, so I started exploring Vim little by little.

To crystallize my understanding and to help others also explore Vim, I started writing this collection of notes, and called it a book.

Some of the principles I have tried to keep in mind while writing these notes are:

  1. Simple literature. The importance of this should be reinforced again and again.
  2. Emphasis on examples and how-to.
  3. The one-stop shop for readers to learn Vim - from getting started to learning advanced stuff.
  4. Get the user to understand how to do things the Vim way - from modes to buffers to customization. Most people learn only the basic vi commands and do not attempt to learn anything beyond that. Learning such concepts is the tipping point, they become hardcore Vim users i.e. Vimmers, which means they extract the most out of Vim, which is the intent of this book.
  5. A lot of things are documented and stored here as a reference for people such as how to use Vim as an IDE, etc. There are various ways of doing it and instead of the user struggling to figure out which plugins to try out, the book already has the basic background work already for the reader.
  6. Just enough info to get you to understand and use, not everything required (Pareto principle)
  7. Relatedly, the book shouldn't attempt to rewrite the reference manual. Where appropriate, it should simply point out the relevant parts. This way, there is no redundancy, the user learns to use the awesome built-in reference manual which is important, and the book can stand on its own strengths as well.

To summarize, the mantra is Concepts. Examples. Pithy.

Status of the Book

The book was a work-in-progress and last updated in 2008. Eight years later (2016), I recreated the book in GitBook format. So let's just say it was a "1.0" book in 2008 :-)

Constructive suggestions are most welcome. Please send your thoughts and suggestions via email or github issues.

Official Website

The official website of the book is http://vim.swaroopch.com/ . From the website, you can read the whole book online or download the latest versions of the book, and also send me feedback.

Something To Think About

Books aren't written - they're rewritten. Including your own. It is one of the hardest things to accept, especially after the seventh rewrite hasn't quite done it. -- Michael Crichton

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. -- Antoine de Saint-Exupery

Introduction.2. Introduction

What is Vim?

Vim is a computer program used for writing any kind of text, whether it is your shopping list, a book, or software code.

What makes Vim special is that it is one of those few software which is both simple and powerful.

Simple means it is easy to get started with. Simple means that it has a minimalistic interface that helps you to concentrate on your main task - writing. Simple means it is built around few core concepts that helps you learn deeper functionality easily.

Powerful means getting things done faster, better and easier. Powerful means making not-so-simple things possible. Powerful does not mean it has to be complicated. Powerful means following the paradigm of "Minimal effort. Maximal effect."

What can Vim do?

I can hear you say, "So it's a text editor. What's the big deal anyway?"

Well, a lot.

Let's see some random examples to compare Vim with your current choice of editor. The point of this exercise is for you to answer the question "How would I do this in the editor I currently use?" for each example.

NOTE: Don't worry too much about the details of the Vim commands here, the point here is to enlighten you with the possibilities, not to start explaining how these things work. That is what the rest of the book is for.

Edit

In Vim

In your editor

How do you move the cursor down by 7 lines?

Press 7j

(Fill this column)

How do you delete a word? Yes, a "word"

Press dw

 

How do you search the current file for the current word that the cursor is at?

Press *

 

How to find and replace only in lines 50-100?

Run :50,10s/old/new/g

 

How to view two different parts of the same file simultaneously?

Run :sp to 'split' the view

 

The cursor is at a file name, how to jump to that file?

Press gf (which means 'g'o to 'f'ile)

 

Switch to a better theme?

Run :colorscheme desert to choose the deserttheme

 

How to map ctrl-s to save the file?

Run :nmap <c-s> :w<CR> (<CR> means 'c'arriage 'r'eturn, i.e. the enter key)

 

How to save the current set of open files & settings so that you can restart the session later?

Run :mksession ~/session.vim and then open Vim next time with vim -S ~/session.vim

 

How to see colors for different parts of your code?

Run :syntax on. If it doesn't recognize the language properly, use set ft=python for example.

 

How to hide different parts of the file so that you can concentrate on only one part at a time?

Run :set foldmethod=indent assuming your file is properly indented.

 

How to open multiple files in tabs?

Use :tabedit <file> to open multiple files in "tabs" (just like browser tabs), and use gt to switch between tabs

 

You use some words frequently in your document and wish there was a way that it could be quickly filled in the next time you use the same word?

Press ctrl-n to see the list of "completions" for the current word, based on all the words that you have used in the current document. Alternatively, use :ab mas Maslow's hierarchy of needs to expadn the abbreviation automatically when you type m a s <space>.

 

You have some data where only the first 10 characters in each line are useful and the rest is no longer useful for you. How do you get only that data?

Press ctrl-v, select the text and press y to copy the selected rows and columns of text.

 

What if you received a document from someone which is all in capitals, find it irritating and want to convert it to lower case?

(1) Run the following: :for i in range(0, line('$')) | call setline(i, tolower(getline(i))) | endfor
(2) Don't worry, details will be explored in later chapters. A more succinct way would be to run : %s#\\(.\\)#\\l\\1#g, but the first way would be simpler. (3) Select all the text using 1GVG and then using the uoperator to convert the selection to lowercase.

 

Phew. Are you convinced yet?

In these examples, you can see the power of Vim in action. Any other editor would make it insanely hard to achieve the same level of functionality. And yet, amazingly, all this power is made as understandable as possible.

Notice that we didn't use the mouse even once during these examples! This is a good thing. Count how many times you shift your hand between the keyboard and the mouse in a single day, and you'll realize why it is good to avoid it when possible.

Don't be overwhelmed by the features here. The best part of Vim is that you don't need to know all of these features to be productive with it, you just need to know a few basic concepts. After learning those basic concepts, all the other features can be easily learned when you need them.

Purchase this material to get access to the full version

Add to cart

Showing only first chapter for book preview.