Cheat Sheet: Red Hat Linux Fedora For Dummies
vi commands
Many people find that working in a text-based environment makes everyday systems administration jobs a little easier. You’re likely to work from a CLI terminal emulator (see our comments in Chapter 4 about the GNOME Terminal) after you have been working with Linux for a while. The Visual Editor, vi, is almost as old as the Unix operating system and is much older than Linux. The straightforward text editor vi is nothing fancy, like OpenOffice, but is nonetheless quite useful and powerful.The following list of commands contains the most useful and commonly used commands to control the vi text editor. We have been using vi for more than 20 years, in fact, and have never had to use many other commands than these — proving that you can be lazy and still get work done.You can start vi by entering the command vi from the GNOME Terminal shell prompt:
[username@somemachine username]$ vi somefile
You enter these commands from the vi editor (see Chapter 4 for more details):
vi filename | Open filename in vi |
I | Enter Insert mode, inserting before the current position |
Shift+I | Enter Insert mode, inserting at the beginning of the current line |
a | Enter Insert mode, inserting after the current position |
Shift+A | Enter Insert mode, inserting at the end of the current line |
Esc | Return from Insert mode to Command mode |
x | Delete a character while in Command mode |
cw | Delete the word to the left of the cursor and put the editor in Input mode |
:w | Write out the file |
:q | Quit with no additional writes to the disk |
:wq | Write back the file, and then quit |
Shift+ZZ | Write back the file, and then quit |
:q! | Quit the file with impending changes unwritten |
/string | Search forward through the file for a string |
?string | Search backward through the file for a string |
n | Find the next string (either forward or backward) |
u | Undo the last command |