185
Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim

Anindya Sen

Autumn 2011

October 19, 2011

Anindya (IITB) Vim October 19, 2011 1 / 19

Page 2: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 3: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 4: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 5: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 6: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modification

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 7: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 8: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 9: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)2 doc 96 Kb (21 Kb zipped)

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 10: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)2 doc 96 Kb (21 Kb zipped)3 txt 65 Kb (17 Kb zipped)

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 11: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)2 doc 96 Kb (21 Kb zipped)3 txt 65 Kb (17 Kb zipped)

Ease of indexing

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 12: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)2 doc 96 Kb (21 Kb zipped)3 txt 65 Kb (17 Kb zipped)

Ease of indexing

Syntax highlighting

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 13: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Why text editor? Motivation!!

Information access in a hurry

Ease of concatenation and splitting

True Read/Write Portability

Searchability

Ease of modificationEfficient storage

1 pdf 137 Kb (129 Kb zipped)2 doc 96 Kb (21 Kb zipped)3 txt 65 Kb (17 Kb zipped)

Ease of indexing

Syntax highlighting

Tool of last resort

Anindya (IITB) Vim October 19, 2011 2 / 19

Page 14: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 15: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source code

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 16: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentation

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 17: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mail

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 18: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mailetc.

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 19: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mailetc.

But you don’t have enough time!

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 20: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mailetc.

But you don’t have enough time!

You want to get more work done in less time :-)

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 21: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mailetc.

But you don’t have enough time!

You want to get more work done in less time :-)

Next hour or so will show you how

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 22: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Editing text

You edit lots of text

Program source codeDocumentationE-mailetc.

But you don’t have enough time!

You want to get more work done in less time :-)

Next hour or so will show you how

Selecting a good editor (e.g. vim, emacs) is the first step. In thistalk, we will be focussing on vim!

Anindya (IITB) Vim October 19, 2011 3 / 19

Page 23: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command mode

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 24: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of text

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 25: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim starts

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 26: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim startsGet back using the ‘Esc’ key

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 27: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim startsGet back using the ‘Esc’ key

Input/Edit mode

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 28: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim startsGet back using the ‘Esc’ key

Input/Edit modeFor editing text!

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 29: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim startsGet back using the ‘Esc’ key

Input/Edit modeFor editing text!Multiple keys for different tasks e.g. insert (i/I), open(o/O), append(a/A), change(c/C), replace (r/R)

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 30: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Modal” editor

Vim is a finite automaton, with states

Command modeFor navigation and manipulation of textDefault mode in which vim startsGet back using the ‘Esc’ key

Input/Edit modeFor editing text!Multiple keys for different tasks e.g. insert (i/I), open(o/O), append(a/A), change(c/C), replace (r/R)Works just like a “normal” text editor :-)

Anindya (IITB) Vim October 19, 2011 4 / 19

Page 31: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line mode

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 32: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vim

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 33: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vimPress ‘:’ to enter

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 34: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vimPress ‘:’ to enter

Visual mode

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 35: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vimPress ‘:’ to enter

Visual modeFor navigation and manipulation of text selections

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 36: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vimPress ‘:’ to enter

Visual modeFor navigation and manipulation of text selectionsUsually enter from command mode by pressing “v”, “Ctrl-V” or“Shift-V”

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 37: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

A “Moded” editor (Cont . . . )

Command-line modeFor entering editor commands, reading/writing files, exiting vimPress ‘:’ to enter

Visual modeFor navigation and manipulation of text selectionsUsually enter from command mode by pressing “v”, “Ctrl-V” or“Shift-V”Possible to select columns (block-visual mode)!

Anindya (IITB) Vim October 19, 2011 5 / 19

Page 38: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 39: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 40: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 41: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 42: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

T he not so quick brown fox jumps over the lazy dog.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 43: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

The n ot so quick brown fox jumps over the lazy dog.w

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 44: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

The q uick brown fox jumps over the lazy dog.2 d w

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 45: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

Again : The quick brown fox jumps over the lazy dog.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 46: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

T he not so quick brown fox jumps over the lazy dog.

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 47: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

The n ot so quick brown fox jumps over the lazy dog.fn

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 48: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Powerful commands can be created out of a combination ofsimple components :

Basic Commands — cut, copy, paste, convert to uppercase etc.Motion — move to beginning/end-of line/paragraph/file, jump to firstoccurrence of character ’f’ in line or word ‘foo’ in file.Count — Number of repetitions of a basic command.

Example

The q uick brown fox jumps over the lazy dog.d fq

Anindya (IITB) Vim October 19, 2011 6 / 19

Page 49: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Switch modes

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 50: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Switch modesInsert (i/I)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 51: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Switch modesInsert (i/I)Replace/Overwrite (R)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 52: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Switch modesInsert (i/I)Replace/Overwrite (R)Append (a/A)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 53: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Switch modesInsert (i/I)Replace/Overwrite (R)Append (a/A)Open a new line (o/O)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 54: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Operate

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 55: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

OperateReplace char (r)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 56: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

OperateReplace char (r)Delete (d/D)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 57: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

OperateReplace char (r)Delete (d/D)Yank (y/Y)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 58: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

OperateReplace char (r)Delete (d/D)Yank (y/Y)Paste (p/P)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 59: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Operate & switch modes

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 60: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Operate & switch modesReplace and insert (s/S)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 61: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Operate & switch modesReplace and insert (s/S)Delete and insert = Change (c/C)

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 62: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Some commands are not really basic i.e. they can be composedof simpler commands. Still, they help reduce typing effort

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 63: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Some commands are not really basic i.e. they can be composedof simpler commands. Still, they help reduce typing effort

a = l + i

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 64: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Some commands are not really basic i.e. they can be composedof simpler commands. Still, they help reduce typing effort

a = l + is = x + i

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 65: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Some commands are not really basic i.e. they can be composedof simpler commands. Still, they help reduce typing effort

a = l + is = x + ic =

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 66: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Basic Commands

All the commands work only in Command/Escape Mode.

Some commands are not really basic i.e. they can be composedof simpler commands. Still, they help reduce typing effort

a = l + is = x + ic = d + i

Anindya (IITB) Vim October 19, 2011 7 / 19

Page 67: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Cursor movements

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut on ce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 68: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Cursor movements↑ (k)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 69: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Cursor movements↑ (k)↓ (j)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut on ce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 70: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Cursor movements↑ (k)↓ (j)← (h)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut o nce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 71: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Cursor movements↑ (k)↓ (j)← (h)→ (l)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut on ce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 72: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Word movements

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut on ce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 73: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Word movementsForward (w/W)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once t he user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 74: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Word movementsForward (w/W)Backward (b/B )

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut o nce the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 75: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Word movementsForward (w/W)Backward (b/B )End-of-word (e/E)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 76: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Line movements

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 77: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Line movementsEnd ($)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 78: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Line movementsEnd ($)Beginning (/̂ 0)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallyb ut once the user gets a grasp of the basics they progress quickly and their

editing becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 79: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Line movementsEnd ($)Beginning (/̂ 0)Land on char ‘p’ (f/F p )

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 80: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Line movementsEnd ($)Beginning (/̂ 0)Land on char ‘p’ (f/F p )Land just before char ‘c’ (t/T c )

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basi cs they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 81: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Sentence movements

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basi cs they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 82: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Sentence movementsBeginning of sentence (()

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.V im is said to have a steep learning curve, meaning learning is slow initially

but once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 83: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

Sentence movementsBeginning of sentence (()Beginning of next sentence ())

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. T o facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 84: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

File movements

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. T o facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 85: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

File movementsBeginning of file (gg )

Example

L earning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 86: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

File movementsBeginning of file (gg )End of file (G)

Example

Learning to use VimVim, which stands for Vi IMproved, is an open-source, multiplatform texteditor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 87: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

File movementsBeginning of file (gg )End of file (G)Line number 2 in file (2 G)

Example

Learning to use VimV im, which stands for Vi IMproved, is an open-source, multiplatform text

editor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 88: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Review of Motion Commands

and many more . . .

Moving to a mark ‘a’ in file (’a)Moving to a matching brace (%)Beginning/End of paragraph ({/} )etc.

Example

Learning to use VimV im, which stands for Vi IMproved, is an open-source, multiplatform text

editor extended from vi. It was first released by Bram Moolenaar in 1991.Vim is said to have a steep learning curve, meaning learning is slow initiallybut once the user gets a grasp of the basics they progress quickly and theirediting becomes more efficient. To facilitate this there’s the vim tutorial forbeginners, usually invoked by typing “vimtutor” on the Unix command line.- Vim on Wikipedia

Anindya (IITB) Vim October 19, 2011 8 / 19

Page 89: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete a word?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 90: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete a word?dw

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 91: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Two words?OR

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 92: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Two words?2dw OR

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 93: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Two words?2dw OR d2w

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 94: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete till end of line?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 95: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete till end of line?d$

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 96: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete till end of file?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 97: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete till end of file?dG

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 98: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete all text till the first occurrence of ‘foo’?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 99: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete all text till the first occurrence of ‘foo’?d/foo

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 100: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete the parameters in “void_func(a,b,c,d)”?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 101: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete the parameters in “void_func(a,b,c,d)”?fa

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 102: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Delete the parameters in “void_func(a,b,c,d)”?fa dt)

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 103: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Yank 8 lines of text?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 104: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Yank 8 lines of text?8yy

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 105: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

And paste two copies of the same text at the end of file?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 106: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

And paste two copies of the same text at the end of file?G

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 107: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

And paste two copies of the same text at the end of file?G 2p

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 108: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Yank 8 lines of text above the current line?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 109: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Yank 8 lines of text above the current line?7yk

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 110: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Indenting (=) a block of code?

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 111: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Indenting (=) a block of code?f{

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 112: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Indenting (=) a block of code?f{ =%

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 113: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim = Count + Command + Motion

Let’s play around with vim’s capabilities :

Example

Indenting (=) a block of code?f{ =%

Notes

Viewing a piece of text in terms of its constituent logical units rather asan ensemble of characters on screen

Anindya (IITB) Vim October 19, 2011 9 / 19

Page 114: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 115: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire file

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 116: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 117: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Flags

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 118: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Flags

No flag — change first occurrence in current line

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 119: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Flags

No flag — change first occurrence in current lineg — changes all occurrences in current line

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 120: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Flags

No flag — change first occurrence in current lineg — changes all occurrences in current linec — confirm each change before committing

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 121: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Replacing text

Ex command : :[range]s/< old>/<new>/[flags] to replace text

Range

% — entire fileN1,N2 — changes restricted to lines between N1 and N2, bothinclusive. In visual mode, N1 and N2 are auto-generated from thestart and end of selection

Flags

No flag — change first occurrence in current lineg — changes all occurrences in current linec — confirm each change before committingi/I — Ignore / Don’t ignore case for this pattern

Anindya (IITB) Vim October 19, 2011 10 / 19

Page 122: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Warning

Vim is addictive. Use it at your own risk!

Anindya (IITB) Vim October 19, 2011 11 / 19

Page 123: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 124: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Programming Language Support — For all major languages suchas C*, Java, Perl, Python, Tcl, Ruby, PHP and many more.

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 125: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Programming Language Support — For all major languages suchas C*, Java, Perl, Python, Tcl, Ruby, PHP and many more.

Syntax Highlighting

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 126: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Programming Language Support — For all major languages suchas C*, Java, Perl, Python, Tcl, Ruby, PHP and many more.

Syntax HighlightingSmart Indentation

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 127: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Programming Language Support — For all major languages suchas C*, Java, Perl, Python, Tcl, Ruby, PHP and many more.

Syntax HighlightingSmart IndentationFor new languages, its possible to write a script for specifyingkeywords and indentation rules.

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 128: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

A vast collection of built-in tools (word completions, indentation,etc.) as well as interfaces to well known tools (make, grep etc.).

Programming Language Support — For all major languages suchas C*, Java, Perl, Python, Tcl, Ruby, PHP and many more.

Syntax HighlightingSmart IndentationFor new languages, its possible to write a script for specifyingkeywords and indentation rules.

Powerful navigation techniques to aid source code comprehensionand editing.

Anindya (IITB) Vim October 19, 2011 12 / 19

Page 129: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Search for keyword ‘foo’ — Use *

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 130: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Search for keyword ‘foo’ — Use *

Cursor should be “within” foo

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 131: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Search for keyword ‘foo’ — Use *

Cursor should be “within” foo∗ = /\ < foo \ >

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 132: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Search for keyword ‘foo’ — Use *

Cursor should be “within” foo∗ = /\ < foo \ >Not too useful if many occurrences in file. Use n to cycle throughmatches.

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 133: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Search for keyword ‘foo’ — Use *

Cursor should be “within” foo∗ = /\ < foo \ >Not too useful if many occurrences in file. Use n to cycle throughmatches.Use ctags instead

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 134: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Go straight to the definition of a function — Use Ctrl-]

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 135: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Go straight to the definition of a function — Use Ctrl-]

Need external program called ctags-exuberant

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 136: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Go straight to the definition of a function — Use Ctrl-]

Need external program called ctags-exuberantctags stores references to all functions, variables in a tags file

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 137: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Go straight to the definition of a function — Use Ctrl-]

Need external program called ctags-exuberantctags stores references to all functions, variables in a tags fileNeed not worry if the function is defined in a different file

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 138: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Go straight to the definition of a function — Use Ctrl-]

Need external program called ctags-exuberantctags stores references to all functions, variables in a tags fileNeed not worry if the function is defined in a different file

“But how do I return to where I was earlier?” — Use Ctrl-o andCtrl-i to navigate (back and forth) through the source code. Reallyuseful!

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 139: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 140: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

:e <file> opens file in same window.

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 141: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

:e <file> opens file in same window.:e # toggles between previous and current file

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 142: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

:e <file> opens file in same window.:e # toggles between previous and current file:ls gives a list of all buffers

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 143: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

:e <file> opens file in same window.:e # toggles between previous and current file:ls gives a list of all buffers:buf <n> opens buffer number n (Order provided by :ls )

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 144: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Moving around quickly

Switching between files quickly — Use the ex commands

:e <file> opens file in same window.:e # toggles between previous and current file:ls gives a list of all buffers:buf <n> opens buffer number n (Order provided by :ls )gf opens filename under cursor

Anindya (IITB) Vim October 19, 2011 13 / 19

Page 145: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 146: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Quick fix — Vim’s support for navigating through grep or make ’soutput/error list. Very useful during the code-compile-run cycle

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 147: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Quick fix — Vim’s support for navigating through grep or make ’soutput/error list. Very useful during the code-compile-run cycle

Captures output of grep/make in a buffer

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 148: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Quick fix — Vim’s support for navigating through grep or make ’soutput/error list. Very useful during the code-compile-run cycle

Captures output of grep/make in a buffer:clist lists all messages

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 149: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Quick fix — Vim’s support for navigating through grep or make ’soutput/error list. Very useful during the code-compile-run cycle

Captures output of grep/make in a buffer:clist lists all messages:cnext /:cprev takes you to line in code corres to next/prevmessage (error/match)

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 150: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Running external commands from within vim

To run a shell command, simply use :!<cmd> . For frequently usedcmds (e.g. cd , make , grep ), drop the !

Quick fix — Vim’s support for navigating through grep or make ’soutput/error list. Very useful during the code-compile-run cycle

Captures output of grep/make in a buffer:clist lists all messages:cnext /:cprev takes you to line in code corres to next/prevmessage (error/match):copen shows the buffer in a split window — Hitting enter on anymessage line in that buffer takes you to the line in code corres tothat message.

Anindya (IITB) Vim October 19, 2011 14 / 19

Page 151: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 152: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 153: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 154: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Folding — Automatically “fold” and “unfold” a region of text

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 155: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Folding — Automatically “fold” and “unfold” a region of text

Collapse all procedures other than current one — Use :setfoldmethod=indent

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 156: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Folding — Automatically “fold” and “unfold” a region of text

Collapse all procedures other than current one — Use :setfoldmethod=indentHide commented out code — :set foldmethod=manual /\/\∗ zf%

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 157: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Folding — Automatically “fold” and “unfold” a region of text

Collapse all procedures other than current one — Use :setfoldmethod=indentHide commented out code — :set foldmethod=manual /\/\∗ zf%

Man Page Lookup — Use K to view the manpage of the wordunder cursor

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 158: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim — A Programmer’s Delight

Other programming essentials

Autocompletion — Use Ctrl-n & Ctrl-p to cycle through theoptions→Works only in Insert mode

Don’t type “this_is_a_long_procedure_name( )” more than once!

Indentation — Use = to indent a block of code

Folding — Automatically “fold” and “unfold” a region of text

Collapse all procedures other than current one — Use :setfoldmethod=indentHide commented out code — :set foldmethod=manual /\/\∗ zf%

Man Page Lookup — Use K to view the manpage of the wordunder cursor

Vimdiff — To view the output of diff

Anindya (IITB) Vim October 19, 2011 15 / 19

Page 159: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 160: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 161: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

set ignorecase — No need to use /[Ww]or[dD]

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 162: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

set ignorecase — No need to use /[Ww]or[dD]

But what if I really want to search for WorD and not the others? —

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 163: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

set ignorecase — No need to use /[Ww]or[dD]

But what if I really want to search for WorD and not the others? —Just add set smartcase to your vimrc!

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 164: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

set ignorecase — No need to use /[Ww]or[dD]

But what if I really want to search for WorD and not the others? —Just add set smartcase to your vimrc!

set expandtabs — Tab-presses are replaced by N spaces, whereN is set using set tabstop = N

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 165: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

vimrc

RC file for setting options globally. Read by Vim during startup

set background = dark/light — Vim chooses foreground colorsto match the background

set incsearch — No need to type the entire search string. Canalso highlight search term using set hlsearch

set ignorecase — No need to use /[Ww]or[dD]

But what if I really want to search for WorD and not the others? —Just add set smartcase to your vimrc!

set expandtabs — Tab-presses are replaced by N spaces, whereN is set using set tabstop = N

Doesn’t work with make! — Need to handle makefiles separately

Anindya (IITB) Vim October 19, 2011 16 / 19

Page 166: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 167: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 168: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Editing source code (C,C++,Perl,Tcl)

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 169: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Editing source code (C,C++,Perl,Tcl)

Writing e-mails (vim and mutt work together nicely)

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 170: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Editing source code (C,C++,Perl,Tcl)

Writing e-mails (vim and mutt work together nicely)

Editing bash commands on-the-fly (set -o vi )

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 171: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Editing source code (C,C++,Perl,Tcl)

Writing e-mails (vim and mutt work together nicely)

Editing bash commands on-the-fly (set -o vi )

Editing unix configuration files

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 172: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

I use(d) vim for :

Preparing this presentation (using Latex packages)!

Editing source code (C,C++,Perl,Tcl)

Writing e-mails (vim and mutt work together nicely)

Editing bash commands on-the-fly (set -o vi )

Editing unix configuration files

and many more day-to-day editing tasks . . .

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 173: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 174: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

G :r <filename> will append contents of <filename> to current file.

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 175: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

G :r <filename> will append contents of <filename> to current file.Combine :r with :! (external command execution) e.g. :r!dateinserts current date

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 176: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

G :r <filename> will append contents of <filename> to current file.Combine :r with :! (external command execution) e.g. :r!dateinserts current date

Combine selection of a region of text in Visual mode with :! to runexternal commands on that region

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 177: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

G :r <filename> will append contents of <filename> to current file.Combine :r with :! (external command execution) e.g. :r!dateinserts current date

Combine selection of a region of text in Visual mode with :! to runexternal commands on that region

:’<,’>!sort to sort contents in place

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 178: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:r <buffer> — Read the contents of a buffer at the location ofcursor.

G :r <filename> will append contents of <filename> to current file.Combine :r with :! (external command execution) e.g. :r!dateinserts current date

Combine selection of a region of text in Visual mode with :! to runexternal commands on that region

:’<,’>!sort to sort contents in place:’<,’>!wc to count number of characters/words in a single paragraph

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 179: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:abbrev <sh> <long string here> — saves ty(ping) and correctsspelling mistaeks mistakes. Can be added to .vimrc file too

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 180: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:abbrev <sh> <long string here> — saves ty(ping) and correctsspelling mistaeks mistakes. Can be added to .vimrc file too

How to underline a long line of text ? — use yy p :s/./-/g

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 181: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:abbrev <sh> <long string here> — saves ty(ping) and correctsspelling mistaeks mistakes. Can be added to .vimrc file too

How to underline a long line of text ? — use yy p :s/./-/g

Repeat previous change cmd using . (dot)

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 182: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

These are a few of my favorite commands

:abbrev <sh> <long string here> — saves ty(ping) and correctsspelling mistaeks mistakes. Can be added to .vimrc file too

How to underline a long line of text ? — use yy p :s/./-/g

Repeat previous change cmd using . (dot)

Repeat line movement (f/F/t/T ) using ; (semi-colon) or , (comma)

Anindya (IITB) Vim October 19, 2011 17 / 19

Page 183: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim Capability Improvement Program (VIMCIP) :-)

Anindya (IITB) Vim October 19, 2011 18 / 19

Page 184: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Vim Capability Improvement Program

“vimtutor ” on bash prompt — a gentle introduction to Vim

“Seven habits of effective text editing”(http://www.moolenaar.net/habits.pdf)

:h [topic] provides on-line help. Navigation is very easy usingtags and Ctrl-o / Ctrl-i cmds

Vimbook (http://ntu.csie.org/ piaip/vim/vimbook-OPL.pdf)

“Mastering Regular Expressions”(http://www.oreilly.com/catalog/regex/)

“Vi Macros, Abbreviations, and Buffers”(http://www.npa.uiuc.edu/docs/vi.macros)

“Best of VIM Tips”(http://gav.brokentrain.net/projects/vimtips/vimtips.pdf )

“Vim Quick Reference Card”

Anindya (IITB) Vim October 19, 2011 18 / 19

Page 185: Anindya Sen - IIT Bombayanindya/tutorials/vim_tut.pdf · 2014. 9. 22. · Vim Anindya Sen Autumn 2011 October 19, 2011 Anindya (IITB) Vim October 19, 2011 1 / 19

Happy Vimming!

Anindya (IITB) Vim October 19, 2011 19 / 19