Basic VI Editor Shortcuts
If you’re a Unix or Linux System Administrator then you will most likely have come across the VI editor, whether you’re bashing out a shell script or need to modify a configuration file VI comes in very handy.
If you’re new to Unix or Linux the following VI shortcut commands should get you started.
VI Editor Shortcuts
# From your shell run the following to open a file for editing vi <your filename> ### Navigation # Use your arrow keys to move around # To jump to the top of the file Press 1 then hold SHIFT + press G # To drop to the bottom of the file Hold SHIFT + press G ### Editing # There are 2 input modes 'replace' & insert # To exit either of these modes simply press ESC # Activate replace mode Hold SHIFT + press R then enter your text # Activate insert mode Press i then enter your text # Delete text Navigate to the beginning of the text to delete and press x # Delete a line Press d twice # Delete multiple lines <number of lines> then press d twice e.g. 100dd # Search for text or a pattern Press / Then enter your text or pattern then press enter to search # Undo last change Exit replace or insert mode, press ESC Then press u # Save the file Press ESC Then type :w then press enter # Force file save (if file is read-only and you have root privileges) Press ESC Then type :w! then press enter # Exit the editor Press ESC Then type :q then press enter
VI may seem complicated at first, but it becomes easier the more you use it.