Basic VI Editor Shortcuts

Basic VI Editor Shortcuts

English: A Shebang, also Hashbang or Sharp ban...

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.

Enhanced by Zemanta
Posted in Development, IT, Linux, Open Source, Unix, Work and tagged , , , , , . Bookmark the permalink. RSS feed for this post. Leave a trackback.

Leave a Reply

  • Who is Gareth?

    Established in the mid eighties, Gareth took to computers at an early age. Growing to lead a career in IT, now spanning over a decade. His big passion is fitness, and studying the impact it has on a persons life. As a regular at the gym he uses his workouts to push his body beyond the limit. When not working, Gareth spends his evenings developing ideas to generate viable business solutions encompassing his passions, IT + Fitness.

Swedish Greys - a WordPress theme from Nordic Themepark.