Vim-Notes

on 2020-12-03 22:16:10.285644
  • technology
  • software

Contents

1. The Vim Way
I. Modes
2. Normal Mode
3. InsertMode
II. Files
4. Normal Mode
5. InsertMode
III. Getting Around Faster
IV. Registers
V. Patterns
VI. Tools

1. The Vim Way

  1. Meet the Dot Command: ., x, u, dd, >G, i, <Esc>
  2. Don’t Repeat Yourself: $, a, A
  3. Take One Step Back, Then Three Forward: f{char}, s, ;
  4. Act, Repeat, Reverse: F{char}/T{char}, /pattern<CR>, :s/target/replacement
  5. Find and Replace by Hand: /target, *, *nn, cw
  6. Meet the Dot Formula: One key to move, One key to execute

I. Modes

2. Normal Mode

  1. Pause with Your Brush Off the Page
  2. Chunk Your Undos
  3. Compose Repeatable Changes: db, b, dw, daw
  4. Use Counts to Do Simple Arithmetic: <C-a>, <C-x>, yyp, cw, cW
  5. Don’t Count If You Can Repeat: d2w/W, 2dw/W, dw.
  6. Combine and Conquer: gu, gU, y, d, c, =

3. Insert Mode

  1. Make Corrections Instantly from Insert Mode: <C-h>, <C-w>, <C-u>
  2. Get Back to Normal Mode: <Esc>, <C-[>, <C-o>, zz
  3. Paste from a Register Without Leaving Insert Mode: yt,, <C-r>0
  4. Do Back-of-the-Envelope Calculations in Place: <C-r>=
  5. Insert Unusual Characters by Character Code: ga, <C-v>, <C-k
  6. Insert Unusual Characters by Digraph: <C-k>{char1}{char2}
  7. Overwrite Existing Text with Replace Mode: R, gR, r, gr

4. Visual Mode

  1. Grok Visual Mode: viw, c
  2. Define a Visual Selection: v, V, <C-v>, gv, o, e
  3. Repeat Line-Wise Visual Commands: <, >
  4. Prefer Operators to Visual Commands Where Possible: vit, U
  5. Edit Tabular Data with Visual-Block Mode: 3j, r, yyp
  6. Change Columns of Text: 26. Append After a Ragged Visual Block: $

5. Command-Line Mode

  1. Meet Vim’s Command Line: :, <C-w><C-u>, <C-v><C-k>, <C-r>{register}
  2. Execute a Command on One or More Consecutive Lines: :print, :digit, :$, :3p, :3d, :2,5p, ., :%p, :%s/old/new/, '<, '>, :/<html>/,/<\/html>/p
  3. Duplicate or Move Lines Using ‘:t’ and ‘:m’ Commands: :copy :co :t, :move :m, dGp
  4. Run Normal Mode Commands Across a Range: :normal, %normal A;, %normal i//
  5. Repeat the Last Ex Command: :@:, :@@, :bn[ext], :bp[revious], <C-o>
  6. Tab-Complete Your Ex Commands: :col<C-d>
  7. Insert the Current Word at the Command Prompt: <C-r><C-w>
  8. Recall Commands from History: q:, <C-f>
  9. Run Commands in the Shell: :!ls, :ls, :!ruby %, :shell, <C-z>, jobs, fg, :read !{cmd}, :write !{cmd}, :[range]!{cmd/filter}, :2,$!sort -t',' -k2, !{motion}, !G

II. Files

6. Manage Multiple Files

  1. Track Open Files with the Buffer List: :bnext, :ls, <C-^>, :bprev, :bfirst, :blast, :buffer N, :buffer {bufname}, :bufdo, :argdo, :bd[elete]
  2. Group Buffers into a Collection with the Argument List: :args {arglist}
  3. Manage Hidden Files: :wirte, :edit!, qall!, :wall,
  4. Divide Your Workspace into Split Windows: <C-w>s, <C-w>v, :edit, :close, :only
  5. Organize Your Window Layouts with Tab Pages: :lcd{path}, :tabe[dit] {filename}, :tabmove [N]

7. Open Files and Save Them to Disk

  1. Open a File by Its Filepath Using ':edit': :edit %<Tab>, :edit %:h<Tab>
  2. Open a File by Its Filename Using ':find': :find, :set path+=app/**
  3. Explore the File System with netrw: :edit ., :e., :Explore, :E.
  4. Save Files to Nonexistent Directories: <C-g>, :!mkdir -p %:h
  5. Save a File as the Super User: :w !sudo tee % > /dev/null

III. Getting Around Faster

8. Navigate Inside Files with Motions

  1. Keep Your Fingers on the Home Row: h,j,k,l
  2. Distinguish Between Real Lines and Display Lines: gj, gk, g0, g$, g^
  3. Move Word-Wise: w, b, e, ge, ea, gea, W, cW
  4. Find by Character: f{char}, ;, ,, F{char}, t{char}, T{char}, dt.
  5. Search to Navigate: /{char}, n, N
  6. Trace Your Selection with Precision Text Objects: vi}, a", i", at, it
  7. Delete Around, or Change Inside: iw, iW, is, ip, aw, aW, as, ap
  8. Mark Your Place and Snap Back to It: m{a-zA-Z}, '{mark}
  9. Jump Between Matching Parentheses: %, S"

9. Navigate Between Files with Jumps

  1. Traverse the Jump List: <C-o>, <C-i>
  2. Traverse the Change List: :changes, .**, **^
  3. Jump to the Filename Under the Cursor: gf
  4. Snap Between Files Using Global Marks: :vimgrep

IV. Registers

10. Copy and Paste

  1. Delete, Yank, and Put with Vim’s Unnamed Register: x, p, xp, dd, ddp, yyp, P, diw
  2. Grok Vim’s Registers: "{register}, "ayiw, "bdd, "ap, "bp, :delete c, :put c, ""p, "0P, :reg "0, "_d{motion}, "+, "+p <C-r>+
  3. Replace a Visual Selection with a Register: m{char}, ``{char} Tip 62. [Paste from a Register](tip62.md):{register}, p, P, gp, `gP``
  4. Interact with the System Clipboard: :set pastetoggle=

11. Macros

  1. Record and Execute a Macro: q, q{register}, :reg a, @{register}, @@
  2. Normalize, Strike, Abort: number@a
  3. Play Back with a Count: qq;.q
  4. Repeat a Change on Contiguous Lines: 0, :normal @a
  5. Append Commands to a Macro: qa, qA
  6. Act Upon a Collection of Files: gg/class<CR>, :argdo, :edit!, :argdo normal @a, :argdo write, :wall, :wnext
  7. Evaluate an Iterator to Number Items in a List: :let i=0, :echo i, <C-r>=i<CR>
  8. Edit the Contents of a Macro: ~, vU, :put a

V. Patterns

12. Matching Patterns and Literals

  1. Tune the Case Sensitivity of Search Patterns
  2. Use the \v Pattern Switch for Regex Searches
  3. Use the \V Literal Switch for Verbatim Searches
  4. Use Parentheses to Capture Submatches
  5. Stake the Boundaries of a Word
  6. Stake the Boundaries of a Match
  7. Escape Problem Characters

13. Search Tip 79. Meet the Search Command

  1. Highlight Search Matches
  2. Preview the First Match Before Execution
  3. Count the Matches for the Current Pattern
  4. Offset the Cursor to the End of a Search Match
  5. Operate on a Complete Search Match
  6. Create Complex Patterns by Iterating upon Search History
  7. Search for the Current Visual Selection

14. Substitution Tip 87. Meet the Substitute Command

  1. Find and Replace Every Match in a File
  2. Eyeball Each Substitution
  3. Reuse the Last Search Pattern
  4. Replace with the Contents of a Register
  5. Repeat the Previous Substitute Command
  6. Rearrange CSV Fields Using Submatches
  7. Perform Arithmetic on the Replacement
  8. Swap Two or More Words
  9. Find and Replace Across Multiple Files

15. Global Commands

  1. Meet the Global Command
  2. Delete Lines Containing a Pattern
  3. Collect TODO Items in a Register
  4. Alphabetize the Properties of Each Rule in a CSS File

VI. Tools

16. Index and Navigate Source Code with ctags

  1. Meet ctags
  2. Configure Vim to Work with ctags
  3. Navigate Keyword Definitions with Vim’s Tag Navigation Commands

17. Compile Code and Navigate Errors with the Quickfix List

  1. Compile Code Without Leaving Vim
  2. Browse the Quickfix List
  3. Recall Results from a Previous Quickfix List
  4. Customize the External Compiler

18. Search Project-Wide with grep, vimgrep, and Others

  1. Call grep Without Leaving Vim
  2. Customize the grep Program
  3. Grep with Vim’s Internal Search Engine

19. Dial X for Autocompletion

  1. Meet Vim’s Keyword Autocompletion
  2. Work with the Autocomplete Pop-Up Menu
  3. Understand the Source of Keywords
  4. Autocomplete Words from the Dictionary
  5. Autocomplete Entire Lines
  6. Autocomplete Filenames
  7. Autocomplete with Context Awareness ##20. Find and Fix Typos with Vim’s Spell Checker Tip 118. Spell Check Your Work
  8. Use Alternate Spelling Dictionaries
  9. Add Words to the Spell File
  10. Fix Spelling Errors from Insert Mode

21. Now What?

21.1 Keep Practicing! 21.2 Make Vim Your Own 21.3 Know the Saw, Then Sharpen It

Comments(30)

Sean on 23 May 2015, 10:40AM

Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.

Strong Strong on 21 May 2015, 11:40AM

Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.

Emma Stone on 30 May 2015, 9:40PM

Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.

Nick Nilson on 30 May 2015, 9:40PM

Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.

Leave A Comment