bookmarks/cheat/vim.md
2020-07-19 11:15:52 +02:00

2.0 KiB

Remove trailing spaces

:%s/\s\+$//e

Create a password-protected file using vim:

vim -x ostechnix.txt

To remove the password, open the file using vim:

vim ostechnix.txt

And type:

:set key=

Finally type :wq to save and close the file.

Indent the whole file in VIM (Source)

gg=G

Text selection (Source)

V       - selects entire lines
v       - selects range of text
ctrl-v  - selects columns
gv      - reselect block

Basics

  • :open FILE_PATH : open a file

Executing commands (shell)

use current buffer as input of a shell command

  • :%! grep hello to search for all lines containing hello in the current buffer (Source)

Window management

  • :tabe filename to open a file in a new tab (Source)
  • gT and gt can be used to switch between tabs (Source)
  • vim -p file1 file2 to open files in tabs (Source)
  • :sp [file] or Ctrl+W, s : split the window (horizontally) (Source)
  • :vsp [file] or Ctrl+W, v : split the window (vertically) (Source)
  • Ctrl+w, l : move to the right window from the left (Source)
  • Ctrl+w, h : move to the left window again (Source)
  • To find more commands: How To Use VIM Split Screen

Buffer management

  • :bf go to first file
  • :bn go to next file
  • :bp go to previous file
  • :bl go to last file
  • :bw close file
  • :help buffer to find more information