vi Editor commands and use

Sharing is caring!

<div dir&equals;"ltr" style&equals;"text-align&colon; left&semi;">&NewLine;<div style&equals;"text-align&colon; justify&semi;"><span style&equals;"font-size&colon; small&semi;"><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-weight&colon; normal&semi;">The default editor that comes with the UNIX operating system is called vi &lpar;<b>vi<&sol;b>sual editor&rpar;&period; &lbrack;Alternate editors for UNIX environments include pico and emacs&comma; a product of GNU&period;&rsqb;&nbsp&semi;&nbsp&semi;<&sol;span><&sol;span><&sol;span><&sol;div>&NewLine;<div style&equals;"text-align&colon; justify&semi;"><span style&equals;"font-size&colon; small&semi;"><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-weight&colon; normal&semi;">vi can be used from any type of terminal because it does not depend on arrow keys and function keys&&num;8211&semi;it uses the standard alphabetic keys for commands&period; <&sol;span>vi has two modes&colon;<&sol;span><&sol;span><&sol;div>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><&sol;p>&NewLine;<ul>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">command mode<&sol;span><&sol;span><&sol;li>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">insert mode<&sol;span><&sol;span><&sol;li>&NewLine;<&sol;ul>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">In command mode&comma; the letters of the keyboard perform editing functions &lpar;like moving the cursor&comma; deleting text&comma; etc&period;&rpar;&period; To enter command mode&comma; press the escape <esc> key&period;<&sol;esc><&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">In insert mode&comma; the letters you type form words and sentences&period; Unlike many word processors&comma; vi starts up in command mode&period;<&sol;span><&sol;span><&sol;p>&NewLine;<h2><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Starting vi<&sol;span><&sol;span><&sol;h2>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">You may use vi to open an already existing file by typing <&sol;span><&sol;span><&sol;p>&NewLine;<pre><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> vi filename<br &sol;><&sol;span><&sol;span><&sol;pre>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">where &&num;8220&semi;filename&&num;8221&semi; is the name of the existing file&period; If the file is not in your current directory&comma; you must use the full pathname&period;<&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Or you may create a new file by typing<&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><&sol;p>&NewLine;<pre><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> vi newfilename<&sol;span><&sol;span><&sol;pre>&NewLine;<pre><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">&nbsp&semi; vi -r filename &lpar;Recover a file&comma; being edited before system crashed&rpar; <&sol;span><&sol;span><&sol;pre>&NewLine;<pre><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">&nbsp&semi;<&sol;span><&sol;span><&sol;pre>&NewLine;<div style&equals;"text-align&colon; left&semi;"><b><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">&nbsp&semi;<&sol;span><&sol;span>Note&colon;<&sol;b>&nbsp&semi;<&sol;div>&NewLine;<pre>&nbsp&semi;<&sol;pre>&NewLine;<div style&equals;"text-align&colon; left&semi;">The cursor moves to bottom of screen whenever a colon &lpar;<tt>&colon;<&sol;tt>&rpar; is typed&period; This type of command is completed by hitting the <tt><return><&sol;return><&sol;tt> &lpar;or <tt><enter><&sol;enter><&sol;tt>&rpar; key&period; <&sol;div>&NewLine;<div style&equals;"text-align&colon; left&semi;"><&sol;div>&NewLine;<div style&equals;"text-align&colon; left&semi;"><b><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Entering Text<&sol;span><&sol;span><&sol;b><&sol;div>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">In order to begin entering text in this empty file&comma; you must change from command mode to insert mode&period; To do this&comma; type<&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> i <&sol;span><&sol;span><&sol;p>&NewLine;<h2><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Moving the Cursor<&sol;span><&sol;span><&sol;h2>&NewLine;<pre><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">The cursor is controlled with four keys&colon; h&comma; j&comma; k&comma; l&period;<&sol;span><&sol;span><&sol;pre>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">&nbsp&semi;h left one space j down one line k up one line l right one space&nbsp&semi;<&sol;span><&sol;span><&sol;p>&NewLine;<p><b>BASIC EDITING<&sol;b><&sol;p>&NewLine;<pre> x delete character<br &sol;> nx delete n characters<br &sol;> X delete character before cursor<br &sol;> dw delete word<br &sol;> ndw delete n words<br &sol;> dd delete line<br &sol;> ndd delete n lines<br &sol;> D delete characters from cursor to end of line<br &sol;> r replace character under cursor<br &sol;> cw replace a word<br &sol;> ncw replace n words<br &sol;> C change text from cursor to end of line<br &sol;> o insert blank line below cursor<br &sol;> &lpar;ready for insertion&rpar;<br &sol;> O insert blank line above cursor<br &sol;> &lpar;ready for insertion&rpar;<br &sol;> J join succeeding line to current cursor line<br &sol;> nJ join n succeeding lines to current cursor line<br &sol;> u undo last change<br &sol;> U restore current line<br &sol;><&sol;pre>&NewLine;<p><b>MOVING AROUND IN A FILE<&sol;b><&sol;p>&NewLine;<pre> <span style&equals;"font-size&colon; small&semi;"> w forward word by word<br &sol;> b backward word by word<br &sol;> &dollar; to end of line<br &sol;> 0 &lpar;zero&rpar; to beginning of line<br &sol;> H to top line of screen<br &sol;> M to middle line of screen<br &sol;> L to last line of screen<br &sol;> G to last line of file<br &sol;> 1G to first line of file<br &sol;> <control>f scroll forward one screen<br &sol;> <control>b scroll backward one screen<br &sol;> <control>d scroll down one-half screen<br &sol;> <control>u scroll up one-half screen<br &sol;> n repeat last search in same direction<br &sol;> N repeat last search in opposite direction<&sol;control><&sol;control><&sol;control><&sol;control><&sol;span><br &sol;><&sol;pre>&NewLine;<h2><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Closing and Saving a File<&sol;span><&sol;span><&sol;h2>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">To save the edits you have made&comma; but leave vi running and your file open&colon;<&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><&sol;p>&NewLine;<ol>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Press <esc>&period;<&sol;esc><&sol;span><&sol;span><&sol;li>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Type &colon;w<&sol;span><&sol;span><&sol;li>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Press <return>&period;<&sol;return><&sol;span><&sol;span><&sol;li>&NewLine;<&sol;ol>&NewLine;<h2><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">&nbsp&semi;Quit and Discard changes<&sol;span><&sol;span><&sol;h2>&NewLine;<p><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">To quit vi&comma; and discard any changes your have made since last saving&colon;<&sol;span><&sol;span><br &sol;><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;"> <&sol;span><&sol;span><&sol;p>&NewLine;<ol>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Press <esc>&period;<&sol;esc><&sol;span><&sol;span><&sol;li>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Type &colon;q&excl;<&sol;span><&sol;span><&sol;li>&NewLine;<li><span style&equals;"font-family&colon; Arial&comma;Helvetica&comma;sans-serif&semi;"><span style&equals;"font-size&colon; small&semi;">Press <return>&period;<&sol;return><&sol;span><&sol;span><&sol;li>&NewLine;<&sol;ol>&NewLine;<&sol;div>&NewLine;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.