• Aucun résultat trouvé

INTRODUCTION TO DISPLAY EDITING WITH VI

Dans le document for the Professional (Page 68-72)

There are other ways to move around in the file: the keys CTRL-F and CTRL-B move forward and backward a page, keeping a couple of lines of continuity between screens so that it is possible to read through a file using these rather than CTRL-D and CTRL-U if you wish.

Notice the difference between scrolling and paging. If you are trying to read the text in a file, hitting CTRL-F to move forward a page will leave you only a little of the previous text to look at. Scrolling, on the other hand, leaves more context and happens more smoothly. You can continue to read the text as it scrolls.

2.2.2 Searching, Goto, and Previous Context

By giving the editor a string of characters or words to search for, you can locate a specific position in the file. Type the character I, then a string of char-acters, and finally a CR. The editor will position the cursor at the next occur-rence of this string. Try hitting n to go on to the next occuroccur-rence of this string.

The character? will search in reverse from where you give the command, but otherwise it is like I.

*

If the search string you give the editor is not present in the file, the editor will print a message on the last line of the screen, and the cursor will return to its initial position.

If you wish the search to match only at the beginning of a line, begin the search string with the caret symbol C). To match only at the end of a line, end the

* These searches will normally wrap around the end of the file, and thus find the string even if it is not on a line in the direction of your search. You can disable this wraparound in scans by giving the command :se nowrapscan CR, or more briefly :se nows CR.

search string with a $. Thus Fsearch CR will search for the word 'search' at the beginning of a line, and Ilast$ CR searches for the word 'last' at the end of a line.**

The command G, when preceded by a number will position the cursor at that line in the file. Thus IG will move the cursor to the first line of the file. If you do not give G a count, then it moves to the end of the file.

If you are near the end of the file, and the last line of text is not at the bottom of the screen, the editor will place only the character '"" on each remaining line.

This indicates that the last line in the file is on the screen, that is, the ,-, lines are past the end of the file.

You can find out the state of the file you are editing by typing a CTRL-G. The editor will show you: the file name, the. number of the current line, the number of lines in the buffer, and the percentage of how far through the buffer you are. Try doing this now, and remember the number of the line you are on.

Give a G command to get to the end and then another G command to get back where you were.

You can also get back to a previous position by using the command" (two back quotes). This is often more convenient than G because it requires no advance preparation. Try giving a G or a search with 1 or? and then a " to get back to where you were. If you accidentally hit n or any command which moves you far away from a context of interest, you can quickly get back by hitting".

* * Actually, the search string you give here can be a regular expression in the sense of the editors ex(l) and ed(l). If you don't wish to learn about this yet, you can disable this more general facility with :se nomagic CR. By putting this command in EXINIT in your environment, it will always be in

INTRODUCTION TO DISPLAY EDITING WITH VI 2.2.3 Moving Around on the Screen

Experiment with moving the cursor around on the screen. First try the arrow keys and then use the optional commands h, j, k, and I as described in section 1.4. Experienced users of vi prefer these keys to arrow keys because they are usually right underneath their fingers.

Hit the + key. Each time you do, notice that the cursor advances to the next line in the file, at the first non-white position on the line. The - key is like

+

but goes the other way.

These are very common keys for moving up and down lines in the file. If you move beyond the text on the screen while using these keys, then the screen will scroll down (or up if possible) to bring a line at a time into view. The CR key has the same effect as the + key.

vi also has commands to take you to the top, middle, and bottom of the screen.

H will take you to the top (home) line on the screen. Preceding it with a num-ber will take you to that line on the screen. For example, 3H will position the cursor on the third line on the screen. The command M will take you to the middle line on the screen, and L will take you to the last line on the screen. L also takes counts, thus SL will take you to the fifth line from the bottom.

2.2.4 Moving Within a Line

Pick a word on the screen, but not the first word on a line. Move the cursor using CR and - to the line where the word is. Now use the w key to advance the cursor word by word on the line or hit the b key to back up by words. You may also want to use the e key which advances the cursor to the end of the cur-rent word rather than the beginning of the next. Also try SPACE (the space bar) which moves right one character and the BACKSPACE key (or CTRL-H) which moves left one character. The key h works as CTRL-H does and is useful if you don't have a BACKSPACE key. (Also, as noted just above, I will move to the right.)

The wand b keys stop at each group of punctuation. To go backward and for-ward by word without stopping at punctuation use Wand B rather than the lower case equivalents. Try these on a few lines with punctuation to see how they differ from the lower case wand b.

The word keys wrap around the end of a line. Try moving to a word on the

advance the cursor one position backwards to previous page

forward a word, ignoring punctuation back a word

Dans le document for the Professional (Page 68-72)