1. 1. Vim Resources
  2. 2. Vi Insert mode & Command Mode
    1. 2.0.1. Vi Insert Mode
      1. 2.0.1.0.1. Vi Command Mode - Vi Insert Mode
  3. 2.0.2. Vi Command Mode
  • 3. Vi File Navigvation
    1. 3.0.0.0.1. Arrow Keys
  • 3.0.1. Move up, down, left and right in Vim
  • 3.0.2. Vi Page Down
  • 3.0.3. Vi Half a Page Down
  • 3.0.4. Vi Page Up
  • 3.0.5. Vi Half a Page Up
  • 4. More Advanced Ways of Entering Insert Mode
    1. 4.0.1. Vi Insert Text at Start of the Line
    2. 4.0.2. Vi Insert Text at the end of the Line
    3. 4.0.3. Vi Append text to the right of the Cursor
    4. 4.0.4. Begin a new line below
    5. 4.0.5. Vi replace line
  • 5. Vi Replace
    1. 5.0.1. Change a Word in Vi
    2. 5.0.2. Replace line, but not wrapped text
    3. 5.0.3. Vi Replace Character
    4. 5.0.4. Vi Replace
  • 6. Vi Delete
    1. 6.0.1. Vi Delete Single Character After the Cursor
    2. 6.0.2. Vi Delete Character before the Cursor
    3. 6.0.3. Vi Delete Word
  • 7. Vi Delete Line commands
    1. 7.0.1. Vi Delete Line
    2. 7.0.2. Vi Delete until end of Line
    3. 7.0.3. Delete to end of screen
    4. 7.0.4. Delete to end of file
    5. 7.0.5. Vi Delete From Cursor To Start of Line
  • 8. Vi Copy and Paste
    1. 8.0.1. Vi Copy Line
    2. 8.0.2. Vi Copy 3 Lines of Text
    3. 8.0.3. Vi Copy Word
    4. 8.0.4. Vi Copy 3 Words
    5. 8.0.5. Vi Paste Commands
  • 9. Vi Search Commands
    1. 9.0.1. Vi Search forward
    2. 9.0.2. Vi Search Back
  • 10. Vi Search and Replace Commands
    1. 10.0.1. Vi Search and Replace First Instance
    2. 10.0.2. Vi Search and Replace on a Single Line
    3. 10.0.3. Vi Search and Replace Entire File
    4. 10.0.4. Vi Search for part of a Word
    5. 10.0.5. Vi Search for words ending with $string
    6. 10.0.6. Vi Search for Metacharacters
    7. 10.0.7. Vi Exact Match Search Only
    8. 10.0.8. Vi Search for a range of Strings
    9. 10.0.9. Vi Search for Upper and Lowercase
  • 11. Advanced Vi commands
    1. 11.0.1. Vi View Options
    2. 11.0.2. Vi Run Shell Commands
    3. 11.0.3. Vi Joining Lines
    4. 11.0.4. Vi Split Windows
      1. 11.0.4.1. Vi Split Window Horizontally
      2. 11.0.4.2. Vi Split Window Virtically
    5. 11.0.5. Vi Close All Split Windows
  • 12. Vi Save commands
    1. 12.0.1. How to Save in Vi
    2. 12.0.2. Vi Save and Exit
  • 13. Misc Vi Commands
    1. 13.0.1. Vi Undo Command
    2. 13.0.2. Vi Undo All
  • 14. Vi Show File Name
  • 15. Vi Multipliers
  • Cheat Sheet VI

    A collection of Vi commands in a cheat sheet, handy reference document for learning / remembering Vi commands. I refer to Vim / Vi as the same thing in this document, but in most modern Linux distros vi is often a symlink to vim.

    It’s worth learning Vi as it’s installed on pretty much every Linux base system out there.

    If you’re learning Vi, you might want to check out Vim Adventures - an online adventure game that uses Vi commands.

    Vim Resources

    Enjoy the cheat sheet :)

    Vi Insert mode & Command Mode

    Vi has two basic modes, insert mode - used for entering text and command mode, used for entering commands. See the tip section below for switching between each mode.

    Vi Insert Mode

    Enter vi insert mode, insert mode is used for inserting text.

    Vi Command Description
    i Enter insert mode from command mode.
    Vi Command Mode - Vi Insert Mode

    Vi has two modes, insert mode for inserting text and command mode a common mistake is attempting to edit in command mode. If you are unsure on what mode Vi is using double tap escape (enters command mode) and then hit “i” if you wish to enter insert mode.

    Vi Command Mode

    Vim Command Description
    Esc Hit escape to enter command mode.

    Vi File Navigvation

    Basic file navigation, how to move up, down, left and right.

    Arrow Keys

    Modern Vi / Vim editors will allow you to use the arrow keys, but it’s worth learning the correct way to navigate vi without using the arrow keys in case you come across Vi command line or a shell that doesn’t like arrow keys.

    Move up, down, left and right in Vim

    You’ll need to be in command mode for these commands, navigation in vi uses h j k l

    Vim Command Description
    h Move left - easy to remember h key is on the left
    j Move down - I remember it with j(d)own for down
    k Move up - k for up - I remember it with (k)up
    l Move right - l is on the right side of hjkl and moves you right

    Vi Page Down

    Vim Command Description
    Ctrl+F Vi move forward a page

    Vi Half a Page Down

    Vi Command Description
    Ctrl+D Vi move half a page down

    Vi Page Up

    Vi Command Description
    Ctrl+B Vi move up a page

    Vi Half a Page Up

    Vi Command Description
    Ctrl+U Vi move up half a page

    More Advanced Ways of Entering Insert Mode

    Vi Insert Text at Start of the Line

    Vi Command Description
    I Insert text at the beginning of the line

    Vi Insert Text at the end of the Line

    Vi Command Description
    A Appends text at the end of the line

    Vi Append text to the right of the Cursor

    Vi Command Description
    a Appends text to the right of the cursor

    Begin a new line below

    Vi Command Description
    o Begin a new line, below the current line

    Vi replace line

    Vi Command Description
    O Removes line, and allows you to type a new line in it’s place

    Vi Replace

    Change a Word in Vi

    Vi Command Description
    cw Replaces a single word, place cursor on first letter and hit cw (Change Word)

    Replace line, but not wrapped text

    Vi Command Description
    c$ Replaces the current line but doesn’t extend to change the rest of a wrapped sentence on the screen

    Vi Replace Character

    Vi Command Description
    r Replaces only the character under the cursor

    Vi Replace

    Vi Command Description
    R Replaces over the top of existing text, until the user hits return.

    Vi Delete

    Vi Delete Single Character After the Cursor

    Vi Command Description
    x Vi deletes single character after the cursor

    Vi Delete Character before the Cursor

    Vi Command Description
    X Vi deletes character before the cursor.

    Vi Delete Word

    Vi Command Description
    dw Vi Delete Word, deleted the word under the cursor, from the curosr position onward

    Vi Delete Line commands

    Vi Delete Line

    Vi Command Description
    dd Delete the current line in Vi

    Vi Delete until end of Line

    Vi Command Description
    D Deletes from cursor to end of line

    Delete to end of screen

    Vi Command Description
    dL Deletes from cursor to end of screen

    Delete to end of file

    Vi Command Description
    dG Deletes from cursor to end of file

    Vi Delete From Cursor To Start of Line

    Vi Command Description
    d^ Deletes from cursor to start of line

    Vi Copy and Paste

    Vi Copy Line

    Vi Command Description
    yy Copies current line into unnamed buffer

    Vi Copy 3 Lines of Text

    Vi Command Description
    3yy Copy 3 lines of text into unnamed buffer

    Vi Copy Word

    Vi Command Description
    yw Copy word under cursor into unnamed buffer

    Vi Copy 3 Words

    Vi Command Description
    3yw Copy 3 words into unnamed buffer

    Vi Paste Commands

    Vi Command Description
    P Copy contents of unamed buffer to right of cursor
    Vi Command Description
    p Copy contents of unamed buffer to left of cursor

    Vi Search Commands

    Vi Search forward

    Vi Command Description
    N Vi search forward in file

    Vi Search Back

    Vi Command Description
    SHIFT+N Vi search backward in file

    Vi Search and Replace Commands

    Vi Search and Replace First Instance

    Vi Command Description
    :s/find-string/replace-string/ Vi search and replace first instance of specified string

    Vi Search and Replace on a Single Line

    Vi Command Description
    :s/find-string/replace-string/g Vi search and replace all instances of specified string on current line

    Vi Search and Replace Entire File

    Vi Command Description
    :%s/find-string/replace-string/g Vi search and replace all instances of specified string for entire file

    Vi Search for part of a Word

    A fuzzy search allows you to find something that you only know part of, for example if you wanted to find all instances of lines starting with the word “Picard” you would use the following:

    Vi Command Description
    /^Picard Vi search within file words starting with Picard

    Vi Search for words ending with $string

    Vi Command Description
    /worf$ Vi search within file for word engine with worf

    Vi Search for Metacharacters

    Vi Command Description
    /\* Vi search within file for metacharacters like, *

    Vi Exact Match Search Only

    Vi Command Description
    /star\. Vi exact search only, will return instances of “star only”, not starfleet or star-trek

    Vi Search for a range of Strings

    Helpful for finding version numbers in text files.

    Vi Command Description
    /v2.[1-9] Vi search for a range, this example would return all v2.1-9 instances within the file, e.g. v2.4 v2.7 etc

    Vi Search for Upper and Lowercase

    Search for upper and lowercase strings in Vi.

    Vi Command Description
    / [tT] [hH [eE] Vi search upper or lowercase strings, this example would return any instance of the word ‘the’. e.g. The, THE, tHE, tHe

    Advanced Vi commands

    Vi View Options

    Vi Command Description
    :set all Lists all Vi options

    Vi Run Shell Commands

    Run shell commands from Vi.

    Vi Command Description
    :! ls -l Run shell command from Vi, in this example ls -l is executed

    Vi Joining Lines

    Backspace doesn’t always work…

    Vi Command Description
    SHIFT+J Position the cursor in either line you wish to join, and press SHIFT+J

    Vi Split Windows

    Useful for comparing files, to switch between windows press SHIFT+W

    Vi Split Window Horizontally
    Vi Command Description
    :split Split window Horizontally in Vi
    Vi Split Window Virtically
    Vi Command Description
    :vsplit Split window Virtically in Vi

    Vi Close All Split Windows

    Vi Command Description
    :only Closes all split windows and focuses on the primary window

    Vi Save commands

    How to Save in Vi

    Vi Command Description
    :w Writes the file to disk

    Vi Save and Exit

    How to save and exit Vi, personally I use :wq

    Vi Command Description
    :wq Save and exit Vi

    | :x | Exit - Vi will prompt and ask if you wish to save |
    | SHIFT+ZZ | Another way to Save and Exit Vi |
    | wq! | Forces save on read only files, and exits |

    Misc Vi Commands

    Vi Undo Command

    Vi Command Description
    U Press SHIFT+Uto undo in Vi

    Vi Undo All

    Vi undo all since last write.

    Vi Command Description
    :+X+! Undo everything since last write

    Vi Show File Name

    SHIFT+G shows the file name, number of lines and current position.

    Vi Multipliers

    Almost every command in Vi can leverage multipliers, typically it’s a case of prefixing the command with a numnber. Example: 10W would move 10 words to the right.

    原文链接:HighOn.Coffee