Random Vim tricks
Aus Stratum 0
Shownotes von Drahflows Talk am 14. Juni 2016 mit Timestamps:
00:00:00 Einführung, Editor-Flamewars 00:01:38 vim starten, :help 00:02:06 vimtutor Searching: 00:03:08 /, *, #, n, N (search, search word below cursor forward/backward, next match, previous match) 00:04:50 % (search matching brace) Registers: 00:05:49 :help registers, :registers, P, p 00:07:10 (spontanes Nachinstallieren von Software) 00:10:15 dd (delete line), u (undo), "add (delete line and save into reg a), "ap (paste from reg a) 00:11:14 side note: :set showcmd (die Lösung für Screencasts) 00:11:48 Register * und + (X Primary Selection, X Clipboard) 00:13:00 Insert Mode: <Ctrl-R>a (insert text from register a), <Ctrl-A> (insert previously inserted text) 00:14:50 Insert Mode: <Ctrl-Y>, <Ctrl-E> (insert text which is above/below cursor) 00:15:45 :set number, :set relativenumber (absolute/relative line numbers on left side) Navigation in Normal Mode (besides hjkl): 00:17:00 w, W, b, B (jump to next/previous word) 00:18:15 fX, tX (jump to next char 'X' / before next char 'X') Edit command + motion, Text objects, ranges: 00:19:41 dw (delete word) 00:20:00 dtX, ctX (delete/change until before next 'X'), ytX (yank into register until before 'X') ... 00:21:15 "inner" range: ci" (delete everything inside ""), cit (change inner HTML tag) ... 00:22:54 das (delete a sentence), cap (change a paragraph) Marks: 00:23:50 ma (set mark a to current position), 'a (jump to line with mark a), `a (jump to mark a) 00:24:26 uppercase marks are (system-)global 00:24:27 Escape auf Caps Lock o.ä. mappen 00:26:47 {, } (jump to begin/end of current "block") 00:27:16 vim mit Input: man bash | vim - 00:27:42 :set scrolloff (scroll offset) 00:27:55 <Ctrl-E>, <Ctrl-Y> (Normal Mode): scroll up/down without cursor Visual Mode: 00:28:30 v (Visual Mode), V (Visual Line), <Ctrl-V> (Visual Block) als Range 00:29:00 {Visual Block}I, {Visual Block}A (insert/append columns) 00:30:00 . (repeat last edit command) Undo/Redo: 00:30:58 u (undo), <Ctrl-R> (redo), g-, g+, :help earlier (time-based undo) Special Chars: 00:33:36 Insert Mode <Ctrl-K>: "compose key" 00:34:30 Insert Mode <Ctrl-V>: "escape" mode (e.g. <Ctrl-V><ESC> => literal ESC char, <Ctrl-V> + hex char, <Ctrl-V><u> + hex char for Unicode) 00:35:23 ga (show hex codepoint of current char), vim -b Character Case: 00:36:28 ~ (switch case), gU<range>, gu<range> (make characters in <range> upper/lowercase) 00:36:45 <Ctrl-A>, <Ctrl-X> (increment/decrement current number. Also hex and octal!) Indentation: 00:37:35 Normal Mode: <<, >>, Insert Mode: <Ctrl-D>, <Ctrl-T> (increase/decrease indentation) 00:37:58 ==, ={motion}, {Visual}= (fix indentation} 00:38:38 0, ^, $ (jump to beginning/first non-space char/end of line) Macros: 00:39:14 qx (start recording macro to register x), q (stop recording), @x (execute macro x) 00:40:24 recorsive macros 00:41:30 gq{motion}, gq{motion} (rewrap lines), :set textwidth, :set colorcolumn, J (join next line) 00:43:38 o, O (insert new line below/above and go to Insert Mode) 00:43:48 p, P, "xp, "xP, {Visual}d (paste buffer below/above current line, delete visual block) Spell Checking: 00:48:33 :set spell (enable spellchecking), :set spelllang, z= (spelling suggestion for word on cursor), ]s (next misspelled word) Tag Files (source code browsing): 00:50:33 <Ctrl-]> (jump to definition of word on cursor), :help tags Autocompletion: 00:51:35 Insert Mode: <Ctrl-N>, <Ctrl-P> (next/previous completion), <Ctrl-X><Ctrl-F> (filename completion), :help completion 00:54:03 :<range>! (filter range through external command, e.g. sort) 00:55:50 :grep (you guessed it), quick fix list, :cn, :cp (next/previous match), :make 00:55:34 gv (last visual selection) Windows/Tabs: 00:58:50 :new, :vnew, :sp, :vsp (split windows), :tabnew, :tabnext, :tabprev (tabs), <Ctrl-W>o (make this the only window) 00:59:45 :buffers (show all open buffers) 01:00:15 :qa! (quit all without saving) 01:00:40 {Visual}o (go to other end of visual selection) 01:01:05 vimdiff 01:01:44 folding, :set foldmethod, zo, zc (open/close fold)