0% found this document useful (0 votes)
58 views

Vim An Advanced Text Editor

This document provides an introduction to the vim text editor. It summarizes that vim is an advanced text editor that is modal, with command, insert, and ex modes. It then provides instructions on basic tasks like opening and saving files, navigating with keys, searching, replacing, and configuring vim permanently with a .vimrc file.

Uploaded by

Badi Ul Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Vim An Advanced Text Editor

This document provides an introduction to the vim text editor. It summarizes that vim is an advanced text editor that is modal, with command, insert, and ex modes. It then provides instructions on basic tasks like opening and saving files, navigating with keys, searching, replacing, and configuring vim permanently with a .vimrc file.

Uploaded by

Badi Ul Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

vim: An Advanced Text Editor

1
   Objectives
 Upon completion of this unit, you should be able to:
     
●Use the three primary modes of vi and vim
● Navigate text and enter Insert mode
● Change, delete, yank, and put text
● Undo changes
● Search a document
●  Save and exit

2
Introducing vim
●Newer version of vi, the standard Unix text 
editor
 Executing vi runs vim by default
● Advantages:
  Speed: Do more with fewer keystrokes
 Simplicity: No dependence on mouse/GUI
 Availability: Included with most Unix­like OSes
●Disadvantages
 Difficulty: Steeper learning curve than simpler
editors
3
vim: A Modal Editor
●Keystroke behavior is dependent upon vim's
"mode"
● Three main modes:
 Command Mode (default): Move cursor, 
cut/paste text, change mode
 Insert Mode: Modify text
Ex Mode: Save, quit, etc
● Esc exits current mode
● EscEsc always returns to command mode
4
vim Basics

● To use vim, you must at least be able to
Open a file
Modify a file (insert mode)
  Save a file (ex mode)

5
Opening a file in vim
●To start vi:
vim filename
 If the file exists, the file is opened and the 
contents are displayed
  If the file does not exist, vi creates it when 
the edits are saved for the first time

6
Modifying a File
Insert Mode
● i begins insert mode at the cursor
 Many other options exist
 A  append to end of line
      I   insert at beginning of line
     o  insert new a line (below)
     O  insert new line (above)

7
Saving a File and Exiting vim
ex mode
 Enter Ex Mode with :
 Creates a command prompt at bottom­left of 
screen
  Common write/quit commands:
:w writes (saves) the file to disk
:wq writes and quits
Ese ZZ  writes and quits
:x  exit saving changes
:w filename  save as a filename
:e filesname  edit filename
8
        :q! quits, even if changes are lost
 Using Command Mode

 Default mode of vim
   Keys describe movement and text manipulation 
commands
 Commands repeat when preceded by a number
  Example
 Right Arrow moves right one character
    5, Right Arrow moves right five characters

9
Moving Around
    Command Mode
 Move by character: Arrow Keys, h, j, k, l
 Non­arrow keys useful for remote connections to
older systems
 Move by word: w, b
 Move by sentence: ), (
Move by paragraph: }, {
           Jump to line x: xG
           Jump to end: G

10
Search and Replace
Command Mode
 Search as in less     r  /, n, N
 Search/Replace as in sed
  Affects current line by default
Use x,y ranges or % for whole file
:1,5s/cat/dog/
:%s/cat/dog/gi

11
Undoing Changes
Command Mode
  u undo most recent change
U undo all changes to the current line since
the cursor landed on the line
 Ctrl-r redo last "undone" change

12
Configuring vi and vim
  Configuring on the fly

:set or :set all


  Configuring permanently

~/.vimrc or ~/.exrc
   A few common configuration items

   :set number
:set autoindent
:set textwidth=65 (vim only)
:set wrapmargin=15
:set ignorecase
  Run :help option­list for a complete list 13
Learning more

  vi/vim built­in help
 :help
:help topic
Use :q to exit help
 vimtutor command

14

You might also like