![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Vi Editor | ||||||||
Home | SCJP | SCWCD | SCEA | SCSA | ||||||||
List the keyboard sequences that are required to switch between the three modes of operation used by the vi editor. vi is an standard text editor used for manipulating ASCII text files in UNIX. It is a very powerful tool with many features. It is important to remember that few system admins can be successful without a perfunctory knowledge of vi. vi has three modes of operation: command mode -- where program commands can be executed on blocks of characters, insert (edit) mode -- where text is actually entered into the file, and search mode -- where blocks of text can be queried. From command mode, enter insert mode by pressing the i key. To exit insert mode, press the escape key. Search mode is entered by the / or ? key, and exited using the escape key. The escape key is used to toggle between command mode (the default) and all other modes. Example session: UNIX ---> vi file ---> COMMAND ---> i I a A o O ---> TEXT SHELL <---- ZZ <------- MODE <------ <Esc> <------ MODE In command mode, typing ":" causes the editor to expect a command (shown on line 23 of the editor window). For example: :w means 'write' the file to disk. :q means quit out of the file. Combining the two... :wq means write and exit the file. :q! means quit without saving changes ZZ means quit and save changes State the vi editor cmds used to position and move the cursor, create and delete text, and copy rm text. The concept of vi centers on the use of the home row keys. All-important commands can be executed using standard keyboard keys, and no combinations of control or alt. Movement: h - moves the cursor one postion left j - moves the cursor one line down k - moves the cursor one line up l - moves the cursor one position right 0 - moves the cursor to the beginning of the line $ - moves the cursor to the end of the line w - moves the cursor forward one word b - moves the cursor back one word G - moves the cursor to the final line Text Editing: a - changes to insert/edit and allows new text to be appended A - changes to insert/edit and appends to the beginning of line i - changes to insert/edit and allows new text to be inserted I - changes to insert/edit and inserts at end of line r - replaces the character in the current position R - replaces the character and all subsequent characters until escape x - deletes the current character X - deletes the character before the cursor dd - deletes the current line o - create new line below current line O- create new line above current line Copying Text: yy - 'yanks' (copies) line(s) into the buffer for use with pasting p - 'puts' (pastes) the stored line(s) onto the line below P - 'puts' (pastes) the stored line(s) onto the line above Moving Text: A user must specify move in command mode: 5, 15 m 1 will move text from line 5 to 15 and place it starting at line number 1. Match the correct vi command sequences with their respective search and replace functions. vi can search the entire file for a given string of text. A string is a sequence of characters. vi searches forward with the slash (/) key or backward with the question mark key (?). You execute the search by typing the command key, then string followed by RETURN. To cancel the search, press ESC instead of RETURN. You can search again by typing n (forward) or N (backward). Also, when vi reaches the end of the text, it continues searching from the beginning. This feature is called wrapscan. vi supports a few special characters, which act as wildcards or search-exclusions. Note that XXXX stands for any number of characters; it could be g, gefha, or 23CG-4. The special characters are: $ . * [ ] ^ \. [XXXX] match any of the characters Example: /sa[fn] [X1-X2] match any characters between X1 and X2 Example: /[d-h]er vi can also search-and-replace, which means finding instances of a given string and replacing them with a new string. This search-and-replace operation is actually an ex command, and it has the following form: line1, line2s/oldstring/newstring |
||||||||
![]() |
||||||||