VI

Discussion(s) about all things *Nix =-p

Moderators: boat, rickh

Post Reply
User avatar
Dictator
[NME] tried and true
[NME] tried and true
Posts: 989
Joined: Mon Jan 07, 2002 8:00 pm
Location: Central Pennsylvania

VI

Post by Dictator » Tue Mar 15, 2005 2:25 pm

I found a nice vi Tutorial site (vi is a console text editor). vilearn.org You can download the tutorial from the site and install it on your *nix machine. When installed, type vilearn and the tutorial will start. :)

While I was learning vi, I copied most vi commands from vilearn and created a vi reference.

I've attached vi-reference.txt in a zip file so you can save it somewhere or print it. :P

Code: Select all

	VI Reference
			------------

Basic Editing
-------------
These are the vi commands you should know after tutorial #1:

        ^D      Move DOWN one half-screen
                (depress the control key and type d)

        ^U      Move UP one half-screen
                (depress the control key and type u)

        h       Move left one character
        j       Move down one line
        k       Move up one line
        l       Move right one character

        dd      DELETE one line
        x       X-OUT one character

        u       UNDO last change

 	:q!<RETURN>    QUIT without saving changes
                (type a colon, then the letter q, then an
                exclamation point, and press RETURN)

        ZZ      Exit and save any changes
                (type capital Z, twice)

        o       OPEN a line for inserting text
        i       INSERT starting at the cursor

        ESC     ESCAPE from insert mode

and to use vi from a UNIX command line:

        vi filename



Moving Efficiently
------------------

        w       Move to the beginning of the next WORD
        e       Move to the END of the next word
        b       Move BACK to the beginning to the previous word

        $       Move to the end of the line
        ^       Move to the first non-white character on the line

        0       Move to the first column on the line (column zero)
        #|      Move to an exact column on the line (column #) e.g.  5| 12|

    	f char      FIND the next occurrence of char on the line
    	t char      Move 'TIL the next occurrence of char on the line

    	F char      FIND the previous occurrence of char on the line
    	T char      Move 'TIL the previous occurrence of char on the line

        ;       Repeat the last  f, t, F, or T
        ,       Reverse the last  f, t, F, or T

        %       Show matching () or {} or []

        H       Move to the HIGHEST position in the window
        M       Move to the MIDDLE position in the window
        L       Move to the LOWEST position in the window

    	m char      MARK this location and name it char
    	' char      (quote character) return to line named char
    	''          (quote quote) return from last movement

         G      GO to the last line in the file
        #G      GO to line #.  (e.g., 3G , 5G , 175G )

        {       (left brace) Move to the beginning of a paragraph
        }       (right brace) Move to the end of a paragraph

        (       (left paren) Move to the beginning of a sentence
        )       (right paren) Move to the beginning of the next sentence

 	[[      Move to the beginning of a section
        ]]      Move to the end of a section

    	/string      Find string looking forward
    	?string      Find string looking backward

        n        Repeat last / or ? command
        N        Reverse last / or ? command



Cutting and Pasting 
-------------------

    	#movement   repeat movement # times

    	dmovement   DELETE to where "movement" command specifies
    	d#movement  DELETE to where the  #movement  command specifies
                (e.g.  dw  d3w )

    	ymovement   YANK to where "movement" command specifies
    	y#movement  YANK to where the  #movement  command specifies
                (e.g.  yw  y3w )

        P       (upper p) PUT the contents of the buffer before the cursor
        p       (lower p) PUT the contents of the buffer after the cursor

        "#P     (upper p) PUT contents of buffer # before the cursor
        "#p     (lower p) PUT contents of buffer # after the cursor
                (e.g.  "2p  "7P )

   	"aDELETE    DELETE text into buffer a
    	"aYANK      YANK text into buffer a
    	"aPUT       PUT text from named buffer a
                (Note, don't actually type 'DELETE', 'YANK', or 'PUT';
                type one of the DELETE commands, YANK commands, or PUT
                commands, e.g.  "ad}  "by3y  "cy200G  "dp  "zP  )

    	:w<RETURN>  WRITE contents of the file (without quitting)
                (type a colon, type w , then press the RETURN key)

    	:e filename<RETURN>    Begin EDITing the file called "filename"



Inserting Techniques
--------------------

        o       OPEN a line below the cursor
        O       OPEN a line above the cursor

        i       INSERT starting before the cursor
        I       INSERT at the beginning of the line

        a       APPEND starting after the cursor
        A       APPEND at the end of the line

        ESC     ESCAPE from insert mode

        J       JOIN two lines

        #s      SUBSTITUTE for # characters
        #S      SUBSTITUTE for # whole lines

        r       REPLACE character (NO need to press ESC)
        R       enter over-type mode

    	cmovement   CHANGE to where the movement commands specifies
                (e.g.  c3w  c$  cc )



Tricks and Timesavers
---------------------

        ~       (tilde) Convert case of current character

        U       (upper u) UNDO all changes made to the current line
                as long as your cursor has not moved off the line

        .       (dot) repeat last change

        ^D      Move DOWN one half-screen
                (depress the control key and type d)

        ^U      Move UP one half-screen
                (depress the control key and type u)

        ^F      Move FORWARD one full-screen
        ^B      Move BACKWARD one full-screen

        ^E      Move the window down one line without moving cursor
        ^Y      Move the window up one line without moving cursor

    	z<RETURN>   Position the current line to top of window
        z.      Position the current line to middle of window
        z-      Position the current line to bottom of window

        ^G      Show status of current file
        ^L      Refresh screen

        !}fmt   Format the paragraph, joining and filling lines to
                produce output lines of up to 72 characters

       !}sort   Sort lines of a paragraph alphabetically

   	>movement    Shift right to where the movement command specifies
   	<movement    Shift left to where the movement command specifies
Attachments
VI-Reference.zip
(1.98 KiB) Downloaded 117 times
Give me liberty, or I may well give you death.

[NME]Llama_Being
Baby Barnacle
Baby Barnacle
Posts: 22
Joined: Sun Feb 27, 2005 9:47 pm

Post by [NME]Llama_Being » Tue Mar 15, 2005 10:08 pm

vi = evil editor of death.

PICO!!!

User avatar
[NME]T-Bone
[NME] tried and true
[NME] tried and true
Posts: 2818
Joined: Fri Jan 18, 2002 8:00 pm
Location: Sharpsville, PA

Post by [NME]T-Bone » Wed Mar 16, 2005 12:49 am

what? you don't have the 3 gazillion commands memorized? :P
T-Bone

"If we hit that bullseye, the rest of the dominos
will fall like a house of cards. Checkmate."

User avatar
Dictator
[NME] tried and true
[NME] tried and true
Posts: 989
Joined: Mon Jan 07, 2002 8:00 pm
Location: Central Pennsylvania

Post by Dictator » Wed Mar 16, 2005 10:44 am

:lol: I never used pico. Usually, I use nano because I enjoy short-cut commands. However, vi is so popular and vi fans rant about it and told me it'd be easy if I use it often. Most books or web sites didn't have what vilearn.org offer, a tutorial which teaches you and experiment with vi commands at same time. ;)

If you think vi's evil, then MS Word is worst of all. It has millions of gazillions commands more than vi. :P
Give me liberty, or I may well give you death.

Post Reply