From e9982704d18c82ae07392a836cc2474eba923412 Mon Sep 17 00:00:00 2001 From: medusa Date: Fri, 29 Mar 2024 04:06:45 +0000 Subject: [PATCH] Update docs/tech_docs/vim_reference.md --- docs/tech_docs/vim_reference.md | 232 +++++++++++++++++++++++++++----- 1 file changed, 197 insertions(+), 35 deletions(-) diff --git a/docs/tech_docs/vim_reference.md b/docs/tech_docs/vim_reference.md index dfb05c7..aa410e4 100644 --- a/docs/tech_docs/vim_reference.md +++ b/docs/tech_docs/vim_reference.md @@ -1,49 +1,211 @@ -## VIM Guide: Copy, Paste, and Find/Replace Operations +Here's a streamlined outline of the VIM guides, focusing on the most relevant and commonly used topics: -### 1. Copy and Paste Lines +I. Copy, Paste, and Find/Replace Operations + A. Copy and Paste Lines + 1. Copy a Single Line + 2. Paste the Copied Line + B. Copy and Paste Words + 1. Copy a Word + 2. Paste the Copied Word + C. Find and Replace + 1. Find and Replace in the Entire Document + 2. Find and Replace in the Current Line + 3. Find and Replace with Confirmation -#### Copy a Single Line -1. In normal mode, move the cursor to the line you want to copy. -2. Press `yy` to yank (copy) the entire line. +II. Useful Tasks and How to Accomplish Them + A. Searching and Navigating + B. Indenting and Formatting + C. Folding Code + D. Working with Registers + E. Switching Between Files -#### Paste the Copied Line -1. Move the cursor to where you want to paste the copied line. -2. Press `p` to paste after the current line or `P` to paste before the current line. +III. Visual Mode and Text Selection + A. Understanding Visual Mode + B. Entering and Exiting Visual Mode + C. Selecting Text in Visual Mode + D. Operating on Selected Text + E. Visual Mode Tips and Tricks -### 2. Copy and Paste Words +IV. Text Objects and Motions + A. Understanding Text Objects + B. Word and WORD Text Objects + C. Sentence and Paragraph Text Objects + D. Code Block Text Objects + E. Combining Text Objects with Motions + F. Using Text Objects in Visual Mode + G. Indentation Text Objects + H. Line and Column Text Objects + I. Repeating Actions with the Dot Operator -#### Copy a Word -1. Move the cursor to the beginning of the word you want to copy. -2. Press `yiw` to yank (copy) the word under the cursor. +V. Undo and Redo + A. Understanding Undo and Redo + B. Basic Undo and Redo Commands + C. Undo and Redo Tips and Tricks -#### Paste the Copied Word -1. Move the cursor to the desired insertion point. -2. Press `p` to paste after the cursor or `P` to paste before the cursor. +VI. Buffer Management and Navigation + A. Understanding Buffers + B. Listing and Switching Buffers + C. Opening and Closing Buffers + D. Saving and Discarding Changes + E. Buffer Navigation -### 3. Copy and Paste Paragraphs +VII. Marks and Jumps + A. Understanding Marks + B. Setting and Jumping to Marks + C. Special Marks + D. Jumps and the Jumplist -#### Copy a Paragraph -1. Move the cursor to any point within the paragraph you wish to copy. -2. Press `yap` to yank (copy) the entire paragraph, including the trailing newline. `ap` stands for "a paragraph". +VIII. Mastering Registers + A. Understanding Registers + B. Unnamed Register + C. Named Registers + D. System Clipboard Register + E. Read-Only Registers -#### Paste the Copied Paragraph -1. Move the cursor to where you want to paste the paragraph. -2. Press `p` to paste after the current position or `P` to paste before. +IX. Customizing VIM with .vimrc + A. Understanding .vimrc + B. Basic .vimrc Settings + C. Mapping Keys in .vimrc + D. Customizing VIM Plugins in .vimrc -### 4. Find and Replace +This streamlined outline focuses on the most essential and commonly used features of VIM that are relevant to a majority of users. It covers copy/paste operations, useful tasks, visual mode, text objects and motions, undo/redo, buffer management, marks and jumps, registers, and basic customization with .vimrc. -#### Find and Replace in the Entire Document -1. Press `Esc` to ensure you are in normal mode. -2. Type `:%s/old/new/g` and press `Enter`. - - `:%s` is the substitute command for the entire file. - - `old` is the text to find. - - `new` is the text to replace it with. - - `g` is the global flag, replacing all occurrences in each line. +Less commonly used topics like persistent undo, advanced buffer management, complex text object manipulations, Vim scripting, and more specialized topics have been removed to keep the guide concise and focused on the most practical features for everyday VIM usage. -#### Find and Replace in the Current Line -1. With the cursor on the line you want to modify, type `:s/old/new/g` and press `Enter`. +--- + +Sure! Here's a concise reference guide for the Copy, Paste, and Find/Replace Operations, as well as the Useful Tasks in VIM: + +# VIM Reference Guide + +## I. Copy, Paste, and Find/Replace Operations + +### Copy and Paste Lines +- Copy a line: `yy` +- Paste after current line: `p` +- Paste before current line: `P` + +### Copy and Paste Words +- Copy a word: `yiw` +- Paste after cursor: `p` +- Paste before cursor: `P` + +### Find and Replace +- Find and replace in the entire document: `:%s/old/new/g` +- Find and replace in the current line: `:s/old/new/g` +- Find and replace with confirmation: `:%s/old/new/gc` + +## II. Useful Tasks + +### Searching and Navigating +- Search for a pattern: `/pattern` +- Jump to the next occurrence: `n` +- Jump to the previous occurrence: `N` +- Jump to a specific line number: `:line_number` + +### Indenting and Formatting +- Indent a block of code: `V` to select lines, then `>` to indent or `<` to unindent +- Autoindent the entire file: `gg=G` +- Format a paragraph: `gq}` + +### Folding Code +- Create a fold: `zf` followed by a motion command (e.g., `zf5j` to fold the next 5 lines) +- Open a fold: `zo` +- Close a fold: `zc` +- Open all folds: `zR` +- Close all folds: `zM` + +### Working with Registers +- Yank text into a named register: `"register_namey` followed by a motion command +- Paste from a named register: `"register_namep` +- View the contents of all registers: `:reg` + +### Switching Between Files +- Open a new file in a split window: + - Horizontal split: `:sp filename` + - Vertical split: `:vs filename` +- Switch between open files: `Ctrl-w` followed by `h`, `j`, `k`, or `l` +- Close the current file: `:q` + +This reference guide provides a quick overview of the essential copy, paste, find/replace operations, and useful tasks in VIM. Keep this guide handy for quick access to the most commonly used commands and techniques. + +--- + +Sure! Here's a concise reference guide for Visual Mode and Text Selection, Text Objects and Motions, and Undo and Redo in VIM: + +# VIM Reference Guide + +## III. Visual Mode and Text Selection + +### Entering and Exiting Visual Mode +- Enter character-wise visual mode: `v` +- Enter line-wise visual mode: `V` +- Enter block-wise visual mode: `Ctrl-v` +- Exit visual mode: `Esc` or `Ctrl-c` + +### Selecting Text +- Character-wise selection: Use motion commands (`h`, `j`, `k`, `l`, `w`, `b`) +- Line-wise selection: Use `j` or `k` to select entire lines +- Block-wise selection: Use motion commands to select a rectangular block +- Select all text: `ggVG` + +### Operating on Selected Text +- Copy (yank) selected text: `y` +- Cut (delete) selected text: `d` +- Change selected text: `c` +- Indent selected text: `>` to indent, `<` to unindent +- Convert selected text to uppercase: `U` +- Convert selected text to lowercase: `u` + +### Visual Mode Tips +- Switch between selection ends: `o` +- Reselect last visual selection: `gv` + +## IV. Text Objects and Motions + +### Word and WORD Text Objects +- `w`: word (alphanumeric characters and underscores) +- `W`: WORD (non-blank characters separated by whitespace) +- Examples: + - `daw`: delete a word (including trailing whitespace) + - `ciW`: change inner WORD (excluding surrounding whitespace) + - `yiw`: yank inner word (excluding trailing whitespace) + +### Sentence and Paragraph Text Objects +- `s`: sentence (characters ending with `.`, `!`, or `?`, followed by whitespace or end of line) +- `p`: paragraph (block of text separated by blank lines) +- Examples: + - `das`: delete a sentence (including whitespace after the sentence) + - `cip`: change inner paragraph (excluding surrounding blank lines) + - `yap`: yank a paragraph (including surrounding blank lines) + +### Code Block Text Objects +- `(`, `)`, `{`, `}`, `[`, `]`, `<`, `>`: code blocks delimited by matching parentheses, braces, brackets, or angle brackets +- Examples: + - `di(`: delete inside parentheses + - `ca{`: change around curly braces (including the braces) + - `yi[`: yank inside square brackets + +### Combining Text Objects with Motions +- Examples: + - `d2aw`: delete two words + - `c3s`: change three sentences + - `y4p`: yank four paragraphs + +## V. Undo and Redo + +### Basic Undo and Redo Commands +- Undo last change: `u` +- Redo last undone change: `Ctrl-r` +- Undo multiple changes: Press `u` multiple times +- Redo multiple changes: Press `Ctrl-r` multiple times + +### Undo and Redo Tips +- Undo all changes to a line since entering insert mode: `U` +- Repeat last change: `.` (dot) + +This reference guide provides a quick overview of the essential commands and techniques for visual mode and text selection, text objects and motions, and undo and redo in VIM. Keep this guide handy for quick access to these powerful editing features. + +--- -#### Find and Replace with Confirmation -1. To replace with confirmation for each occurrence, add `c` at the end: `:%s/old/new/gc`. -These commands provide a solid foundation for navigating and editing text within VIM, covering basic copying, pasting, and find/replace operations. Remember to always start in normal mode before executing these commands. With practice, these operations will become second nature, allowing you to efficiently edit and manipulate text in VIM. \ No newline at end of file