Vi Editor Handling
Vi Editor is one of basic editing utility provided by Unix or Ubuntu systems.
Here, I will give some basic directions or cue pointers per say for more efficient usage of vi editor.
To use the vi /path/to/file command to open an existing file with Vi. The vi /path/to/file command also works if the file doesn’t exist yet;
Vi will simply create a new file and write it to the specified location when you save.
By default with above command, vi will open the file, It looks like you can just start typing, but you CAN'T.
Vi is a modal text editor, and it opens in command mode. Trying to type at this screen will result in unexpected behavior.
* While in command mode,
While in Command Mode
You can move the cursor around with the arrow keys.
- Typing dd (press the d key twice) deletes an entire line of text
- You can select, copy, cut and paste text in command mode.
- Move your cursor to select text, and then press y to copy the selected text
- Move your cursor to select text, and then press x to cut the selected text
- Position your cursor at the desired location and press the p key to paste the text you copied or cut.
Now, lets go a bit further. What about writing into the file ? We can't just keep copy + paste all the time now, can we ?
To go to Insert Mode, move the cursor at desired position using arrow keys whilest Command Mode. Once you are at intended position in file, you just need to press i and you are in insert mode.
Start typing and Vi will insert the characters you type into the file rather than trying to interpret them as commands.
Once you’re done in insert mode, press the escape key to return to command mode again.
Command to Save and Quit : Esc + type :wq!
Command to Quit without Saving : Esc + type :q!
Enjoy !!
Add new comment