Contents
|
Introduction
The VI editor is a one of the most powerful text editor which has a very extensive functionalities to allow developer enabling to edit files with a minimum of keystrokes. This power and functionality comes as a cost. This article I am going to explain basic command which helps you to put your hands on in VIM editor to write your program.
Mode of Operations
VIM has three modes of operation.
- Command Mode : This is the mode VIM starts in by default. In this mode, most keys on the keyboard are defined to specific command. At any time, pressing the ESC key and typing colon : returns the user to command mode.
- Insert Mode: This mode allows a user to start inputing data into file. To reach this mode, press i or o
- Visual Mode: This mode allows you to do the visual operation which is common in grapical editors like selecting punch of lines copy/pasting/deleting the text in the editor. Pressing v will enters you in visual mode.
Commands for basic Operations
-
Opening a File
|
-
Inserting Text
Commands
Descriptions i Insert a text in after the current cursor position I Insert a text before the cursor position o Insert a text one line below the cursor position O Insert a text one line above the cursor position a Append a text after the cursor A Append a text before the cursor
-
Moving around
Commands
Descriptions k Go up j Go down h Go left i Go right w Go write a word b Go left a word gg Go to the beginning of the file G Go to the end of the file 22j Go to the line no 22 1 Go to start of the line $ Go to end of the line
-
Copy & Paste
Commands
Descriptions v Press v to enter visual mode Use Arrow keys [k, j h, I ] To select the text to copy y To copy the selected text p To paste the text d To cut the text followed by y to paste d To delete the selected text yy To copy a Line yw To copy a word dd To delete/cut a Line dw To delete/cut a word x To delete a character r To replace a character cw To replace a word
-
Undo & Redo
Commands
Descriptions u Undo the changes Ctrl + R Redo the changes
-
Search & Replace
Commands
Descriptions /<keyword> after the slash put whatever you want to find and press the enter key) n Find next N Find previous * Pressing star on top of the word you want to search automatically show the search result :noh Turn off highlighting (after a search) :%s/search/replace/gc It will search and replace the text in the entire document [g mean global] [c mean confirm before replacing the text] :1,5s/search/replace/ci It will only replace the text in between line number 1 and 5. [I mean ignore case]
-
Save & Quit
Commands [see colon is there before ]
Descriptions :w Save the file :!w Save it forcefully to override the readonly files :q Close the file :q! Close the unsaved file forcefully : :wq save and close the file :wq! Save and Close the file forcefully :x Save and close the file
-
Splitting windows
Commands
Descriptions : sp Split the window into two buffer : sp filename open the new file in the window : vsp Vertically split the window : vsp filename Open the file in vertical window ctrl + w w Switch between windows
-
Advance Options
|
Conclusion
This article provides a very basic command which is used in VIM for day to day work. As I told VIM is so powerful text editor It has more than 150 commands which provides the different functionality. VIM can be configured as better than modern IDE. It has support of editing all the modern programming language. Please feel free to give your comments in the below section. If you have any query feel free to send a mail to sentenwin@gmail.com
No comments:
Post a Comment