- Choosing an Editor: nano/pico or vi/vim
- Starting nano and Dabbling with It
- Saving in nano
- Cutting and Pasting Text Blocks in nano
- Checking Spelling in nano
- Getting Help in nano
- Exiting nano
- Starting vi (or vim) and Dabbling with It
- Saving in vi
- Adding and Deleting Text in vi
- Importing Files into vi
- Searching and Replacing in vi
- Exiting vi
Searching and Replacing in vi
One of vi’s better features (and advantages over nano) is that it allows you to search and replace throughout entire files. As shown in the next sections, you can just find a specific string of text (a regular expression, in Unix lingo; see ), or you can find the text and replace it with other text, as in .
To find a string of text in vi:
vi hairyspider
For starters, access vi and a specific file.
/spider
Enter command mode, then type / followed by the text you’re looking for. Here, we’re looking for “spider,” but you may be looking for “the fly” or “wiggled and jiggled and tickled inside her.” Or whatever.
-
Press to find the first occurrence of the term. Type to find the next one.
To search and replace in vi:
vi hairyspider
For starters, access vi and a specific file.
:%s/spider/horrible horrible awful spider/
Enter :%s/ plus the text to find, another /, followed by the replacement text, as in . Here, we replace “swallowed a fly” with “swallowed a spider to catch the fly,” but perhaps you might forgo the spider and simply go for some antacid.