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 quiti
enter insert mode (write mode)o
/O
enter insert mode and creates a newline under/over markeresc
exit current modeh
,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 wordgg
/G
moves to the start/end of the file0
/$
move cursor to start/end of the linew
/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 paragraphV
/v
mark lines / single characters
delete
x
removes one letterd
removes marked textdd
/dw
removes line / wordd0
removes from mark and to start of lineD
removes from mark and rest of line
copy
y
copyyw
/yy
copy word / liney$
copy from cursor and rest of liney0
copy from start of line and up to cursorp
- 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 filevim -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 vericalctrl + w
switch between windowsctrl + ws
/ctrl + wv
splits windowctrl + wq
quit window
search in file
/<text>
in order to search in documentn
/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