SlideShare a Scribd company logo
VI - EDITOR
INTODUCTION TO VIM
• vi → The standard Unix text editor
• vim → vi improved is a powerful text editor
• gvim → Graphical version of vim
• Advantages of Vi / Vim :
– Speed : Do more with fewer keystrokes
– Simplicity : No dependence on mouse/GUI
– Availability : Included with most Unix / Linux Distro
• Disadvantages of Vi/Vim :
– Difficult : Steeper learning curve than simpler editors
VI MODES OF WORKING
• Keystroke behavior is dependent upon vim's "mode"
• Three main modes:
– Command Mode (default) : Move cursor, cut / copy / paste /
or delete text in file
– Insert Mode : Modify text in file
– Ex Mode : Save, Quit, Customize etc
• <Esc key > : exits current mode into
command mode.
• NOTE : When in doubt press Escape key, you will be back in
command mode
OPEN A FILE IN VI / VIM
• To start vi / vim :
– # vim filename
– # vi +number filename ( open file and put cursor at line number
specified )
• 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
• By default vi has unnamed temporary buffer where file is edited
MODIFY A FILE : INSERT MODE
• INSERT MODE → To insert the text in file we should be in Insert
mode
– i → inserts the text before cursor location
– I → insert at beginning of line
– a → inserts text after cursor location
– A → insert at end of line
– I → insert at beginning of line
– o → insert new line (below)
– O → insert new line (above)
– S → deletes the character under cursor and get into insert
mode
MODIFY A FILE : REPLACING TEXT
• ONE CHARACTER AT A TIME → Replacing text also happens in
insert mode as follows :
– r → replace a single character
– R → replace multiple char( will be in replace mode )
SAVE & EXIT FILE : EX MODE
• Enter Ex Mode by pressing → :
– Creates a command prompt at bottom-left of screen
• Common write/quit commands :
– :q <enter key> → quits the vi only if no changes have been made
to the file being edited
– :q! <enter key> → quits the vi without making any changes in file
– :w <enter key> → writes (saves) the file to disk only
– :wq <enter key> → writes the buffer and quits vi
– :ZZ <enter key> → writes the buffer and quits vi
– :x <enter key> → writes and quits
WRITE TO FILE : EX MODE
• Common write commands :
– :w <enter key> → writes (saves) the file to disk only
– :wq <enter key> → writes the buffer and quits vi
– :f <filename> → renames current file to filename
– :w <filename> → write the file to path / filename given
– :w>> filename → append current file to the filename given
– :5,10w filename → write lines 5 through 10 to the filename given
– :5,10w>>filename→ append lines 5 through 10 to the filename given
– :r <filename> → read a copy of file into current file at cursor
positon
– :e <filename> → opens another file with filename
– :e# <enter key> → switch between the open vi windows ******** (this
works after saving the file once on disk using :w )
USING COMMAND MODE
• Default mode of vim
• Keys describe movement and text manipulation commands
• Commands repeat when preceded by a numberCommands repeat when preceded by a number
• Example
– Right Arrow : moves right 1 character
– 5 followed by Right Arrow : moves right 5 characters
MOVING AROUND : COMMAND MODE
• Move by character : Arrow Keys, h, j, k, l
( Non-arrow keys useful for remote connections to older systems )
MOVING AROUND : COMMAND MODE
• MOVE BY WORD
• w : moves the cursor forward one word
• b : moves cursor back one word
• e : moves cursor to the end of current word
• MOVE BY LINE
• ^ : moves cursor to the beginning of current line
• $ : moves to the end of current line
• MOVE BY SENTENCE
• ( : moves to the beginning of previous sentence
• ) : moves to the end of next sentence
MOVING AROUND : COMMAND MODE
• MOVE BY PARAGRAPH
• { : moves to the beginning of previous paragraph
• } : moves to the end of next paragraph
• MOVE BY SCREEN
• <ctrl>f : moves forward one screen
• <ctrl>b : moves back one screen
• <ctrl>d : moves down half screen
• <ctrl>u : moves up half screen
• H : first line on screen
• M : middle line on the screen
• L : last line on the screen
MOVING AROUND : COMMAND MODE
• MOVE INSIDE WHOLE DOCUMENT
• nG : move to nth line of file (****in command mode*****)
• :n : move to nth line of file (****in ex mode****)
• 1G : first line of the document / file
• G : last line of the file
• 25G : 25th
line of the file ( in command mode )
• :25 : 25th
line of the file ( in ex mode )
SEARCH : EX MODE
• Same implementation as in less editor
• /<pattern> – search forward in buffer for next occurrence of the
pattern of text.
• ?<pattern> – search backwards
• n – Repeats the last search command
• N – Repeats the search command in opposite
direction
• We can use regular expression in searches
SUBSTITUTION : EX MODE
• By default substitute the first occurrence of text on current line
– : s/file/book/ ( first occurrence of file with book on current
line )
– :s/file/book/g ( all the occurrence of file with book on
current line )
• Use x,y ranges
– :1,5s/cat/dog/ ( first occurrence of cat with dog between
line 1 to line 5 )
– :1,5s/cat/dog/g ( all occurrence of cat with dog between line
1 to line 5 )
• Use % for whole file
– :%s/cat/dog/ ( substitute first occurrence of cat with dog in
full file )
– :%s/cat/dog/g ( substitute all occurrence of cat with dog in
full file )
– :%s/cat/dog/gc ( c → prompt before each substitution )
DELETING TEXT : COMMAND MODE
• DELETING SINGLE CHARACTERS
– x → Deletes a character at current cursor position
– 3x → Deletes the character currently under cursor
followed bye two
– Nx → Deletes n-1 characters on right of cursor position
– X → Deletes a character to the left of the cursor
• NOTE : Deleting puts the text in unnamed temporary
buffer which can be used for paste operation at
other place, and thus becomes cut paste *******
DELETING TEXT : COMMAND MODE
• DELETING LARGER CHUNKS
– dw → deletes a word (or part of a word) from the cursor to the next
space or to the next punctuation.
– db → delete one word backwards
– d$ → deletes the current line from the cursor to the end of the line
– d^ → deletes the current line from the cursor to the beginning of the
line
– d0 → same as d^
– d) → delete one sentence forward
– d( → delete one sentence backwards
– dG → delete from current line to the end of file
– dgg → delete from current line to the beginning of file
– dd → deletes the current line *******
– ndw → deletes n words from current cursor position
– ndd → deletes n lines from current line *******
COPY TEXT : COMMAND MODE
• COPY / YANKING → yank command puts the text in temp buffer for copy
– yw → yank a word forward
– yb → one word backwards
– y$ → yank the current line from the cursor to the end of the line
– y^ → yank the current line from the cursor to the beginning of the
line
– y0 → same as d^
– y) → yank one sentence forward
– y( → yank one sentence backwards
– yG → yank from current line to the end of file
– ygg → yank from current line to the beginning of file
– yy → yank the current line *******
– nyw → yank n words from current cursor position
– nyy → yank n lines from current line *******
– 20yy → yank 20 lines from current line *******
• P → 'PUT' comman for paste operation, place the contents
of the unnamed buffer back into the file. ( Buffered content
of delete & yank command )
– p → Paste the content below the current line
– P → Paste the content above the current line
PASTE TEXT : COMMAND MODE
UNDO 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
USING MULTIPLE “WINDOWS”
• View multiple documents in a single vim screen.
– Ctrl-w followed by s → s splits the screen horizontally
– Ctrl-w followed by v → v splits the screen vertically
– Ctrl-w followed by arrow → Arrow moves between windows
– Ctrl-w followed by q → quit / close open windows
• Ex-mode instructions always affect the current window
• :help windows displays more window commands
CUSTOMIZING VI SESSION
• A few common configuration items
– :set all - Display all options
– :set - Display current setting of
options
– :set number / :set nu - Display line numbers
– ( This can be useful when deleting or substituting selected text
as follows )
– :2,10d - Delete line 2 to 10
– :1,10s/foo/bar/g - Substitute foo with bar
from line 1 to 10
– :set nonumber / :set nonu - Hide line numbers
CUSTOMIZING VI SESSION
• A few common configuration items
– :set all - Display all options
– :set - Display current setting of
options
– :set autoindent or :set ai - Turn on autoindenting
– :set textwidth=65 (vim only)
– :set wrapmargin=15 / :set wm=15 - Set wrap margin 15
spaces from right edge
of screen
– :set wrapmargin=0 / :set wm=0 - Turn off Wrap margin
– :set ignorecase or :set ic - Set ignore case during
searches
– :syntax on - Turn on syntax
highlighting
– :syntax off - Turn off syntax
hightlighting
CUSTOMIZING VI SESSION
• Options can be set in the following ways
– During a vi session
• :set nu / :set nonu ...etc ( preserve setting for that session)
– For permanent setting for a user.
• Create either ~/.vimrc or ~/.exrc file in user home directory
Sample contents of .exrc are →
set nu
set ai
set wm=10
ABBREVIATIONS
• ABBREVIATIONS → are text strings which automatically expand
to larger string when used in Insert Mode ( use .vimrc for
permanent changes )
• To add an abbreviation
– :ab UW University of Delhi
(Now if in insert mode I enter UW it be expanded to University of
Delhi on entering any non-alphanumeric character)
• To list currently defined abbreviations
– :ab
• To disable / delete an abbreviation use the :unab command
– :unab UW → clears the given abbreviation
– :abc → clear all the set abbreviation
MAPPING
• MAPPING → any key can be mapped as shortcut for command.
( For making permanent changes use .vimrc )
• To add a key map
– :map – dd (it creates a key map that works in command mode)
– :map! @ dd (it creates a key map that works in insert mode)
• To list currently defined map keys
– :map
– :map!
• To remove a keymap
– :unmap -
– :unmap @
USEFUL TIPS
• Launch vi and begin editing <filename> at line 125
– # vi +125 <filename>
• Launch vi and edit multiple files
– # vi <file1> <file2> (switch to next file using :n)
• Change case of character under cursor
– ~ ( press tilde key at current cursor positon)
• Join the current line and the next line
– J ( capital J in command mode )
• Remove null lines in the file
– : g/^$/d
• List all occurrences of the word 'foo' with line numbers
– :g/foo/#
• Read output from a Unix shell command into current text
– :r !<command>
USEFUL TIPS
• Get the line number of current cursor positon
– Ctrl + g
• Repeats the action performed by last command
– . ( press . In command mode )
• Temporarily returns to the shell to perform shell commands
– :sh ( Type exit to return to vi )
• Execute a command from vi editor ex mode
– :! <command>
LEARNING MORE
• vi/vim built-in help
• :help topic
• :help
• Use :q to exit help
• vimtutor command
• NOTE → USERS WITH UIDs > 200 WHEN TYPE VI WILL
GET VIM EDITOR ( Because of alias of vi )
?

More Related Content

PPT
Vi editor in linux
PDF
Archiving in linux tar
PPT
Basic command ppt
PPTX
VI editor in unix
PPT
06 users groups_and_permissions
PDF
Linux Basic Commands
PPTX
Filepermissions in linux
PDF
Vi editor Linux Editors
Vi editor in linux
Archiving in linux tar
Basic command ppt
VI editor in unix
06 users groups_and_permissions
Linux Basic Commands
Filepermissions in linux
Vi editor Linux Editors

What's hot (20)

PPTX
Vi editor
PPTX
File permission in linux
PPT
Basic 50 linus command
PPT
Linux file system
PDF
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
PPTX
PPT
Linux basic commands
PPTX
User and groups administrator
PPTX
Linux standard file system
PPTX
Know the UNIX Commands
PPT
Introduction to Linux Kernel by Quontra Solutions
PPTX
Unix Linux Commands Presentation 2013
PPTX
Linux security
PDF
Linux cheat-sheet
PDF
Lesson 2 Understanding Linux File System
PDF
File permission of linux
PDF
An Introduction To Linux
PPTX
Linux kernel
PPTX
User management
PDF
Linux File System
Vi editor
File permission in linux
Basic 50 linus command
Linux file system
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Linux basic commands
User and groups administrator
Linux standard file system
Know the UNIX Commands
Introduction to Linux Kernel by Quontra Solutions
Unix Linux Commands Presentation 2013
Linux security
Linux cheat-sheet
Lesson 2 Understanding Linux File System
File permission of linux
An Introduction To Linux
Linux kernel
User management
Linux File System
Ad

Viewers also liked (20)

PPTX
Vi editor
PPTX
PDF
The "vi" Text Editor
ODP
Linux commands
ODP
Linux Introduction (Commands)
PPTX
Unix operating system
PPT
Unix Internals OS Architecture
ODP
Even internet computers want to be free: Using Linux and open source software...
PDF
Using VI Editor in Red Hat by Rohit Kumar
PPT
1359 Vi Editor
PPT
Introduction to vi editor
PPT
MySQL and its basic commands
DOCX
Introduction to unix
PPT
Php File Operations
PPTX
Linux files
PDF
PPSX
PHP Comprehensive Overview
PPT
PDF
Linux Network commands
PPT
Linux ppt
Vi editor
The "vi" Text Editor
Linux commands
Linux Introduction (Commands)
Unix operating system
Unix Internals OS Architecture
Even internet computers want to be free: Using Linux and open source software...
Using VI Editor in Red Hat by Rohit Kumar
1359 Vi Editor
Introduction to vi editor
MySQL and its basic commands
Introduction to unix
Php File Operations
Linux files
PHP Comprehensive Overview
Linux Network commands
Linux ppt
Ad

Similar to Vi Editor (20)

PPTX
Vi Vi Editor Unit 4 Power point presentation
PDF
Linux text editors
PDF
Linux text editors Vim nano
PPTX
Linux Text Editor (Vi) Command List Summary
PDF
1_Editors_in_Unix
PDF
Vi reference
PDF
Vi reference
DOC
Qc document draft
PPTX
VI Editor - R.D.Sivakumar
PPT
07 vi text_editor
PDF
Tuffarsi in vim
PPT
VI Editors
PDF
Mission vim possible-full
PPTX
PDF
Vi editor commands
PDF
Vi cheat sheet
PDF
Vi cheat sheet
PDF
Using vi editor
PPT
Mastering the Linux vi Editor: Essential Commands and Techniques
PDF
Vi Vi Editor Unit 4 Power point presentation
Linux text editors
Linux text editors Vim nano
Linux Text Editor (Vi) Command List Summary
1_Editors_in_Unix
Vi reference
Vi reference
Qc document draft
VI Editor - R.D.Sivakumar
07 vi text_editor
Tuffarsi in vim
VI Editors
Mission vim possible-full
Vi editor commands
Vi cheat sheet
Vi cheat sheet
Using vi editor
Mastering the Linux vi Editor: Essential Commands and Techniques

More from Shiwang Kalkhanda (7)

PDF
Why linux is better than windows
PDF
Intro to operating_system
PDF
Intro to libre_office
PDF
Intro to open_source
PDF
History of linux
PDF
Cryptoparty Handbook
PDF
Before begining linux
Why linux is better than windows
Intro to operating_system
Intro to libre_office
Intro to open_source
History of linux
Cryptoparty Handbook
Before begining linux

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Big Data Technologies - Introduction.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Big Data Technologies - Introduction.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Dropbox Q2 2025 Financial Results & Investor Presentation
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Vi Editor

  • 2. INTODUCTION TO VIM • vi → The standard Unix text editor • vim → vi improved is a powerful text editor • gvim → Graphical version of vim • Advantages of Vi / Vim : – Speed : Do more with fewer keystrokes – Simplicity : No dependence on mouse/GUI – Availability : Included with most Unix / Linux Distro • Disadvantages of Vi/Vim : – Difficult : Steeper learning curve than simpler editors
  • 3. VI MODES OF WORKING • Keystroke behavior is dependent upon vim's "mode" • Three main modes: – Command Mode (default) : Move cursor, cut / copy / paste / or delete text in file – Insert Mode : Modify text in file – Ex Mode : Save, Quit, Customize etc • <Esc key > : exits current mode into command mode. • NOTE : When in doubt press Escape key, you will be back in command mode
  • 4. OPEN A FILE IN VI / VIM • To start vi / vim : – # vim filename – # vi +number filename ( open file and put cursor at line number specified ) • 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 • By default vi has unnamed temporary buffer where file is edited
  • 5. MODIFY A FILE : INSERT MODE • INSERT MODE → To insert the text in file we should be in Insert mode – i → inserts the text before cursor location – I → insert at beginning of line – a → inserts text after cursor location – A → insert at end of line – I → insert at beginning of line – o → insert new line (below) – O → insert new line (above) – S → deletes the character under cursor and get into insert mode
  • 6. MODIFY A FILE : REPLACING TEXT • ONE CHARACTER AT A TIME → Replacing text also happens in insert mode as follows : – r → replace a single character – R → replace multiple char( will be in replace mode )
  • 7. SAVE & EXIT FILE : EX MODE • Enter Ex Mode by pressing → : – Creates a command prompt at bottom-left of screen • Common write/quit commands : – :q <enter key> → quits the vi only if no changes have been made to the file being edited – :q! <enter key> → quits the vi without making any changes in file – :w <enter key> → writes (saves) the file to disk only – :wq <enter key> → writes the buffer and quits vi – :ZZ <enter key> → writes the buffer and quits vi – :x <enter key> → writes and quits
  • 8. WRITE TO FILE : EX MODE • Common write commands : – :w <enter key> → writes (saves) the file to disk only – :wq <enter key> → writes the buffer and quits vi – :f <filename> → renames current file to filename – :w <filename> → write the file to path / filename given – :w>> filename → append current file to the filename given – :5,10w filename → write lines 5 through 10 to the filename given – :5,10w>>filename→ append lines 5 through 10 to the filename given – :r <filename> → read a copy of file into current file at cursor positon – :e <filename> → opens another file with filename – :e# <enter key> → switch between the open vi windows ******** (this works after saving the file once on disk using :w )
  • 9. USING COMMAND MODE • Default mode of vim • Keys describe movement and text manipulation commands • Commands repeat when preceded by a numberCommands repeat when preceded by a number • Example – Right Arrow : moves right 1 character – 5 followed by Right Arrow : moves right 5 characters
  • 10. MOVING AROUND : COMMAND MODE • Move by character : Arrow Keys, h, j, k, l ( Non-arrow keys useful for remote connections to older systems )
  • 11. MOVING AROUND : COMMAND MODE • MOVE BY WORD • w : moves the cursor forward one word • b : moves cursor back one word • e : moves cursor to the end of current word • MOVE BY LINE • ^ : moves cursor to the beginning of current line • $ : moves to the end of current line • MOVE BY SENTENCE • ( : moves to the beginning of previous sentence • ) : moves to the end of next sentence
  • 12. MOVING AROUND : COMMAND MODE • MOVE BY PARAGRAPH • { : moves to the beginning of previous paragraph • } : moves to the end of next paragraph • MOVE BY SCREEN • <ctrl>f : moves forward one screen • <ctrl>b : moves back one screen • <ctrl>d : moves down half screen • <ctrl>u : moves up half screen • H : first line on screen • M : middle line on the screen • L : last line on the screen
  • 13. MOVING AROUND : COMMAND MODE • MOVE INSIDE WHOLE DOCUMENT • nG : move to nth line of file (****in command mode*****) • :n : move to nth line of file (****in ex mode****) • 1G : first line of the document / file • G : last line of the file • 25G : 25th line of the file ( in command mode ) • :25 : 25th line of the file ( in ex mode )
  • 14. SEARCH : EX MODE • Same implementation as in less editor • /<pattern> – search forward in buffer for next occurrence of the pattern of text. • ?<pattern> – search backwards • n – Repeats the last search command • N – Repeats the search command in opposite direction • We can use regular expression in searches
  • 15. SUBSTITUTION : EX MODE • By default substitute the first occurrence of text on current line – : s/file/book/ ( first occurrence of file with book on current line ) – :s/file/book/g ( all the occurrence of file with book on current line ) • Use x,y ranges – :1,5s/cat/dog/ ( first occurrence of cat with dog between line 1 to line 5 ) – :1,5s/cat/dog/g ( all occurrence of cat with dog between line 1 to line 5 ) • Use % for whole file – :%s/cat/dog/ ( substitute first occurrence of cat with dog in full file ) – :%s/cat/dog/g ( substitute all occurrence of cat with dog in full file ) – :%s/cat/dog/gc ( c → prompt before each substitution )
  • 16. DELETING TEXT : COMMAND MODE • DELETING SINGLE CHARACTERS – x → Deletes a character at current cursor position – 3x → Deletes the character currently under cursor followed bye two – Nx → Deletes n-1 characters on right of cursor position – X → Deletes a character to the left of the cursor • NOTE : Deleting puts the text in unnamed temporary buffer which can be used for paste operation at other place, and thus becomes cut paste *******
  • 17. DELETING TEXT : COMMAND MODE • DELETING LARGER CHUNKS – dw → deletes a word (or part of a word) from the cursor to the next space or to the next punctuation. – db → delete one word backwards – d$ → deletes the current line from the cursor to the end of the line – d^ → deletes the current line from the cursor to the beginning of the line – d0 → same as d^ – d) → delete one sentence forward – d( → delete one sentence backwards – dG → delete from current line to the end of file – dgg → delete from current line to the beginning of file – dd → deletes the current line ******* – ndw → deletes n words from current cursor position – ndd → deletes n lines from current line *******
  • 18. COPY TEXT : COMMAND MODE • COPY / YANKING → yank command puts the text in temp buffer for copy – yw → yank a word forward – yb → one word backwards – y$ → yank the current line from the cursor to the end of the line – y^ → yank the current line from the cursor to the beginning of the line – y0 → same as d^ – y) → yank one sentence forward – y( → yank one sentence backwards – yG → yank from current line to the end of file – ygg → yank from current line to the beginning of file – yy → yank the current line ******* – nyw → yank n words from current cursor position – nyy → yank n lines from current line ******* – 20yy → yank 20 lines from current line *******
  • 19. • P → 'PUT' comman for paste operation, place the contents of the unnamed buffer back into the file. ( Buffered content of delete & yank command ) – p → Paste the content below the current line – P → Paste the content above the current line PASTE TEXT : COMMAND MODE
  • 20. UNDO 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
  • 21. USING MULTIPLE “WINDOWS” • View multiple documents in a single vim screen. – Ctrl-w followed by s → s splits the screen horizontally – Ctrl-w followed by v → v splits the screen vertically – Ctrl-w followed by arrow → Arrow moves between windows – Ctrl-w followed by q → quit / close open windows • Ex-mode instructions always affect the current window • :help windows displays more window commands
  • 22. CUSTOMIZING VI SESSION • A few common configuration items – :set all - Display all options – :set - Display current setting of options – :set number / :set nu - Display line numbers – ( This can be useful when deleting or substituting selected text as follows ) – :2,10d - Delete line 2 to 10 – :1,10s/foo/bar/g - Substitute foo with bar from line 1 to 10 – :set nonumber / :set nonu - Hide line numbers
  • 23. CUSTOMIZING VI SESSION • A few common configuration items – :set all - Display all options – :set - Display current setting of options – :set autoindent or :set ai - Turn on autoindenting – :set textwidth=65 (vim only) – :set wrapmargin=15 / :set wm=15 - Set wrap margin 15 spaces from right edge of screen – :set wrapmargin=0 / :set wm=0 - Turn off Wrap margin – :set ignorecase or :set ic - Set ignore case during searches – :syntax on - Turn on syntax highlighting – :syntax off - Turn off syntax hightlighting
  • 24. CUSTOMIZING VI SESSION • Options can be set in the following ways – During a vi session • :set nu / :set nonu ...etc ( preserve setting for that session) – For permanent setting for a user. • Create either ~/.vimrc or ~/.exrc file in user home directory Sample contents of .exrc are → set nu set ai set wm=10
  • 25. ABBREVIATIONS • ABBREVIATIONS → are text strings which automatically expand to larger string when used in Insert Mode ( use .vimrc for permanent changes ) • To add an abbreviation – :ab UW University of Delhi (Now if in insert mode I enter UW it be expanded to University of Delhi on entering any non-alphanumeric character) • To list currently defined abbreviations – :ab • To disable / delete an abbreviation use the :unab command – :unab UW → clears the given abbreviation – :abc → clear all the set abbreviation
  • 26. MAPPING • MAPPING → any key can be mapped as shortcut for command. ( For making permanent changes use .vimrc ) • To add a key map – :map – dd (it creates a key map that works in command mode) – :map! @ dd (it creates a key map that works in insert mode) • To list currently defined map keys – :map – :map! • To remove a keymap – :unmap - – :unmap @
  • 27. USEFUL TIPS • Launch vi and begin editing <filename> at line 125 – # vi +125 <filename> • Launch vi and edit multiple files – # vi <file1> <file2> (switch to next file using :n) • Change case of character under cursor – ~ ( press tilde key at current cursor positon) • Join the current line and the next line – J ( capital J in command mode ) • Remove null lines in the file – : g/^$/d • List all occurrences of the word 'foo' with line numbers – :g/foo/# • Read output from a Unix shell command into current text – :r !<command>
  • 28. USEFUL TIPS • Get the line number of current cursor positon – Ctrl + g • Repeats the action performed by last command – . ( press . In command mode ) • Temporarily returns to the shell to perform shell commands – :sh ( Type exit to return to vi ) • Execute a command from vi editor ex mode – :! <command>
  • 29. LEARNING MORE • vi/vim built-in help • :help topic • :help • Use :q to exit help • vimtutor command • NOTE → USERS WITH UIDs > 200 WHEN TYPE VI WILL GET VIM EDITOR ( Because of alias of vi )
  • 30. ?