A Practical Guide to Fedora and Red Hat Enterprise Linux Chapter 5: The vim Editor By Fred R. McClurg Linux Operating System © Copyright 2014, All Rights.

Slides:



Advertisements
Similar presentations
Course Outline: System Requirements What is Vi Editor Conventions
Advertisements

In the last class… The vi basics command, input and ex mode Input mode – entering and replacing text Saving text and quitting – the ex mode.
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
A Guide to Unix Using Linux Fourth Edition
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
Chapter 5 Editing Text Files
CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
CS 497C – Introduction to UNIX Lecture 9: The vi/vim Editor Chin-Chih Chang
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
UNIX Filters.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Chapter 3 Mastering Editors
Basic Text Processing, Redirection and Pipes. 222 Lecture Overview  Basic text processing commands head, tail, wc  Redirection and pipes  Getting to.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Chapter8 The vi Editor. Introduction to vi u Modes of Operation u The Work Buffer  During the editing session, vi make all changes in the buffer  Advantage.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
1 of 47 Chapter 4: The vi Editor – First Look Copyright ©2008 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Chapter Three Text Editing1 System Programming Text Editing.
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
THE vi EDITOR. Introduction There are three editors available in almost all versions of Unix: ed, ex and vi. The ed program is the original editor that.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
1 Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
Linux Working with files Saleh Khazaei
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Purdue Linux Users Group Presents Linux 201: Session 1 Everything you ever wanted to do in VIM Thor Smith.
CS:414 introduction to Unix and Linux
vi basic introduction through advanced tips and "tricks"
Vim basics Vi IMproved.
Using Vi(m) This presentation on using the Vi(m) editor will cover:
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Linux 104 Training Module File Editing.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Technical University of Kosice
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
Presentation transcript:

A Practical Guide to Fedora and Red Hat Enterprise Linux Chapter 5: The vim Editor By Fred R. McClurg Linux Operating System © Copyright 2014, All Rights Reserved

vi, vim, gvim: yum install vim-X11 ascii man page: yum install man-pages Install for this class …

vi, vim, gvim: Visual Editor Syntax: gvim filename

vim: Modes of Operation Command Mode: Accepts vim commands Input Mode: Accepts any text Escape Key: Toggles between Command and Input Modes cursor mode indicator mode indicator line number line number column number column number percent content percent content

vim: Command Modes Vi Command Mode: ◦ Short (usually one or two) character commands Ex Command Mode: ◦ Always begins with colon

Vi Commands

vi: Cursor Movement Commands 1GH k ^0hMl$ j L G goto first line of file goto last line of file home (top of screen) line up line down lower (btm of screen) left middle screen right end of line begin line begin text

vi: Insert/Append Commands OIi□aA o open above open below insert left cursor position append right append right append line insert line

SsC cursor position vim: Replace (Overwrite) Commands rR replace line end replace character cursor position vi: Change/Substitute Commands substitute character substitute line change line end change line end □

vi: Page Scroll Commands Ctrl+UCtrl+B □ Ctrl+D Ctrl+F forward full screen up full screen cursor position down half screen back half screen

vi: Screen Scroll Commands middle screen bottom screen top screen

{( Bb□weWE ) } vi: Move by word, sentence, paragraph paragraph up paragraph down sentence up sentence down cursor word big end big word back big word back word end word word

XxD cursor position vi: Delete Commands delete character delete previous delete to line end delete to line end □

CharDescription u Undo last operation U Undo last line change Ctrl+RRedo the undo command. Repeat previous command J Join current line with next % Match brace or parenthesis * Find next occurrence of word ~ Change case of character vi: Misc one character commands

vi: Delete and Change

CmdDescription Y Yank (copy) line yy Yank (copy) line P Put (paste) yanked line above p Put (paste) yanked line below "ayy Yank line into buffer named “ a ” "ap"ap Put line from named buffer “ a ” vi: Yank and Put Commands

CmdDescription mxmx Mark position with letter “x” 'x'x Go to marked line “x” `x`x Go to marked char position “x” vi: Marker commands

CmdDescription >> Shift (indent) current line >} Shift (indent) next paragraph << Unshift (unindent) current line <} Unshift (unindent) paragraph vi: Shift (indentation) commands

CmdDescription fxfx Find character “x” FxFx Find previous “x” txtx Find character before “x” TxTx Find character after previous “x” ; Repeat prior f, F, t, or T command vi: Find character commands

CmdDescription /str Define and find string “ str ” ?str Define & find previous “ str ” n Find next string occurrence N Find previous occurrence vi: Find string commands

Ex Commands

ex: Substitute Addresses Syntax: :[address]s/search/replace/options Address Examples: ◦ noneCurrent line ◦ % Entire buffer ◦ 1,$ Lines one through the last line ◦.,$ Current line through the last line ◦ 'm,'n From marker “m” through marker “n”

ex: Search Regular Expressions CharsDescription ^ Beginning of line anchor $ End of line anchor. Any one character * Zero or more of the previous character \= Zero or one of the previous character \+ One or more of the previous character [] Any character in set (ex: [0-9], [a-z], [aeiou]) [^] Character not in set (ex: [^ -~ ] and [^aeiou]) Syntax: :[address]s/search/replace/options

ex: Search Regular Expressions Syntax: ◦ :[address]s/search/replace/options Regular Expression Search Examples: ◦ ^ Beginning of line anchor ◦ $ End of line anchor ◦. Any one character ◦ * Zero or more of the previous character ◦ \= Zero or one of the previous character ◦ \+ One or more of the previous character ◦ [] Any character in set (ex: [0-9], [a-z], [aeiou]) ◦ [^] Any character not in set (ex: [^ -~], [^aeiou]) ◦ \< Beginning of word ◦ \> End of word ◦ \( \) Grouping CharDescription \< Beginning of word anchor \> End of word anchor \( \) Numbered grouping \| Alternative (OR) expressions \{n,m} Matches n to m of the previous character \{n} Matches exactly n times of previous character \{,m} Matches maximum of m (0 to m) of previous \{n,} Matches a minimum of n of previous character

ex: Search Regular Expressions Syntax: ◦ :[address]s/search/replace/options MatchingEquivalent \s Any white space character \S Non white space character \a Alphabetic character [a-zA-Z] \A Non alphabetic character [^a-zA-Z] \d Digit character [0-9] \D Non digit character [^0-9] \l Lowercase character [a-z] \u Uppercase character [A-Z]

ex: Regular Expression Replacements Syntax: ◦ :[address]s/search/replace/options Replace Examples: ◦ &Replace with string that was matched ◦ \1 End of line anchor ◦ \< Beginning of word ◦ \> End of word ◦ * Zero or more of the previous character ◦. Any one character ◦ [] Any character in set (ex: [0-9], [a-z], [aeiou]) ◦ [^] Any character not in set (ex: [^ -~], [^aeiou]) ◦ \( \) Grouping ReplaceDescription & Replace with matched string \1 … \9 Matched groups \L Following characters lowercase \U Following characters uppercase \l Next character lowercase \u Next character uppercase

ex: Search Modifiers Syntax: ◦ :[address]s/search/replace/options

ex: Global Commands Syntax: :[address]g[!]/search/cmds :[address]v/search/cmds CmdDescription g Delete lines matching. Ex: :g/Microsoft/d g Search and replace match. Ex: :g/^search/s/$/append/i v Delete lines not matching. Ex: :v/Linux/d

ex: Copy and Move Commands Syntax: :[address]co[address] :[address]m[address] CmdDescription co Copy lines 5 to last line after current line: :5,$co. m Move lines marked “a” to “b” after line marked “z”: :’a,’bm’z

ex: Editing Files Syntax: ◦ :e file Edit file “filename” ◦ :e! Revert file to last save ◦ :w file Write file “filename” ◦ :q Quit the editor ◦ :q! Quit without saving ◦ :wq Write file and quit editor ◦ :n Next file ◦ ZZ Write file (if modified) and exit

ex: Editor Settings Keep same indentation as previous line (Ctrl+T for next indent, Ctrl+D previous indent) ◦ :set autoindent:set ai Writes file before using “ :n ” to edit next file ◦ :set autowrite:set aw Number of columns in editor ◦ :set columns=80:set co=80 Insert spaces instead of tabs ◦ :set expandtab:set et Highlight search string ◦ :set hlsearch:set hls Case insensitive search ◦ :set ignorecase:set ic

ex: More Editor Settings Number of lines displayed ◦ :set lines=30 Search for pattern as it is typed ◦ :set incsearch:set is Display line numbers ◦ :set nonumber:set nu Wrap buffer when searching for a string ◦ :set wrapscan:set ws Define number of spaces in a tab ◦ :set tabstop=3:set ts=3 Threshold for reporting number of lines changed. ◦ set report=1

ex: Still More Editor Settings Number of spaces for shift (indent). Works with “ >> ” and “ << ”. ◦ :set shiftwidth=3:set sw=3 Show matching braces {}, parenthesis (), or brackets [] ◦ :set showmatch :set sm Number of characters from right margin where wrapping begins ◦ :set wrapmargin=2:set wm=2 Flash screen instead of beeping ◦ :set visualbell:set vb

vim: Ex Editor Alias Commands Alias an Insert Mode abbreviation ◦ Syntax: :abbreviate alias expanded ◦ Example: :ab ittti ITT Technical Institute

ex: Editor Key Map Commands Map an unused key to a command ◦ :map K :%s/[ \t][ \t]*$//^M Unused vim key commands: ◦ Ctrl+ACtrl+Q Ctrl+Z ◦ g Ctrl+S ◦ Kv ◦ Ctrl+K V ◦ Ctrl+OCtrl+V ◦ q Ctrl+X

ex: Execute Shell Commands Syntax ◦ :!!cmd Use current line as input to cmd and replace with output from cmd ◦ :!}cmd Use paragraph as input to cmd and replace with output from cmd Examples: ◦ :!!which perl Inputs the location of Perl ◦ :!}sort Sort the next paragraph ◦ :!}fmt Format next paragraph by wrapping long lines and joining short lines ◦ :1,$!expand –t 3 Replace tabs with 3 spaces

ex: Indent Shell Command Syntax ◦ :1,$!indent

ex: Split Command Syntax ◦ :split [filename]

vim: Location of vimrc Location: ◦ Unix: $HOME/.vimrc ~/.vimrc ◦ Windows: :version :echo $HOME :echo $VIM