有趣的vi-Pratical Vim读书笔记


;session
    :mks! start.vim
    :so start.vim
;--session end

;init module
;mov ^v$"ay@a  to register@c  with ^v$h"cy
    ^v$"ay@a
;mov down and exec @c
    :map <F4> @c
;--init end

;test module
;mov to different line and push <F4>
    :set number
    :set nonumber
;--test end

;extend module
;mov ^v$h"ay to register@b with ^v$h"by
    ^v$h"ay
;exec with <F4>
    :map <F2> @a
    :map <F3> @b
;mov :wq to register@b with push <F3>
;exec with push <F2>
    :wq
;--extend end

;exec with <F4>
    :r !uname -a
Linux fiks 3.14.8-200.fc20.i686 #1 SMP Mon Jun 16 22:36:56 UTC 2014 i686 i686 i386 GNU/Linux
;--exec end

;learning 《Practical Vim》
;1. The Vim Way
;Tip 1: Meet the Dot Command
    .
;Tip 2: Don't Repeat Yourself
    C    c$
    s    cl
    S    ^C
    I    ^i
    A    $a
    o    A<CR>
    O    ko
;Tip 3: Take one Step Back,Then Three Forward
    f
    ;
;Tip 4: Act,Repeat,Reverse
    {edit}                    .    u
    f{char}/t{char}            ;    ,
    F{char}/T{char}            ;    ,
    /pattern<CR>            n    N
    ?pattern<CR>            n    N
    :s/target/replacement    &    u
    qx{changes}q            @x    u
;Tip 5: Find and Replace by Hand
    :%s/content/copy/g
    *
    #
;Tip 6: Meet the Dot Formula
    j.
    ;.
    n.
;--1. end

Part Ⅰ    Modes
;2. Normal Mode
;Tip 7: Pause with Your Brush Off the page
;Tip 8: Chunk Your Undos
    u
    <ESC>o        <CR>
;Tip 9: Compose Repeatable Changes
    daw
;Tip 10: Use Counts to Do Simple Arithmetic
    <C-a>
    <C-x>
    10
;Tip 11: Don't Count If You Can Repeat
    2dw        d2w        dw.
;Tip 12: Combine and Conquer
;Operator+Motion=Action
    Trigger        Effect
    c            Change
    d            Delete
    y            Yank into register
    g~            Swap case
    gu            Make lowercase
    gU            Make uppercase
    >            Shift right
    <            Shift left
    =            Autoindent
    !            Filter {motion} lines through an external program
;--2. end
;3. Insert Mode
;Tip 13: Make Corrections Instantly from Insert Mode
    <C-h>
    <C-w>
    <C-u>
;Tip 14: Get Back to Normal Mode
    <Esc>
    <C-[>
    <C-o>
;Tip 15: Paste from a Register Without Leaving Insert Mode
    <C-r>{register}
    <C-r><C-p>{register}
;Tip 16: Do Back-of-the-Envelope Calculations in Place
    <C-r>=
    3*7=    21
;Tip 17: Insert Unusual Characters by Character Code
    Keystrokes                Effect
    <C-v>{123}                Insert character by decimal code
    <C-v>u{1234}            Insert character by hexadecimal code
    <C-v>{nondigit}            Insert nondigit literally
    <C-k>{char1}{char2}        Insert character represented by {char1}{char2} digraph
    :digraphs
;Tip 18: Insert Unsual Characters by Digraph
;Tip 19: Overwrite Existing Text with Replace Mode
    R
    gr
;--3. end
;4. Visual Mode
;Tip 20: Grok Visual Mode
    v
    V
    <C-g>
;Tip 21: Define a Visual Selection
    <C-v>
    gv
;Tip 22: Repeat Line-Wise Visual Commands
    :set shiftwidth=4 softtabstop=4 expandtab
    Vj  >.
;Tip 23: Prefer Operators to Visual Commands Where Possible
;Text Object
;Tip 24: Edit Tabular Data with Visual-Block mode
    <C-v>   x..     gv      r|
    yyp     Vr-
;Tip 25: Change Columns of Text
    <C-v>   jje     c
;Tip 26: Append After a Ragged Visual Block
    <C-v>   jj$     A
;--4. end
;5. Command-Line Mode
;Tip 27: Meet Vim's Command Line
    :
    <C-h>
    <C-w>
    <C-u>
    <C-r>{register}
    :[range]delete [x]
    :[range]yank [x]
    :[line]put [x]
    :[range]copy {address}
    :[range]move {address}
    :[range]join
    :[range]normal {commands}
    :[range]substitute/{pattern}/{string}/[flags]
    :[range]global/{pattern}/[cmd]
;Tip 28: Execute a Command on One or More Consecutive Lines
    :[number]
    :print
    :.
    :$
    :p
    :%p
    Symbol  Address
    1       First line of the file
    $       Last line of the file
    0       Virtual line above first line of the file
    .       Line where the cursor is placed
    'm      Line containing mark m
    '<      Start of visual selection
    '>      End of visual selection
    %       The entire file (shorthand for :1,$)
;Tip 29: Duplicate or Move Lines Using ':t' and ':m' Commands
    :6t.
    :t6
    :t.
    :t$
    :'<,'>t0
;Tip 30: Run Normal Mode Commands Across a Range
    :%normal A;
    :%normal i//
;Tip 31: Repeat the Last Ex Command
    @:  @@
    <C-o>   :bnext  :next   :cnext  :tnext
;Tip 32: Tab-Complete Your Ex Commands
    <C-d>
    :set wildmode=longest,list
    :set wildmenu
    :set wildmode=full
;Tip 33: Insert the Current Word at the Command Prompt
    <C-r><C-w>
;Tip 34: Recall Commands from History
    :history
    :set history=200
    q/
    q:
    <C-f>
;Tip 35: Run Commands in the Shell
    :r!ls
    :shell        exit
    :read !{cmd}
    :r !dir
    :write !sh
    :write ! sh
    :write! sh
;--5. end
;--Part end

;Part Ⅱ    Files
;6. Manage Multiple Files
;Tip 36: Track Open Files with Buffer List
    :ls
    :bprev
    :bnext
    :bfirst
    :blast
    <C-^>
    :buffer N
    :buffers
    :bdelete N1 N2 N3
    :N,M bdelete
;Tip 37: Group Buffers into a Collection with the Argument List
    :args
    :args *
;Tip 38: Manage Hidden Files
    :ls
    :first
    :next
    :argdo {cmd}
    :bufdo {cmd}
;Tip 39: Divide Your Workspace into Split Windows
    <C-w>s
    <C-w>v
    :sp {file}
    :vsp {file}
    <C-w>w
    <C-w>h
    <C-w>j
    <C-w>k
    <C-w>l
    :close
    :on
    <C-w>=
    <C-w>_
    <C-w>|
    [N]<C-w>_
    [N]<C-w>|
;Tip 40: Organize Your Window Layouts with Tab Pages
    :tabedit
    :tab new
    :<C-w>T
    :tabclose
    :tabonly
    :tabnext {N}
    :tabprevious
    gt
    gT
    :tabmove [N]
;--6. end
;7. Open Files and Save Them to Disk
;Tip 41: Open a File by Its Filepath Using ':edit'
    :edit
    :edit %
    :edit %
    :edit %:h
;Tip 42: Open a File by Its Filename Using ':find'
    :set path+=    
;Tip 43: Explore the File System with netrw
    vim .
    :e.
    :E
    :Se
    :Ve
;Tip 44: Save Files to Nonexistent Directories
    :!mkdir -p %:h
    :write
;Tip 45: Save a File as the Super User
;--7. end
;--Part end

;Part Ⅲ    Getting Around Faster
;8. Navigate Inside Files with Motions
;Tip 46: Keep Your Fingers on the Home Row
;Tip 47: Distinguish Between Real Lines and Display Lines
    g
;Tip 48: Move Word-Wise
    w
    b
    e
    ge
    W
;Tip 49: Find by Character
    f
    ;
    f[character]f[character]
;Tip 50: Search to Navigate
;Tip 51: Trace Your Selection with Precision Text Objects
    {v,c,y,d}{a,i}{),b,},],>,',",`}
    it
    at
    <tag>inside</tag>
    {i,a}{w,W,s,p}
;Tip 52: Delete Around,or Change Inside
;Tip 53: Mark Your Place and Snap Back to It
    m{a-zA-Z}
    `{mark}
    ``
    `.
    `^
    `[
    `]
    `<
    `>
;Tip 54: Jump Between Matching Parenteses
    %
;--8. end
;9. Navigate Between Files with Jumps
;Tip 55: Travese the Jump List
    :jumps
    [count]G
    //pattern<CR>/?pattern<CR>/n/N
    %
    (/)
    {/}
    H/M/L
    gf
    <C-]>
    `{mark}/'{mark}
;Tip 56: Travese the Change List
    u
    <C-r>
    :changes
;Tip 57: Jump to the Filename Under the Cursor
    gf
    :set suffixesadd+=.fiks
    :set path?
;Tip 58: Snap Between Files Using Global Marks
    :marks
    m{A-Z}
    :
;--9. end
;--Part end

;Part Ⅳ    Register
;10. Copy and Paster
;Tip 59: Delete,Yank,and Put with Vim's Unnamed Register
    yyp
    ddp
    xp
;Tip 60: Grok Vim's Registers
    "{Registers}
    "ayiw
    "ydd
    ""p
    *_
    "+
    "*
    "=
    "%
    "#
    ".
    ":
    "/
;Tip 61: Replace a Visual Selection with a Register
;Tip 62: Paste from a Register
    <C-r>{register}        ;insert mode
    "{register}p        ;normal mode
;Tip 63: Interact with the System Clipboard
    :set autoindent
;--10. end
;11. Macros
;Tip 64: Record and Execute a Macro
    q{a-zA-Z}q
    @{a-zA-Z}
;Tip 65: Normalize,Strike,Abort
;Tip 66: Play Back with a Count
;Tip 67: Repeat a Change on Contiguous Lines
    :'<,'>normal @a
;Tip 68: Append Commands to a Macro
;Tip 69: Act Upon a Collection of Files
    :edit!
    :argdo normal @a
    :wall
;Tip 70: Evalute an Iterator to Number Items in a List
    :let i=0
    :echo i
    :let i+=1
    :normal i=i

;Tip 71: Edit the Contents of a Macro
    :put c
    :let @a=substitute(@a,'\~','vU','g')
;--11. end
;--Part end

;Part Ⅴ    Patterns
;12. Matching Patterns and Literals
;Tip 72: Tune the Case Sensitivity of Search Patterns
    \c
    ignorecase
    smartcase
;Tip 73: Use the \v Pattern Switch for Regex Searches
    /#\([0-9a-fA-F]\{6}\|[0-9a-fA-f]\{3}\)    
    /\v#([0-9a-fA-F]{6}|0-9a-fA-F]{3})
    /\v#(x{6}|\x{3})
;Tip 74: Use the \V Literal Switch for Verbatim Searches
    /a\.k\.a\.
    /\Va.k.a.
;Tip 75: Use Parentheses to Capture Submatches
;Tip 76: Stake the Boundaries of a Word
;Tip 77: Stake the Boundaries of a Match
    \zs
    \ze
;Tip 78: Escape Problem Characters
    =eacape(@u,getcmdtype(),'\')
;--12. end
;13. Search
;Tip 79: Meet the Search Command
    /
    ?
    n
    N
;Tip 80: Highlight Search Matches
    :se hls
    :se nohls
;Tip 81: Preview the First Match Before Execution
;Tip 82: Count the Matches for the Current Pattern
    :%s/end//gn
;Tip 83: Offset the Cursor to the End of a Search Match
    /{string}/e
;Tip 84: Operate on a Complete Search Match
;Tip 85: Create Complex Patterns by Iterating upon Search History
;Tip 86: Search for the Current Visual Selection
;--13. end
;14. Substitution
:Tip87: Meet the Substitute Command
    :[range]substitute/{pattern}/{string}/[flags]
;Tip 88: Find and Replace Every Match in a File
    %    ;vertical axis
    g    ;horizontal axis
;Tip 89: Eyeball Each Substitution
    :%s/{pattern}/{string}/gc
;Tip 90: Reuse the Last Search Pattern
;Tip 91: Replace with the Contents of a Register
    :%s//0/g
    :%s//\=@0/g
    :%s/Pragmatic Vim/Practical Vim/g
    :let @/='Pragmatic Vim'
    :let @q='Practical Vim'
    :%s//\=@q/g
;Tip 92: Repear the Previous Substitue Command
;Tip 93: Rearrage CSV Fiels Using Submatches
;Tip 94: Perform Arithmetic on the Replacement
;Tip 95: Swap Two or More Words
    :let @/='\v(<change-1>|<change-2>)'
    :%s//\={"change-1":"change-2","change-2":"change-1"}[submatch(1)]/g
    :let swapper={"change-1":"change-2","change-2":"change-1"}
    :echo swapper["change-1"]
    :echo swapper["change-2"]
;Tip 96: Find and Replace Across Mutiple Files
;--14. end
;15. Global Commands
;Tip 97: Meet the Global Command
    :[range]global[!]/{pattern}/[cmd]
;Tip 98: Delete Lines Containg a Pattern
    :let @/='\v\<\/?\w+>'
    :g//d
;Tip 99:    Collect TODO Items in a Register
    :g/TODO
;Tip 100: Alphabetize the Properties of Each Rule in a CSS File
;--15. end
;--Part end

;Part Ⅵ    Tools
;16. Index and Navigate Source Code with ctags
;Tip 101: Meet ctags
    :r!sudo yum install ctags
;Tip 102: Configure Vim to Work with ctags
    :set tags?
    :!ctags -R
;Tip 103: Navigate Keyword Definitions with Vim's Tag Navigation Commands
;--16. end
;17. Compile Code and Navigate Errors with the Quickfix List
;Tip 104: Compile Code Without Leaving Vim
;Tip 105: Browse the Quickfix List
;Tip 106: Recall Results from a Previous Quickfix List
;Tip 107: Customize the External Complier
;--17. end
;18. Search Project-Wide with grep,vimgrep,and Others
;Tip 108: Call grep Without Leaving Vim
    :grep test *
    :cnext
    :cprev
;Tip 109: Customize the grep Program
;Tip 110: Grep with Vim's Internal Search Engine
    :vim[grep][!] /{pattern}/[g][j] {file}
;--18. end
;19. Dial X for Autocompletion
;Tip 111: Meet Vim's Keyword Autocompletion
    <C-n>
    <C-p>
    <C-x><C-n>
    <C-x><C-i>
    <C-x><C-]>
    <C-x><C-k>
    <C-x><C-l>
    <C-x><C-f>
    <C-x><C-o>
;Tip 112: Work with the Autocompletion Pop-Up Menu
    <C-y>
    <C-e>
    <C-l>
;Tip 113: Understand the Source of Keywords
;Tip 114: Autocomplete Words from the Dictionary
;Tip 115: Autocomplete Entire Lines
;Tip 116: Autocomplete Filenames
    :pwd
    :cd ..
    :cd -
;Tip 117: Autocomplete with Context Awareness
;--19. end
;20. Find and Fix Typos with Vim's Spell Checker
;Tip 118: Spell Check Your Work
    :set spell
    :set nospell
    ]s
    [s
    z=
    zg
    zug
;Tip 119: Use Aternate Spelling Dictionaries
;Tip 120: Add Words to the Spell File
    setlocal spellfile+={file}
;Tip 121: Fix Spelling Errors from Insert Mode
    <C-x><C-s>
;--20. end
;21. Now What?
;--Part end

;Other Command
    :!caja ./
    :version
;Combination Of Command
    >G
    yt,
;--learning end

你可能感兴趣的:(vi)