Technoracle
    Facebook Twitter Instagram
    • Sitemap
    • Privacy Policy
    • Disclaimer
    • Term of Services
    Facebook Twitter Instagram Pinterest Vimeo
    TechnoracleTechnoracle
    • Tutorials
      • Amazon Cloud
      • Google Cloud
    • How To
    • Blog
    • About
    Subscribe
    Technoracle
    Home»Tips»Ubuntu»Updated VI Keyboard Shortcuts – Make Your Command Line Super Friendly [PDF Cheatsheet]
    Ubuntu

    Updated VI Keyboard Shortcuts – Make Your Command Line Super Friendly [PDF Cheatsheet]

    Sulagna MukherjeeBy Sulagna MukherjeeJune 3, 2022Updated:June 3, 2022No Comments5 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    VI Keyboard Shortcuts
    VI Keyboard Shortcuts
    Share
    Facebook Twitter LinkedIn Pinterest Email

    In this tutorial, I am going to share some of the most important VI Keyboard Shortcuts, that make your command line tasks super easier. I also included VI Cheatsheet PDF to download.

    VI Keyboard Shortcuts

    Page Contents

    • What is a VI editor?
    • Modes of VI Editor
    • Vi Commands and their Description
      • To switch from command to insert mode
      • To save and quit (VI Keyboard Shortcuts)
      • To move around a file VI text editor
      • To jump lines on VI text editor
      • To delete on VI text editor
      • To repeat and undo (VI Keyboard Shortcuts)
      • Command to cut, copy and paste
      • Command to cut, copy and paste in blocks
      • Start and end of the line VI text editor
      • Joining lines in VI text editor
      • Move forward or backward in VI
      • Search a string in VI text editor
      • Replace all in VI text editor
      • Text buffers in VI text editor
      • Abbreviation
    • Conclusion

    What is a VI editor?

    VI Keyboard Shortcuts: The most practical and commonly used terminal-based editor is VI. As a visual editor, the vi editor has been enhanced and in 2022 Vi Shortcuts and Vi Commands are so much useful to work in VI using the terminal. Every Unix system has it.

    In other words, it is accessible in all Linux distributions. It is simple to use and runs on a variety of operating systems and platforms. It is a highly strong program. But now Vim is the enhanced version of the vi editor.

    Modes of VI Editor

    VI Editor has three modes

    • Command Mode: When the vi editor starts up in the terminal, it is in Command Mode as default. In command mode Vi interprets any characters we type as commands and thus does not display them in the terminal. This mode allows us to move through a file, and delete, copy, or paste a piece of text. To enter into this Mode from any other mode you have to press the [Esc] key. If you press [Esc] when you are in Command Mode, then vi will beep or flash the screen and change to that required mode using vi keyboard commands and vi shortcuts.
    • Insert Mode: This mode allows you to input text into the terminal. Everything written in this mode is evaluated as input and thereafter saved to a file. The vi always opens in command mode as default. The Insert mode is required to enter text. Simply type I to enter insert mode. To exit insert mode, use the Esc key, which returns you to command mode.
    • Last Line Mode: While in Command Mode, type a colon [:] to enter Line Mode. The cursor will go to the final line of the terminal while vi waits for a command. This mode allows you to do things like save files and run commands.

    Vi Commands and their Description

    Vi Editor and the vi shortcut and vi commands are different from other editors and they used different functions to execute.

    The commands used in the vi editor are case-sensitive.

    CommandDescription
    vi filenameCreates a new file if it does not exist, otherwise opens the existing file.
    vi -R filenameOpens an existing file in read-only mode. view filename: Opens an existing file in read-only mode.

    To switch from command to insert mode

    CommandAction
    iStart typing before the current character
    IStart typing at the start of the current line
    aStart typing after the current character
    AStart typing at the end of the current line
    oStart typing on a new line after the current line
    OStart typing on a new line before the current line

    To save and quit (VI Keyboard Shortcuts)

    CommandsAction
    :wqSave and quit
    :wSave
    :qQuit
    :w fnameSave as fname
    ZZSave and quit
    :q!Quit discarding changes made
    :w!Save (and write to the non-writable file)

    To move around a file VI text editor

    CommandsAction
    jTo move down
    kTo move up
    hTo move left
    lTo move right

    To jump lines on VI text editor

    CommandsAction
    GWill direct you at the last line of the file
    “Will direct you to your last position in the file

    To delete on VI text editor

    CommandsAction
    xDelete the current character
    XDelete the character before the cursor
    rReplace the current character
    xpSwitch two characters
    ddDelete the current line
    DDelete the current line from the current character to the end of the line
    dGdelete from the current line to the end of the file

    To repeat and undo (VI Keyboard Shortcuts)

    CommandsAction
    uUndo the last command
    .Repeat the last command.

    Command to cut, copy and paste

    CommandsAction
    ddDelete a line
    yy(yank yank) copy a line
    pPaste after the current line
    PPaste before the current line

    Command to cut, copy and paste in blocks

    CommandsAction
    <n>ddDelete the specified n number of lines
    <n>yyCopy the specified n number of lines

    Start and end of the line VI text editor

    CommandsAction
    θBring at the start of the current line
    ^Bring at the start of the current line
    $Bring at the end of the current line
    dθDelete till the start of a line
    d$Delete till the end of a line

    Joining lines in VI text editor

    CommandsAction
    JJoin two lines
    yypRepeat the current line
    ddpSwap two lines

    Move forward or backward in VI

    CommandsAction
    wMove one word forward
    bMove one word backward
    <n>wMove specified number of words forward
    dwDelete one word
    ywCopy one word
    <n>dwDelete specified number of words

    Search a string in VI text editor

    CommandsAction
    /stringForward search for given string
    ?stringBackward search for given string
    /^stringForward search string at beginning of a line
    /string$Forward search string at end of a line
    nGo to the next occurrence of the searched string
    /\<he\>Search for the word he (and not for there, here, etc.)
    /pl[abc]ceSearch for place, plbce, and plcce

    Replace all in VI text editor

    Syntax:

    <startLine,endLine**>** s/<oldString>/<newString>/g

    Example:

    CommandsAction
    :1,$ s/readable/changed/Replace forward with backward from the first line to the last line
    :3,6 s/letters/neww/gReplace forward with backward from the third line to the ninth line

    Text buffers in VI text editor

    CommandsAction
    “addDelete the current line and put text in the buffer a
    “apPaste the line from buffer a

    Abbreviation

    Syntax:

    :ab <abbreviation> <abbreviatedWord>

    Example:

    CommandsAction
    :ab au abbreviation and unabbreviationAbbreviate au to be ‘abbreviation and unabbreviation’
    :una auUn – abbreviate au
    Download PDF Cheat sheet

    Read More: How to Install Vim on Ubuntu Easily [3 steps]

    Conclusion

    In this article, I covered most of the important and most used VI keyboard Shortcuts with the VI commands cheatsheet in PDF. Download the PDF and also share it with your friends.

    ubuntu tips
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow To Setup FTP on AWS EC2 Ubuntu Instance
    Next Article Migrate WordPress Site to AWS in 2022 [Step by Step Guide]
    Sulagna Mukherjee

    Sulagna is a tech enthusiastic girl, she is exploring the different fields of technology and sharing her learning through her writings with everyone . You can follow her at YouTube(Noobie Techs)

    Related Posts

    How To

    How to Install Microsoft Teams on Ubuntu 22.04 Easily

    February 22, 2023
    Read More
    How To

    How To Install Composer on Ubuntu 22.04 LTS Easily

    November 24, 2022
    Read More
    How To

    How to Install Laravel on Ubuntu 22.04 [Super Easy Guide]

    November 24, 2022
    Read More
    Add A Comment

    Leave A Reply Cancel Reply

    Facebook Twitter Instagram Pinterest
    © 2023 Technoracle

    Type above and press Enter to search. Press Esc to cancel.

    Go to mobile version