VIM text editor

Morten Hansen • July 22, 2021

VIM - text editor

General use of VIM
So I've decided to move on from nano as my text-editor and over to VIM. I've used it for some weeks now and can already see the benefits of using VIM. One of the struggles in the start is how to navigate inside the editor. This has resulted in some Googling and self-study in order to find the shortkeys/hotkeys that I think would benefit me the most.

After reading online I've compiled a collection of shortkeys that I think would give me a good start in order to start using VIM. Like many other programs there is the possibility to create a ~/.vimrc file which you can modify and adjust to your own preferences! This is quite genius and can for example get VIM to open text with syntax when files are ending in the correct format, instead of having to type :syntax on every time you access the file.

I also like the possibility to run commands and edit HEX-values directly from VIM.

general

  • vim <filename> creates a file, or opens an existing one.
  • :wq write and quit
  • i enter insert mode (write mode)
  • o / O enter insert mode and creates a newline under/over marker
  • esc exit current mode
  • h,l,j, k move cursor left,right, down, up
  • . repeat last action
  • ~ change case (ctrl + ^ in order to get ~ )
  • u undo last change

marking, pointer

  • e move cursor to the end of word
  • gg / G moves to the start/end of the file
  • 0 / $ move cursor to start/end of the line
  • w / b move cursor to the start of next/previous word
  • ) / ( move cursor to end/ start of next sentence
  • } / { moves to the start/end of next paragraph
  • V / v mark lines / single characters

delete

  • x removes one letter
  • d removes marked text
  • dd / dw removes line / word
  • d0 removes from mark and to start of line
  • D removes from mark and rest of line

copy

  • y copy
  • yw / yy copy word / line
  • y$ copy from cursor and rest of line
  • y0copy from start of line and up to cursor
  • p - paste in selection

windows and tabs

  • vim -O \<filname\> \<filname\> opens two files and splits the view in the middle.
  • :vsplit \<filname\> splits windows with new file
  • vim -p <\filename> <\filename\> splits view in tabs.
  • ctrl+shift arrow / gt in order to switch between tabs.
  • :sp <filename>opens new file and splits windows horizontalt
  • :vsp <fileename>opens new file and splits verical
  • ctrl + w switch between windows
  • ctrl + ws / ctrl + wv splits window
  • ctrl + wqquit window

search in file

  • /<text> in order to search in document
  • n / N move to next/previous hit in search result.
  • ggn / GN jump to first/last result in search
  • ?<text> in order to search in reverse direction from current point in document

commands

  • :! + command in order to run a command like ex. :! ls. If you want to specify current file just append % like ex. :! wc %.
  • :! sh/ :shell gives a shell from VIM (can be used to escalate privileges)

Hex-editing

  • %:!xxd to edit hex-values
  • %:!xxd -r to return to text version (from hex)

 

Sources
VIM
VIM - faq
keycdn
howtoforge
rachaellappan