

Command Mode: When vi starts up, it is in Command Mode.Modes of Operation in vi editor There are three modes of operation in vi:
Vi page down shortcut key how to#


It will replace text until it hits a space. R – enters the insert mode to replace text not insert text. The Esc key exits insert mode and returns you back to command mode. Insert Mode: Enables you to insert and edit text. := – returns number of current line :w filename – writes contents of file to a new filename. This mode is also referred to as colon commands Replace text – :%s/fine/ one – this replaces all occurs of “fine” with “one” % represents “global changes to all occurrences” replace to a line number, ending line number of comma. n – moves to next occurrence of search string N – move to next occurrence of search string in opposite direction Ex mode: Enter ex mode from command mode with “:”. w – Move over one word at a time Shift + G– Takes you to the bottom of the page Page up and down in VI Shift + f Page down (forward) Shift + b page up (backward) note* The keyboard page and and page down keys work the same Change text – cc-allows you to change the entire line (basically removes the line and inserts into insert mode) cw to replace just one word on the line the current word your mouse is over.Search – search forward type / and ? searches backwards both followed immediately by the term to search for.:%s/foo/bar will replace the first occurrence of foo with bar, operating on every line in the buffer.:%s/foo/bar/g will replace every occurrence of foo with bar, operating on every line in the buffer.:s/foo/bar will replace the first occurrence of foo with bar, operating on the current line.:s/foo/bar/g will replace every occurrence of foo with bar, operating on the current line.Also very helpful is the /c flag – it will allow you to confirm each replacement match, depending on the above criteria for searching. u – undo any change, must be in command mode and only goes back one change. P – Upper case P will paste the yanked line(s) starting on the line before our cursor G – Takes you to specified line H – Takes the cursor to the top of the page L – Takes the cursor to the bottom of the page o – inserts a new line below the line your cursor is on and inserts into insert mode for typing. a – append text after cursor A – append text to end of current line p – Command will paste the yanked line(s) contents starting on the line after your cursor. Precede the YY command with the number of lines you would like to yank. 2yy will yank 2 lines, 4yy will yank 4 lines. Navigate to the line you wish to yank and type yy make sure you are in command mode.

Not needed if you have an up and down arrow on your keyboard.Yank – Term used to copy files. Example, a and i.You can use h, j, k and I to navigate in similar ways as the up and down arrow. You’ll find yourself needing this if you are coding or scripting inside of the unix/linux command line using VI.Command Mode: Accepts commands, which are usually in the form of individual letters. This is a collection of some of the basic VI commands and shortcuts for newbies.
