website/content/lab-notes/vim.md
2025-01-23 15:11:51 -05:00

876 B

title
vim
  • Sort selected lines: :sort
  • Open man page: :man [command] or \K
  • Open URL: gx
  • Move between splits: ctrl+w [direction]
  • vim-commentary: gc [motion] to comment out
  • Case switching:
    • gU to uppercase
    • gu to lowercase -g~ to toggle
  • Substitute:
    • /g global - sub all in line
    • :%s/ - substitute in all lines
    • :5,12s/ substitute from lines 5 to 12
    • :.,+2s/ substitute this line (.) and the next 2
    • :g/^foo/s/bar/baz/g substitute all instances of bar with baz on lines beginning with foo
    • /c - ask for confirmation
  • Windows
    • :sp [filename] horizontal split, optionally open file
    • vsp vertical split
    • ctrl+w w move between windows
    • ctrl+w = resize windows to be equal
    • ctrl+w q close window
    • ctrl+w <direction> move window