Vi Editor Basic Commands

Embed Size (px)

Citation preview

  • 7/30/2019 Vi Editor Basic Commands

    1/2

    Vi Editor Commands

    h Left

    j Down

    k Up

    l (or spacebar) Right

    w Forward one word

    b Back one word

    e End of word

    ( Beginning of current sentence

    ) Beginning of next sentence

    { Beginning of current paragraph

    } Beginning of next paragraph

    [[ Beginning of current section

    ]] Beginning of next section

    0 Start of current line

    $ End of current line

    ^ First non-white character of current line

    + or RETURN First character of next line

    0 First character of previous line

    n | character n of current line

    H Top line of current screen

    M Middle line of current screen

    L Last line of current screen

    nH n lines after top line of current screen

    nL n lines before last line of current screen

    Ctrl-F Forward one screen

    Ctrl-B Back one screen

    Ctrl-D Down half a screen

    Ctrl-U Up half a screen

    Ctrl-E Display another line at bottom of screen

    Ctrl-Y Display another line at top of screen

    z RETURN Redraw screen with cursor at top

    z . Redraw screen with cursor in middlez - Redraw screen with cursor at bottom

    Ctrl-L Redraw screen without re-positioning

    Ctrl-R Redraw screen without re-positioning

    /text Search for text (forwards)

    / Repeat forward search

    ?text Search for text (backwards)

    ? Repeat previous search backwards

    n Repeat previous search

    N Repeat previous search, but it opposite direction

    Vi Editor has two main modes of operation:

    1. Command mode : Initially Vi Editor Opens in Command Mode. To Switch from Insert Mode to Command Mode

    Press ESC Key.

    2. Insert mode : To switch into insert mode, simply press the 'i' key. To Exit Insert Mode Press ESC Key.

    If you are unsure which mode you are in, press 'ESC'. If you were in insert mode, you will be returned to command

    mode. If you were already in command mode, you will be left in command mode (possibly with a 'beep', to indicate

    that you were already in command mode).

    Cursor Control Commands

    Page 1

  • 7/30/2019 Vi Editor Basic Commands

    2/2

    Vi Editor Commands/text/+n Go to line n after text

    ?text?-n Go to line n before text

    % Find match of current parenthesis, brace, or bracket.

    Ctrl-G Display line number of cursor

    nG Move cursor to line number n

    :n Move cursor to line number n

    G Move to last line in file

    dd Delete current line

    ndd Delete n lines

    D Delete remainer of line

    dw Delete word

    d} Delete rest of paragraph

    d^ Delete back to start of line

    dL Delete up to last line on screen

    dG Delete to end of file

    u Undo last change

    U Restore current line

    J Joins two lines (Current Line & the next line))

    rx Replace character with x

    Rtext Replace text beginning at cursor

    ~ Reverse caseyy Copy current line

    Paste Copied line below the Current Line

    P Paste Copied line above the Current LineCtrl-U Delete current line Works in the Insert Mode

    ESC End of insert mode

    :e file2 Edit file2 (current file becomes alternate file) To Edit 2nd File while First is still

    :e! Reload file from disk (revert to previous saved version)

    :e# Edit alternate file Switch to other opened file for

    :n1,n2w >> file Append lines n1 to n2 to file

    :n1,n2w Write lines n1 to n2 to file

    :q Quit

    :q! Quit (even if changes not saved):r file Insert file after cursor

    :w Write file

    :w file Write file as file, leaving original untouched

    :w! Write file (ignoring warnings)

    :w! filename Overwrite file (ignoring warnings)

    :wq Write file and quit

    :x Quit, only writing file if changed

    ZZ Quit, only writing file if changed

    Editing

    File Handling Commands (Press ESC then the command)

    Press ESC Key & then the below mentioned command.

    Page 2