You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
David Doblas Jiménez ab2066aa4b Up to chapter 11 10 months ago
Mastering Vim Quickly.pdf Add pdf 11 months ago
README.md Up to chapter 11 10 months ago

README.md

Personal notes

  • Chapter 3:

    • vim +X file: ViM will open file at line number X (useful for debugging)
    • vim file +cmd: ViM will open file and execute cmd afterwards, e.g.: vim .ssh/known_hosts +"46d|x" will delete line 46 from known_hosts
  • Chapter 5:

    • From within vim, one could open files by doing: ESC+:e file_to_open
  • Chapter 6:

    • More examples for reading files within ViM:

      • :r file_to_read will insert file_to_read below the cursor in current buffer
      • :0r file_to_read will insert file_to_read before the first line
      • :r!sed -n 2,8p file_to_read will insert linest 2 to 8 from file_to_read below the cursor
      • :r !ls dir_to_list will insert the output of ls dir_to_list below the cursor
    • Navigation through words (if one wants to stop at delimiters and characters like ( ) . { } , $ use w, otherwise use W:

      • w go to the start of next word
      • W go to the start of next Word
      • e go to the end of next word
      • E go to the end of next Word
      • b go to the previous word
      • B go to the previous Word
    • Scrolling pages:

      • Ctrl-d: scroll down half a page
      • Ctrl-u: scroll up half a page
      • Ctrl-f: scroll down full page
      • Ctrl-b: scroll up full page
    • Jumping around the file:

      • gg: go to the top of the file
      • G: go to the bottom of the file
      • {: go to the beginning of the current paragraph
      • }: go to the end of the current paragraph
      • %: go to the matching pair of [], {}, ()
      • 50%: go to the line at 50% of the file
      • :NUM: go to line NUM
    • Navigating inside the window

      • H: move cursor to first line in current window
      • L: move cursor to lowest line in current window
      • M: move cursor to middle of the current window
    • Navigating in Insert mode (don't do it, do it in Normal mode)

      • Shift-Right-arrow: go to the right, word by word
      • Shift-Left-arrow: go to the left, word by word
    • Basic search (done in Normal mode)

      • /+search_pattern+Enter: will search search_pattern in the text
        • n: will search forwards for next occurrence
        • N: will search backwards for previous occurrence
      • ?+search_pattern+Enter: will search search_pattern backwards in the text
        • n: will search backwards for previous occurrence
        • N: will search forwards for next occurrence
      • *: will search forwards for the exact word under the cursor
      • #: will search backwards for the exact word under the cursor
      • g*: will search forwards for the word (pattern) under the cursor
      • g#: will search backwards for the word (pattern) under the cursor
      • / or ? + arrow up/down: go through previous search commands
    • File manager in Vim (netrw)

      • :Ex: open current dir in current Vim window

        • ZZ: close it
      • :Ex directory: open directory in current Vim window

      • :Sex: open current dir in horizontal split window (same as :Ex)

      • :Vex: open current dir in vertical split window

      • :Tex: open current dir in new tab

      • :Lexplore: open current dir in vertical split window (same as :Vex)

      • :40vs +Ex: open current dir in vertical split window with width of 40 columns

      • Vim can open directories as well to give you a list of all files and list all subdirs:

        • Enter: open file under the cursor or enter dir under cursor
        • D: deletes file under the cursor
        • R: renames file under the cursor
        • X: executes file under the cursor
        • %: creates a new file in current dir
  • Chapter 7:

Skip chapter of configuration

  • Chapter 8:

    • u: undo all recent changes on the current line. It accepts a prefix.
    • Ctrl+r: redo command
    • ea[rlier] num: will go back num changes. It accepts time periods, e.g., earlier 10m
    • lat[er] num: will go forward num changes. It accepts time periods
    • g-: move backward to previous branch. Useful in combination with u
    • g+: move forward to next branch. Useful in combination with u
    • set undodir=~/.vim/undodir: will save the hidden files for persistent undo under this, previously created, directory
  • Chapter 9:

    • Verbs:

      • x: delete character under the cursor to the right

      • X: delete character under the cursor to the left

      • r: replace character under the cursor with another character

      • s: delete character under the cursor and enter the Insert mode

      • y: yank (copy)

      • c: change

      • d: delete

      • v: visually select

    • Modifiers:

      • i: inner (inside)
      • a: a (around)
      • NUM: number
      • t: searches for something and stops before it (search until)
      • f: searches for that thing and lands on it (find)
      • /: find a string (literal or regex)
    • Nouns:

      • w,W: start of next word or WORD

      • b,B: start of previous word or WORD (start of word before)

      • e,E: end of word or WORD

      • s: sentence

      • p: paragraph

      • t: tag (in context HTML)

      • b: block (in context programming)

      • h,j,k,l: left, down, up, right

      • $: end of line

      • ^,0: start of line

      • aw: a (complete) word

      • as: a (complete) sentence

      • ap: a (complete) paragraph

      • iw: inner word

      • is: inner sentence

      • ip: inner paragraph

      • dw: delete word from cursor position to the end of the word

      • cis: change current sentence

      • ci": change a string inside quotes

      • c/hello: change until next occurrence of hello

      • ctY: change everything from here to the letter Y

      • vap: visually select this paragraph

      • dd: delete a line

      • dw: delete to the next word

      • daw: delete the whole current word

      • dt,: delete up until the next comma

      • de: delete to the end of current word

      • d2e: delete to the end of next word

      • dj: delete down a line

      • dt): delete up until next closing paranthesis

      • d/rails: delete up until the first search match for rails

      • 3wd2w: jump 3 words from cursor forward and delete next 2 words

      • dvb: delete a word from cursor to beginnig of a word, including character under cursor

  • Chapter 10

    • Ranges:

      • :s/bad/good/g: changes all words bad to good in the current line

      • 6,11s/bad/good/g: same changes, but in lines 6 to 11

      • %s/bad/good/g: same changes in entire file

      • 28: line 28, e.g., :28s/bad/good/g

      • 1: first line

      • $: last line

      • %: all lines in a file. Similar to 1,$

      • 6,28: lines 6 to 28

      • 11,$: lines 11 to end of the file

      • .,$: current line to end of the file

      • .+1,$: line after current to end of the file

      • .,+4: current to current+5

      • ?a?,/b: between patterns a and b

    • Search and replace:

      • s/\<is\>/was/g: replace only whole word is by was
      • s/\(pretty\|good\)/awesome/g: replace either pretty or good by awesome
      • %s/bad/good/gc: run interactive search and replace (c for confirmation)
    • Search through multiple files:

      • vimgrep warning *.md: will search for the string warning in all markdown files of the current directory
        • :cn: jump to the next match
        • :cN: jump to the previous match
        • :clist: view all the files that contain the matched string
        • :cc number: jump to the specific match number, which you get from :clist
      • vimgrep error **/*.log: search recursive
    • Match that string:

      • :match ErrorMsg /Error/: highlight all matches of string Error with the color defined by ErrorMsg
    • The power of the global command:

      • :[range]g/pattern/cmd: will look for pattern in the file (by default, the whole file unless a range is specified) and execute the cmd command, such as :d for delete
        • :g/error/d: will delete all ocurrences of error in the file
        • :g!/important/d: will delete all lines NOT containing important
        • :g/^\s*$/d: will delete all blank lines ~ g: the global command ~ ^: the start of line ~ \s*: zero or more space characters ~ $: the end of line ~ d: the Ex command delete
      • Delete huge number of lines
        • :g/pattern/d_: avoid the copy of lines to registers (put in the blackhole register _). Very fast!
      • Execute macros with the global command:
        • :g/vim/normal @a: matches all lines with the string vim and executes the macro stored in register a in Normal mode
      • Copy and move lines using :g:
        • :3,9t20: copy lines 3 through 9 after line 20. No matter where your cursor is.
        • :3,9m20: move lines, instead of copy
      • Reverse all the lines:
        • :g/^/m0: will reverse the order of lines

Chapter 11: