Книга: Fedora™ Unleashed, 2008 edition
Working with vi
Working with vi
The editor found on nearly every UNIX and Linux system is, without a doubt, the vi
editor, originally written by Bill Joy. This simple-to-use but incredibly capable editor features a somewhat cryptic command set, but you can put it to use with only a few commands. Although more experienced UNIX and Linux users continue to use vi
extensively during computing sessions, many newer users might prefer learning an easier-to-use text editor such as pico
or GNU nano.
Diehard GNU fans and programmers definitely use emacs.
That said, learning how to use vi
is a good idea. You might need to edit files on a Linux system with a minimal install, or a remote server without a more extensive offering of installed text editors. Chances are better than good that vi
will be available.
You can start an editing session by using the vi
command like this:
$ vi file.txt
The vi
command works by using an insert (or editing) mode, and a viewing (or command) mode.
When you first start editing, you are in the viewing mode. You can use your cursor or other navigation keys (as shown later) to scroll through the text. To start editing, press the i
key to insert text or the a
key to append text. When finished, use the Esc key to toggle out of the insert or append modes and into the viewing (or command) mode. To enter a command, type a colon (:
), followed by the command, such as w
to write the file, and press Enter.
Although vi
supports many complex editing operations and numerous commands, you can accomplish work by using a few basic commands. These basic vi
commands are the following:
? Cursor movement — h
, j
, k
, l
(left, down, up, and right)
? Delete character — x
? Delete line — dd
? Mode toggle — Esc, Insert
(or i
)
? Quit — :q
? Quit without saving — :q!
? Run a shell command — :sh
(use 'exit'
to return)
? Save file — :w
? Text search — /
NOTE
Use the vimtutor
command to quickly learn how to use vi
's keyboard commands. The tutorial takes less than 30 minutes, and it teaches new users how to start or stop the editor; navigate files; insert and delete text; and perform search, replace, and insert operations.
- SERVER WORKING SIZE
- Chapter 8. Saving and restoring large rule-sets
- CHAPTER 3 Working with GNOME
- Working with Compressed Files
- Logging In to and Working with Linux
- Working with emacs
- Working with OpenOffice.org Writer
- Working with OpenOffice.org Calc
- Working with Gnome Office
- Working with KOffice
- Working with Graphics Formats
- Networking with TCP