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.

    • </code>:Movecursortotheendofthecurrentline.</p></li><li><p><code>w</code>:Movecursortothenextword.</p></li></ul></li></ul><h4id="709b5f4b−1ff4−4edc−901f−93b2bd75f867"data−toc−id="709b5f4b−1ff4−4edc−901f−93b2bd75f867"collapsed="false"seolevelmigrated="true">TextSearchandSubstitution</h4><ul><li><p><strong>SearchingforText</strong>:</p><ul><li><p><code>/text</code>:Searchesforwardforthespecifiedtext.</p></li><li><p><code>?text</code>:Searchesbackwardforthespecifiedtext.</p></li></ul></li><li><p><strong>TextSubstitution</strong>:</p><ul><li><p><code>:</code>: Move cursor to the end of the current line.</p></li><li><p><code>w</code>: Move cursor to the next word.</p></li></ul></li></ul><h4 id="709b5f4b-1ff4-4edc-901f-93b2bd75f867" data-toc-id="709b5f4b-1ff4-4edc-901f-93b2bd75f867" collapsed="false" seolevelmigrated="true">Text Search and Substitution</h4><ul><li><p><strong>Searching for Text</strong>:</p><ul><li><p><code>/text</code>: Searches forward for the specified text.</p></li><li><p><code>?text</code>: Searches backward for the specified text.</p></li></ul></li><li><p><strong>Text Substitution</strong>:</p><ul><li><p><code>:%s/old/new/</code>: Substitute <code>old</code> with <code>new</code> in the entire document.</p></li><li><p>Adding <code>g</code> at the end (<code>:%s/old/new/g</code>) indicates a global substitute, replacing all instances on each line.</p></li><li><p>If <code>g</code> is omitted, only the first occurrence on each line will be replaced.</p></li></ul></li></ul><h4 id="4bebe487-3d17-4e0b-aee6-9fa08a84af5e" data-toc-id="4bebe487-3d17-4e0b-aee6-9fa08a84af5e" collapsed="false" seolevelmigrated="true">Demonstration of Commands</h4><ul><li><p>Example to illustrate commands:</p><ul><li><p>Created a sample document with lines of text to demonstrate VIM operations.</p></li><li><p>Used escape key to return to command mode and executed various commands including moving around using <code>^</code>, <code>w</code>, <code>, and gg.

    • Conducted searches for specific text and performed visual selections.

    • Utilized u for 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.