[go: up one dir, main page]

0% found this document useful (0 votes)
231 views1 page

Vim Cheatsheet PDF

Uploaded by

urdamihai82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views1 page

Vim Cheatsheet PDF

Uploaded by

urdamihai82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Vi

Vi IMproved
IMproved



Go to beggining of next/previous word: . . . . . . . . . . . . . wC / bC
Go to end of a word: . . . . . . . eC , . . . . . . . with interpunction EC
Go to declaration:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gdC
• Cancel command: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+uex
2.5. Insert special sumbols



Shrink/large window by 𝑛 columns: Ctrl+w𝑛<C / Ctrl+w𝑛>C
Same size for all windows: . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+w=C
Mass: . . . . . . . . . . . . . . . . . . . . write :wall , quit :qall , :wqall
• Display unprintable characters: . . . . . . . . . . . . . . . . . :set list
© 2013 Martin Bruchanov, bruxy@regnet.cz • Go to begin/end of paragraph:. . . . . {C / }C , block: [{C / ]}C • Insert ASCII char: . . . . . . . . . . . . . . . . . . . . . . . Ctrl+v code EndE • Perform mass command for all windows: . . :windo command
• Go to begin/end of line: . . . . . . . . . . . HomeC ≈ ^C / EndC ≈ $C • Open name under cursor in new window: . . . . . . . . . Ctrl+wfC
Basic control and conventions Go to next/previous sentence:. . . . . . . . . . . . . . . . . . . . . . . )C / (C
• Show ASCII/UTF-8 of char under cursor:. . . . . . . . . gaC / g8C
• • Suppress control character, e.g. Tab (^I): . . . . . . Ctrl+v TabE 5.2.1. Moving in window
• Key combination – several keys pressed together, e.g. • Go to next/previous line: . . . . . . . . . . . . . . . . . . . EndC ≈ +C / -C
Ctrl+AE means Ctrl+Shift+aE . • Table of Unicode digraphs: . . . . . . . . . . . . . . . . . . . . . . :digraphs • Jump to window line: . . . . . . . . . . . . top HC , middle MC , last LC
• Go to column: . . . . . . . . . . . . . . . . . . . . . . . first 0C ≈ |C ; nth n|C • Insert digraphs: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+k K1 K2E • Jump to 𝑛 th line from top/bottom: . . . . . . . . . . . . . . . 𝑛HC / 𝑛LC
• Key sequence – several keys or combinations pressed gra- • Jump to pair bracket: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . %C
dually, e.g.. Ctrl+wwE means a press of combination Ctrl+w • Digraphs: ± +- ° DG × *X ÷ -: – -N — -M „ :9 “ :6 • Set actual line to: . . . . . . . top zEndC , center z.C , bottom z-C
• Print position, number of lines and chars, etc.: . . . . gCtrl+gC • Define digraphs .3 for „…“ (U+2026): . . . . . . . :dig .3 8230 • Scroll window up/down by:line Ctrl+eC / Ctrl+yC , page
and than a key w .
2.1.1. Marking of position Ctrl+bC / Ctrl+fC , half-page Ctrl+uC / Ctrl+dC
• Working mode – it is displayed bottom right:
• Insert invisible mark a: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . maC
3. Search and replace • Redraw window without scrolling: . . . . . . . . . . . . . . . . . Ctrl+lC
− ■ C – basic command mode, EscE , • Ignore case: . . . . . . . . :set ignorecase , opposite :set noic
− ■ E – insert mode InsC , iC , • Jump to mark a: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 'aC 5.3. Tabs
• Print marks: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :marks • Search forward/backward: . . . . . . . . . . /patternC / ?patternC
− ■ V – visual, used for highlighting of text blocks vC / VC , • Repeat last search: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /C / ?C • Command: . . . . . . . . . . . . . vim -p 𝑓 1, 𝑓 2 … open files in tabs
− ■ ex – command line ex-mode :C . • Erase mark a: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :delmarks a • Create/close tab: . . . . . . . . . . . . . . . . . . . . . . . . . :tabnew / :tabc
• Process text from mark a to b: . . . . . . . . :'a,'b příkaz , e.g. • Ignore case: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /\cpatternC
• Repeat command with typing number 𝑛× of repetitions be- • Jump to next searched place: . . . . . nC forward, NC backward • Close all, except current tab: . . . . . . . . . . . . . . . . . . . . . . . . :tabo
fore command, e.g. 5xC deletes 5 chars from cursor position. :'a,'b !sort will use external command for sort • Go to next/previous:. . :tabn ≈ Ctrl+PageDownE / :tabp ≈
• Search for word under the cursor: . #C forward, . *C backward
Option :set showcmd shows command sequence in bottom 2.2. Deleting, moving and copying of text Ctrl+PageUpE
• Search by ASCII code of „M“:. . . . . . .\%d77, \%x4d, \%o0115
right. • Deletion automaticly stores text in register (for moving) • Search Unicode character „𝛼“ (U+03B1): . . . . . . . . . . \%u03b1 • Move after the fold 𝑛: . . . . . . . . . . . . . . . . . . . . . . . . . . . . :tabm 𝑛
• Help: :help topic , use Tabex for command completion. • Delete:char xC ≈ DelC ; previous char XC ≈ d←C ≈ dhC , • Substitution:. . . . . . . . :substitute/from/to/flag , abbr. :s • Perform mass command: . . . . . . . . . . . . . . . . . . :tabdo command
• Similar commands uses same keys, e.g. fC / FC , tC / TC (see Ctrl+hE ≈ BackSpaceE ; word dwC ≈ Ctrl+wE ; line ddC • Repeat last substitution: . . . . . . . . . . . . . . . . . . . . . :s ≈ :s//~/ • Change tab design: . . . . . . . . . . . . . . . . . . . . . . . . . . :set tabline
below). The difference is direction or range of operation. • Delete up to pair bracket: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d%C • The delimiter / can be any char instead \, " and | • Open name of file under cursor in new tab: . . . . . . Ctrl+wgfC
• Repeat last: . . . . . . . . . . . . . . . . . . . . . . . command .C , macro @@C • Delete to end/beginning of sentence: . . . . . . . . . . . . . . d)C / d(C
• Undo: . . . . . . . . . . . . . . . . . uC ≈ :undo , redo Ctrl+rC / :redo • Delete the rest of line/file: . . . . . . . . . . . . . . . . . DC ≈ d$C / dGC
• Flags:c – confirmation, g – for whole line, p – print, without 6. Visual mode
flag changes only first occurence
• Set or unset options with :set option a :set nooption . • Delete from cursor position to beginning: . . . . . . . . d0C ≈ d^C • Select: . . . . . . . . . . . . . . . . . chars vC , lines VC , cursor sets range
• Cancel highlight: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :nohlsearch
Alone :set displays current options. • Join lines: . . . . . . . . JC add space, . . . . . . . . gJC without space • Block text selection: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+VC
• Search in more files: . . . . . :vimgrep /pattern/g f1 f2 …fn
• Shortening of options:. . . . . . . . . :set ignorecase ≈ :se ic • Copy to register: . . . . . . . . . . . . . . . . . . line YC ≈ yyC , word ywC • Change to upper/lower case: . . . . . . . . . . . . . . . . . . . . . . . . UV / uV
• Execute command on line with: :global/pattern/command
• Line addressing of ex-commands: • Copy to the beginning/end of line: . . . . . . . . . . . . . . . . y0C / y$C • Select: . . . . . . . . . word awV , ()/{}block abV / aBV , no brackets
• Execute where pattern not match:. . . :g!/pattern/command
− :𝑥command . . . . . . . . . . . . . . . . . . . . . . . . . . . . execute on line 𝑥 • More registers: press "k…C before command will save text to ibV / iBV ; XML block with marks atV , inside marks itV
register k. E.g. "kyyC copies line into k
3.1. Regular expressions • Perform command in selected range: . . . . . . :'<,'> command
− :𝑥,𝑦command . . . . . . . . . . . . . . . . . . . . . . . . . . from 𝑥 to line 𝑦
− :.,$command . . . . . . . . . . . . from actual position to the end • Paste content of last used register or last deleted text: after • Begin/end of: . . . . . . . . . . line ^ / $, word \< / \>, file \%^ / \%$
− :%command ≈ :1,$command . . . . . . . . . . . . . . . for whole file pC , before PC cursor, "kppC pastes register k • Last searched pattern/substitution: . . . . . . . . . . . . . . . . . . . & / ~ 7. Abbreviations, key maps and macros
− :.,+𝑥comm ≈ 𝑥 :comm . . . . . . . from cursor to next 𝑥 lines • Special register: "% – current file name, "/ – last search,… • Matches any character: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . (dot) • Define abbreviation: . . . :abreviate abbr full expansion
− :.,$--𝑥 . . . from current position to 𝑥. line from the end • Show content of registers: . . . . . . . . . . . . . . . . . . . . :register a • Or/and: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \| / \& • Abbreviations for insert/ex-mode: . . . . :iabbrev / :cabbrev
− :/pattern1/,/pattern2/ . . . from the first occurrence of • Swaps the next two chars/lines: . . . . . . . . . . . . . . . . . xpC / ddpC • Suppress next special symbol: . . . . . . . . . . \., \&, $, \^, \\, \* • List/delete abbreviations: . . . . . . :ab / :unab abbreviation
line with pattern1 to the first pattern2 • ex-mode: . . . . . . . . . . . . . . delete :d , move :m , copy :co ≈ :t • Atom: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \(pattern\) • Map key x: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :map x commands
• More ex-commands together: . . . . . . . :command1 | command2 • :10,20m0 – move lines 10–20 to the beginning (0) • 𝑁 th reference: . . . . . . . . . . \N, . . . . . . . . . . first \(pattern\) = \1 • Map by mode: . . . . . . . . . . . :map :imap :cmap :nmap :vmap
• Comparison of two files:. . . . . . . . . . . . . .vimdiff file1 file2 • :.,+5d a – delete next 5 lines and store them to reg. a • Ranges: . . . . . . [abcd] ≈ [a-d], [a-zA-Z] ≈ \a, [0-9] ≈ \d • Map key for insert mode: . . . . . . . . . . . . . . . :map! x commands
• Ignored chars and ranges: . . . . . . . . . . . . . . . [^abcd] ≈ [^a-d] • List key mapping: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :map / :map!
2. Edit and save 2.3. Formatting
• Zero or multiple z: . . . . . . . . . . . . . . . . . . . . . . . . . . . z* ≈ z\{0,\} • Delete mapping: . . . . . . . . . . . . . . . . . . . . . :unmap x / :unmap! x
• Set text width: . . . . . . . . . . . . . . . . . . . . . . . . . :set textwidth=𝑛 One or multiple z: . . . . . . . . . . . . . . . . . . . . . . . . . . z\+ ≈ z\{1,\}
• Edit: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :edit file • • Write macro to register a: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . qaC
• Switch on line wrap: . . . . . . . . . . . . . . . . . . . . . . . . . . . . :set wrap One or zero times: . . . . . . . . . . . . . . . . . . . . . . . . . z\? ≈ z\{0,1\}
• Open new empty file: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :enew • • End macro definition: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . qC
• Justify:. . . . . . . . . . . . . . . . . . . . . . . . . . . :center , :right , :left Repetition z: . . . . z\{n\} accurate 𝑛×, z\{n,\} minimal 𝑛×,
• Insert file to current position: . . . . . . . . . . . . . . . . . . :read file • • Perform macro in register a: . . . . . . . . . . . . . . . . . . . . . . . . . . . . @aC
• Format line: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gqqC z\{n,m\} min. 𝑛 and max. 𝑚 times
• Insert output of system command: . . . . . . . . :read !command • Repeat last called macro: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@C
• Format paragraph: . . . . . . . . . . . . . . gqapC jump to end, gwapC
• Save/append file: . . . . . . . . . . . . . . . :write file / :w >> file
• Reverse case of char: . . . . . . . . . . . . . . . . . . . . . . . . . . ~C , line g~~C 4. Folding of text blocks ( :help folding ) • Execute macro a as ex-command: . . . . . . . . . . . . . . . . . . . . . . :@a
• Save/append lines 𝑛 to 𝑚: . . :𝑛,𝑚w file / :𝑛,𝑚w>> file
• Save and quit:. . . . . . . . . . . . . . . . . . . . . . . . . . :wq , enforced :wq!
• Line to upper/lower: . . . . . . . . . . . . . . gUUC / VuC ≈ guuC / VUC • Fold text: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . zfC , selected zfV 8. Spell checking
• Whole file to upper/lower case: . . . . . . . . . . . . gggUGC / ggguGC • Jump to beginning/end of fold: . . . . . . . . . . . . . . . . . . . [zC / ]zC
• Quit without save: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :q! ≈ ZQC • Switch on spelling:. . . . . . . . . . :set spell spelllang=cs,en
• While line/file ROT13 encoding: . . . . . . . . . . . . . g??C / ggg?GC • Open fold under the cursor: . . . . . . . . . . . . zoC , recursively zOC
• Quit and save when file was changed:. . . . . . . . . . . . . :x ≈ ZZC • Search next/previous mistype: . . . . . . . . . . . . . . . . . . . . ]sC / [sC
2.3.1. Indentation • Open/close all: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . zRC / zMC
• Go to file under the cursos:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . gfC • Add to dictionary a word under cursor: . . . . . . . . . . . . . . . . . zgC
Shift line: . . . . . . . . . . . . >>C , Ctrl+tE of :set shiftwidth=𝑛 • Switch fold-unfold:. . . . . . . . . . . . . . . . . . . . . zaC , recursively zAC
• Change name of current file: . . . . . . . . . . . . . . . . . . . . . :f jméno • • Add temporary to dictionary: . . . . . . . . . . . . . . . . . . . . . . . . . . zGC
Shift line leftwards: . . . . . . . . . . . . . . . . . . . . . . . . . . <<C , Ctrl+dE • Highlight folded parts: . . . . . . . . . . . . . . . . :set foldcolumn=5
• Insert before/after: . . . . . . . . char iC / aC , line . . . . . . . . IC / AC • • Set word as bad: . . . . . . . . . . . . . . . . . . . . . . . zwC , temporary zWC
• Insert new line above/below cursor: . . . . . . . . . . . . . . . . . OC / oC • Tabbing: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TabE ≈ Ctrl+iE 5. Edit more files, windows and tabs • Suggest correctly spelled words: . . . . . . . . . . . . . . . . . . . . . . . . z=C
Rewrite:char rC , word cwC , line ccC , text RC ≈ InsInsC • Shift line same as before: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ==C • Always take the first suggestion: . . . . . . . . . . . . . . . . . . . . . . 1z=C
• 5.1. More files (edit buffers)
• Delete char/line and continue edit: . . . . . . . . . . . . . . . . . . sC / SC • Indent block relatively:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . =a{C
• Refresh indentation of whole file:. . . . . . . . . . . . . . . . . . . . . gg=GC
• Start vim: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vim file1 file2… 9. Programmer support
2.1. Moving throught file • Display buffers: . . . . . . . . . . . . . . . . . :ls ≈ :files (numbered)
2.4. Complementation • Run make: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :make
• Open file on 23rd line: . . . . . . . . . . . . . . . . . . . . . . . vim file +23 • Switch to next/previous file: . . . . . . . . . . . . . . . . . :next / :prev
• Complement word before/after cursor: . . . Ctrl+pE / Ctrl+nE • Jump to next/previous error: . . . . . . . . . :cprevious / :cnext
• Cursor: . . . . . . . . . . . . →C ≈ lC , ←C ≈ hC , ↑C ≈ kC , ↓C ≈ jC • Switch to first/last file: . . . . . . . . . :rewind ≈ :first / :last
• Name of file in working directory: . . . . . . . . . Ctrl+x Ctrl+fE • List all errors: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :clist
• Paging: . . . . . . . Ctrl+fC ≈ PageUpE / Ctrl+bC ≈ PageDownE • Perform mass command for all files: . . . . . . . :bufdo command
• Name of directory: . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+x Ctrl+dE • Add window with list of errors: . . . . . . . . . . . . . . . . . . . . . :copen
• Half-paging up/down: . . . . . . . . . . . . . . . . . . . Ctrl+uC / Ctrl+dC 5.2. Windows
• Jump to 𝑛 th line: . . . . . . . . . . . . . :𝑛 ≈ 𝑛GC , the last :$ ≈ GC • Whole line: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+x Ctrl+lE
• New window: . . . . . . . . . . . . . . . . . . . . . . . . . . . . :new ≈ Ctrl+wnC 10. Other
• Jump to percentual line position: . . . . . . . . . . . . . . . . . . . . . . . n%C • Word from dictionary:. . . . . . . . . . . . . . . . . . . . . Ctrl+x Ctrl+kE
• Split window: . . . . . . . . . . . . . . . . . . . . . . . . . :split ≈ Ctrl+wsC • Start shell: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . :shell
• Display current line number: . . . . . . . . Ctrl+gC , :set number • System command (reads $PATH): . . . . . . . . . . Ctrl+x Ctrl+vE
• Vertically split window: . . . . . . . . . . . . . . :vsplit ≈ Ctrl+wvC • Open manpage of command under cursor: . . . . . . . . . . . . . . . KC
• Display number of lines: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . := • Increase/decrease number under cursor: . Ctrl+aC / Ctrl+xC
• Close window: . . . . . . . . . . . . . . . . . . . . . . . . . :close ≈ Ctrl+wcC • Open file under the cursor: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gfC
• Jump to byte position: . . . . . . . . . . . . . . . . . . . . . . . . . . . . :goto 𝑛 • Name of current file: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+r%E
• Close all except current: . . . . . . . . . . . . . . . . :only ≈ Ctrl+woC • Save as color HTML: . . . . . . . :runtime! syntax/2html.vim
• Jump in line before char a forward/backward: . . . . taC / TaC 2.4.1. Completition at ex-command line • Jump to next window: . . . . . . . . . . . . . . . . . . . . . . . . . . . Ctrl+wwC • Wildcard of current file %, e.g. :!context % process current
• Jump in line to char a forward/backward: . . . . . . . . faC / FaC • Insert content of register a: . . . . . . . . . . . . . . . . . . . . . . Ctrl+raex • Shrink/large window by 𝑛 lines: . . . Ctrl+w𝑛-C / Ctrl+w𝑛+C file with ConTEXt
• Repeat last line search forward/backward: . . . . . . . . . . ;C / ,C • Insert word under the cursor: . . . . . . . . . . . . . Ctrl+r Ctrl+aex

You might also like