Tuesday, 28 January 2014

Vi editor - Keyboard shortcuts

If you're new to working on a Unix shell, you must know that you can edit files through the command line itself, using the vi mode. Let me quickly show you some basic most frequently used commands (keyboard shortcuts) about vi editing.

1. To create a new file or open an existing file to edit, type vi filename

2. To close an opened file :

type :wq (to save your changes and quit) and press Enter

type :wq! (to quit without saving, use !) and press Enter

type just :w (to save a file without quitting)

3. To add some text to an opened file press i (This will allow you to insert text before the cursor)

Press a to append text after the cursor.

4. To Replace some text exactly under the cursor, type r

5. To delete a character under the cursor, type

6. To delete the entire current line type dd

7. To copy the current line, type yy

8. To paste the copied line, type p

9. To search for a string, word or a pattern in a file, type :/string-to-be-searched (Note the forward slash /) This will search the string in a forward fashion (from top-to-bottom). However, if you want to start searching backwards (from bottom-to-top) type :?string-to-be-searched

10. When you search for a string using forward slash / or question mark ? you could move to the string's next occurrence by typing n

11. To display the total number of lines in the file, type :=

12. To display the current line number, type :.= (Note the dot .)

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker