Exploring VIM editor
Overview of VIM Commands
Introduction to VIM Commands
VIM Cheat Sheets:
Often created as two-column, double-sided, with small print.
Contain many commands that can be overwhelming.
A curated list of essential commands is provided for practical use.
Modes in VIM
Escape Key:
Pressing the escape key switches from input mode to command mode.
Input Mode:
Entered using:
i: Insert mode - starts inserting text at the cursor position.a: Append mode - starts inserting text just after the cursor position (can be thought of as "after").o: Opens a new line below the current line in input mode.
Command Mode:
Triggered by the escape key from input mode.
Basic File Operations
Writing and Quitting Commands:
:wq: Write changes and quit the file.:wq!: Force write and quit, used when there are warnings or unexpected messages.:q!: Quit without saving any changes.
Editing Text
Line Manipulation Commands:
dd: Deletes the current line.yy: Copies or yanks the current line.p: Pastes the text currently in the buffer (clipboard).v: Enters visual mode, allowing the selection of a block of text using arrow keys for manipulation.
Undo and Redo:
u: Undoes the last operation.CTRL + r: Redoes the last operation undone.
Navigation Commands
Document Navigation:
gg: Go to the top of the document, useful for large files.G: Uppercase G goes to the bottom of the document.
Cursor Movement:
^: Move cursor to the start of the current line.$: Move cursor to the end of the current line.w: Move cursor to the next word.
Text Search and Substitution
Searching for Text:
/text: Searches forward for the specified text.?text: Searches backward for the specified text.
Text Substitution:
:%s/old/new/: Substituteoldwithnewin the entire document.Adding
gat the end (:%s/old/new/g) indicates a global substitute, replacing all instances on each line.If
gis omitted, only the first occurrence on each line will be replaced.
Demonstration of Commands
Example to illustrate commands:
Created a sample document with lines of text to demonstrate VIM operations.
Used escape key to return to command mode and executed various commands including moving around using
^,w,$, andgg.Conducted searches for specific text and performed visual selections.
Utilized
ufor undoing actions.Explained global substitution with examples.
Additional Resources
VimTutor:
A built-in instructional document that guides users through VIM functionalities.
Takes approximately 20 minutes to complete and can make users proficient in VIM.
Final Thoughts
VIM vs Nano:
While mastering VIM is beneficial, one does not need to be an expert to pass the RHCSA (RH Certification System Administrator).
Nano is an alternative text editor that is simpler and acceptable for basic editing needs.
Conclusion
Understanding fundamental VIM commands enhances productivity and efficiency while editing text files in Linux.
Utilize VIM’s comprehensive features or fallback to simpler options like Nano as needed.