vim stuff

Posted on January 15, 2022 by vhs
Tags: vim
  • you can sort multiple lines by the first letter of each line, by highlighting the bunch and executing :sort

  • you can edit multiple lines by enting visual mode <ctrl>v and then hitting I or A entering your edit and pressing Esc

  • you can also append to the end of the line by hitting $ before the A

  • hello you can input x amount of chars at once with: <x> i <char> rgoodbye

  • you can replace x amount of chars with a char by highlighting the text then r <char>

Capture groups

using vimgrep

You can use vimgrep to capture some text that matches a particular regex.

:vimgrep /['"]github[^'"]*['"]/ %

using a global search and replace.

You can define a capture group like this /\(my_capture_group\)/

For example for all lines that have hello. Highlight the lines you want to run the search and replace command on and then :s/\(.*hello.*\)/\1 \r goodbye. The 1 represents the text we subbed out.