diff --git a/docs/tech_docs/linux/vim.md b/docs/tech_docs/linux/vim.md index 195ab22..6ad999c 100644 --- a/docs/tech_docs/linux/vim.md +++ b/docs/tech_docs/linux/vim.md @@ -1,3 +1,261 @@ +It's great to see the foundation of your Vim guide taking shape! Let’s review and enrich the content with some more context and practical examples, especially focusing on programming and working with structured data. Here's a refined and expanded version based on your feedback and previous content: + +--- + +# Vim Guide + +## 1. Introduction to Vim's Philosophy + +Vim, renowned for its modal editing system, allows users to switch between various modes designed for specific tasks such as inserting text, navigating within files, or executing commands. This modal approach greatly enhances editing efficiency by reducing the number of keystrokes required for tasks and enabling a more intuitive control over text manipulation. + +## 2. Quick Reference Guide + +This section provides a quick lookup for the most frequently used Vim commands, categorized for easy reference: + +- **Navigating** + - `h, j, k, l`: Move left, down, up, right (the arrow keys of Vim). + - `gg, G`: Jump to the top or bottom of the document. +- **Editing** + - `i, a, o`: Enter insert mode at cursor, after cursor, or on a new line. + - `d, c, y`: Delete, change, or yank (copy) text. +- **Searching** + - `/pattern, ?pattern`: Search forward or backward for a pattern. + - `n, N`: Repeat search in the same or opposite direction. + +## 3. Core Guides with Integrated Efficiency Tips + +### Basic Editing and File Management + +**Opening, Saving, and Exiting Files** +- **Commands**: `vim filename`, `:w`, `:wq`, `:q!` + - **Description**: Open files with `vim filename`. Save with `:w`, exit with `:q!`, or combine both with `:wq`. +- **Tip**: Use `ZZ` as a quicker alternative to `:wq` when you need to save and exit efficiently. + +**Navigating Within Files** +- **Commands**: `h, j, k, l` + - **Description**: Precisely navigate within lines or across the text. +- **Tip**: Pair `h, j, k, l` with `Ctrl` (e.g., `Ctrl-f` and `Ctrl-b`) for faster document scrolling. + +### Efficient Navigation + +**Word and Line Movements** +- **Commands**: `w, b, e, 0, ^, $` + - **Description**: Navigate efficiently by words or to specific positions within a line. +- **Tip**: `5w` can save significant time by jumping five words forward, reducing repeated keystrokes. + +**Document Navigation** +- **Commands**: `gg, G` + - **Description**: Quickly move to the beginning or end of a document, or directly to a specific line with `50G`. +- **Tip**: Use percentage jumps like `50%` to reach the midpoint of a document quickly. + +### Advanced Text Manipulation + +**Editing Commands** +- **Commands**: `dw, ciw, d$` + - **Description**: Efficient commands for deleting a word, changing inside a word, or deleting to the end of a line. +- **Tip**: `ci(` changes content inside parentheses, a common task in programming. + +**Using Visual Mode for Complex Selections** +- **Commands**: `v, V, Ctrl-v` + - **Description**: Select text for manipulation in various modes: character, line, or block. +- **Tip**: Use `>` or `<` to indent selected blocks quickly, crucial in code formatting. + +### Search and Replace + +**Finding and Replacing Text** +- **Commands**: `:s/old/new/g`, `/%s/old/new/g` + - **Description**: Replace 'old' text with 'new' globally or within the current line. +- **Tip**: Use `*` to search for the word under the cursor quickly. + +**Navigational Searches** +- **Commands**: `f, F, t, T` + - **Description**: Jump to the next or previous occurrence of a character on the line. +- **Tip**: Use `;` and `,` to repeat the last `f` or `t` search efficiently. + +### Enhanced Motion for Programming and Structured Data + +**Paragraph and Section Motions** +- **Commands**: `{`, `}`, `[[`, `]]` + - **Description**: Navigate quickly between paragraphs or code blocks. Ideal for structured data and code structures. + +**Screen Motions** +- **Commands**: `H`, `M`, `L`, `Ctrl-d`, `Ctrl-u` + - **Description**: Manage on-screen text positioning and rapid scrolling effectively. + +**Document Motions** +- **Commands**: `gg`, `G` + - **Description**: Essential for moving quickly through large files or to specific lines, critical in debugging and reviewing. + +### Tips for Using Motions in Structured Data and Programming + +- Combine motions with searches for efficient navigation within XML, JSON + +, or YAML, especially useful in large data files or complex codebases. +- Record macros for repetitive edits across similar structures, optimizing time and ensuring consistency. +- Utilize `Ctrl-v` for block visual mode, particularly effective for column-based editing or configuration adjustments. + +--- + +This expanded guide not only provides a comprehensive look at using Vim effectively but also integrates practical tips directly applicable to programming and structured data editing, ensuring users can leverage Vim's power to its fullest. + +--- + +Certainly! Let's flesh out your Vim guide with enriched content and contextual details, structured in Markdown format. This enriched version will delve deeper into each section, offering clearer explanations and practical examples to ensure users grasp the concepts and can apply them effectively. + +--- + +# Vim Guide + +## 1. Introduction to Vim's Philosophy + +Vim, distinguished by its modal editing capabilities, allows users to switch between various modes for different editing tasks. This design is fundamental for increasing editing speed and efficiency as it enables users to execute commands and navigate files with minimal keystrokes. Each mode in Vim is tailored to a specific purpose—inserting text, navigating files, or executing commands—making it highly efficient once mastered. + +## 2. Quick Reference Guide + +### Most Used Commands and Modes + +- **Navigating** + - `h, j, k, l` - Move left, down, up, right + - `gg, G` - Jump to the top or bottom of the document +- **Editing** + - `i, a, o` - Enter insert mode at cursor, after cursor, or a new line + - `d, c, y` - Delete, change, or yank (copy) text +- **Searching** + - `/pattern, ?pattern` - Search forward or backward for a pattern + - `n, N` - Repeat search in same or opposite direction + +## 3. Core Guides with Integrated Efficiency Tips + +### Basic Editing and File Management + +**Opening, Saving, and Exiting Files** +- **Commands**: `vim filename`, `:w`, `:wq`, `:q!` + - `vim filename` opens a file or creates a new one if it doesn't exist. + - `:w` saves changes, `:wq` saves and quits, and `:q!` quits without saving. +- **Tip**: Use `ZZ` to save and quit Vim quickly, which is a more efficient alternative to `:wq`. + +**Navigating Within Files** +- **Commands**: `h, j, k, l` + - Navigate precisely within lines with minimal movement. +- **Tip**: Combine these with `Ctrl` (e.g., `Ctrl-f` and `Ctrl-b`) to scroll faster through documents, balancing precise and rapid movement. + +### Efficient Navigation + +**Word and Line Movements** +- **Commands**: `w, b, e, 0, ^, $` + - `w` jumps to the start of the next word, `b` to the beginning of the current or previous word, and `e` to the end of the current or next word. + - `0`, `^`, and `$` navigate to the start, first non-blank character, and end of the line, respectively. +- **Tip**: Use `5w` to jump five words forward, saving time compared to repeated presses. + +**Document Navigation** +- **Commands**: `gg, G` + - `gg` jumps to the beginning, and `G` to the end of the document. Use `50G` to jump directly to line 50. +- **Tip**: Jump to specific percentages of your document with `50%` to quickly reach the midpoint. + +### Advanced Text Manipulation + +**Editing Commands** +- **Commands**: `dw, ciw, d$` + - `dw` deletes a word, `ciw` changes inside a word, and `d$` deletes to the end of a line. +- **Tip**: Use `ci(` to change inside parentheses, demonstrating how command combinations can cater to specific coding needs. + +**Using Visual Mode for Complex Selections** +- **Commands**: `v, V, Ctrl-v` + - `v` starts visual mode for character selection, `V` for line, and `Ctrl-v` for a block. +- **Tip**: After selecting text in Visual mode, use `>` or `<` to quickly indent blocks of code. + +### Search and Replace + +**Finding and Replacing Text** +- **Commands**: `:s/old/new/g`, `/%s/old/new/g` + - Replace 'old' with 'new' in the current line or entire document. +- **Tip**: Use `*` to search for the word under the cursor, enhancing workflow speed. + +**Navigational Searches** +- **Commands**: `f, F, t, T` + - `f` moves to the next occurrence of `` on the line, `F` moves to the previous. +- **Tip**: Combine `;` and `,` to repeat the last `f` or `t` search forward or backward, optimizing character searching. +Absolutely, let's expand on the specific Vim motions that are especially useful for programming and working with structured data files like XML, JSON, and YAML. This additional information will seamlessly integrate into your existing guide, providing focused insights on navigating and manipulating code structures effectively. + +#### Paragraph and Section Motions + +**Commands**: `{`, `}`, `[[`, `]]` +- **Description**: + - `{` and `}` allow you to move quickly between blocks of text separated by blank lines, which is common in documentation blocks within code. + - `[[` and `]]` are particularly useful for jumping through sections of code delimited by braces (`{}`), which is a common structure in many programming languages. This makes them ideal for navigating functions, classes, and other code blocks. + +#### Screen Motions + +**Commands**: `H`, `M`, `L`, `Ctrl-d`, `Ctrl-u` +- **Description**: + - `H` (High) moves the cursor to the top of the screen, `M` (Middle) to the center, and `L` (Low) to the bottom. This helps in quickly relocating the visible area of your code without scrolling. + - `Ctrl-d` (down) and `Ctrl-u` (up) scroll the view half a screen at a time. This is useful for a rapid yet controlled scan through your code, allowing you to maintain context without losing your place. + +#### Document Motions + +**Commands**: `gg`, `G` +- **Description**: + - `gg` quickly jumps to the beginning of the document, which is helpful when you need to refer to initial configurations or declarations in programming files. + - `G` moves to the end of the document. You can also use `G` with a number, like `50G`, to jump directly to a specific line, facilitating precise navigation when you're debugging or reviewing logs that reference specific lines. + +### Tips for Using Motions in Structured Data and Programming + +- **Combining Motions with Searches**: When navigating through structured data like XML or JSON, combine section or paragraph motions with searches. For example, use `/tagName` followed by `n` and `{` to jump directly to specific tags and then navigate around their blocks. +- **Macro Usage**: Consider recording macros when performing repetitive tasks across similar structures. For instance, if you are refactoring code or need to update multiple sections of a JSON file in the same manner, record a macro of the process using `q`, perform the task, and then replay it with `@`. +- **Visual Block Mode**: Utilize `Ctrl-v` to enter visual block mode, which can be incredibly effective for column-based editing in structured files like CSV or configuration blocks in YAML files. + +Adding these specific motions and tips to your Vim guide will not only enrich the content but also enhance the practical utility for developers and data engineers, ensuring they can navigate and edit their files with greater speed and precision. + +--- + +Certainly! Let’s delve deeper into the modal editing philosophy of Vim, which forms the core of its operation and differentiates it from other text editors. This detailed guide will cover the primary modes—Normal, Insert, and Visual—along with a few additional modes you might encounter, such as Command-line and Replace modes. Understanding these modes and when to use them is fundamental to mastering Vim. + +### 1. Normal Mode +**Purpose**: Navigation, text manipulation, and command execution. +- **Entering Normal Mode**: This is the default mode when you open Vim. You can always return to Normal mode from other modes by pressing `Esc`. +- **Key Operations**: + - **Navigation**: Use `h`, `j`, `k`, `l` to move left, down, up, and right, respectively. Advanced movements include `w` (next word), `b` (beginning of word), and `$` (end of line). + - **Editing**: Commands like `dd` (delete line), `cc` (change line), and `yy` (yank or copy line) are activated here. + - **Complex Commands**: Combining commands to perform complex text manipulations, like `d3w` (delete next three words) or `2dd` (delete two lines). + +### 2. Insert Mode +**Purpose**: Typing and editing text directly. +- **Entering Insert Mode**: Press `i` to insert at the cursor, `I` to insert at the beginning of the line, `a` to append after the cursor, and `A` to append at the end of the line. +- **Key Operations**: + - **Text Entry**: Typing behaves as in conventional text editors. + - **Exiting**: Press `Esc` to return to Normal mode. + +### 3. Visual Mode +**Purpose**: Text selection for manipulation. +- **Entering Visual Mode**: Press `v` to start character-wise selection, `V` for line-wise selection, or `Ctrl-v` for block-wise selection. +- **Key Operations**: + - **Expand Selection**: Move the cursor to expand the selection area. + - **Operations on Selection**: Once text is selected, operations like `d` (delete), `y` (yank), and `c` (change) can be applied. + +### 4. Command-Line Mode +**Purpose**: Entering editor commands, searching, and more. +- **Entering Command-Line Mode**: Press `:` from Normal mode. +- **Key Operations**: + - **Commands Execution**: Type commands like `:w` (save), `:q` (quit), and `:/pattern` (search for a pattern). + +### 5. Replace Mode +**Purpose**: Replace existing text without entering Insert mode. +- **Entering Replace Mode**: Press `R` to start replacing text under the cursor until `Esc` is pressed. + +### Transitioning Between Modes +Mastering Vim involves fluidly switching between these modes as needed. Here’s a quick reference on transitioning: +- **Normal to Insert**: `i`, `I`, `a`, `A`, etc. +- **Normal to Visual**: `v`, `V`, `Ctrl-v`. +- **Any to Normal**: `Esc` or `Ctrl-[`. + +### Practical Tips +- **Mode Indicators**: Many users customize their Vim status line to indicate the current mode visually. +- **Learning Tools**: `vimtutor` is an excellent resource for beginners to practice these modes in a tutorial format. + +Understanding and becoming proficient in these modes unlocks the true power of Vim, allowing you to edit and navigate with efficiency and precision that few other editors can match. + +--- + ## `.vimrc` File: Structured Guide with Documentation ### Compatibility and Initial Setup