www.neotek.ch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computer:software:cheatsheets:vim [2026/09/05 17:54] – admincomputer:software:cheatsheets:vim [2026/09/06 17:43] (current) – [Line Numbers] neotek
Line 1: Line 1:
-===== Vi / Vim Cheatsheet =====+===== Vi / Vim  =====
  
 ==== Open Files, save and exit ==== ==== Open Files, save and exit ====
Line 12: Line 12:
  
 ==== Grammar ==== ==== Grammar ====
 +=== Navigation ===
 +<code>
 +h           # cursor left
 +j           # cursor down
 +k           # cursor up
 +l           # cursor right
 +0           # (zero) move to beginning of the line
 +$           # move to the end of the line
 +w           # move to the beginning of the next word
 +}           # skip to next section
 +H           # Jump to the beginning of the displayed screen
 +M           # Jump to the center of the displayed screen
 +L           # Jump to the bottommost line shown
 +CTRL-f      # Jump down one Page
 +CTRL-b      # Jump up one Page
 +CTRL-d      # Jump down halve a page
 +CTRL-u      # Jump up halve a page
 +gj          # For very long lines that wrap at the screen edge, jump up one line.
 +gk          # For very long lines that wrap at the screen edge, jump down one line.
 +%           # Jump to the next bracket character (){}[]
 +</code>
  
 +=== Edit ===
 <code> <code>
-h            # cursor left +i           # insert at cursor position 
-j            # cursor down +a           # add after cursor position 
-k            # cursor up +o           # insert a line below 
-l            # cursor right +O           # insert a line above 
-0            # (zero) move to beginning of the line +12i <character>   # write the same character 12 times  ( type eight zero i dash <ESC> results in ------------) 
-$            # move to the end of the line +y           # yank text (copy) 
-w            # move to the beginning of the next word +d           # delete 
-}            # skip to next section +dt'         # delete everything to the character ' 
-H            # Jump to the beginning of the displayed screen +df'         # delete everything including character ' 
-M            # Jump to the center of the displayed screen +c           # copy line 
-L            # Jump to the bottommost line shown +y$          # copy to the end of the line (yank) 
-CTRL-f       # Jump down one Page +y5l         # yank five Characters from the cursor position to the right 
-CTRL-b       # Jump up one Page +yt(         # copy everything to the round bracket 
-CTRL-d       # Jump down halve a page +d2w         #  delete two words 
-CTRL-u       # Jump up halve a page +c2j         # change the next two lines 
-gj           # For very long lines that wrap at the screen edge, jump up one line. +:undo or u 
-gk           # For very long lines that wrap at the screen edge, jump down one line. +:redo or CTRL-R
-%            # Jump to the next bracket character (){}[]+
 </code> </code>
 +
 +==== complex editing ====
 +=== Commenting 1 ===
 +<code>
 +CTRL-q       Cursor turns gray as soon you move the cursor keys (or hjkl). Mark everything you want comment
 +SHIFT-i      press Shift Key and i
 +#            type '#'
 +ESC          Press ESC
 +</code>
 +
 +=== Commenting 2 ===
 +Add '# ' in the beginning of line 5 to 12
 +<code>
 +:5,12s/^/# /     
 +</code>
 +
 +=== Uncomment 1 ===
 +<code>
 +CTRL-q       Mark everything you want to remove
 +q            press q
 +</code>
 +
 +=== Uncomment 2 ===
 +remove '# ' from the beginning of line 5 to 12
 +<code>
 +:5,12s/^# //
 +</code>
 +
 +==== Split window ====
 +<code>
 +$ vi file1.txt
 +:split file2.txt     # file2.txt is display in the same terminal window on top of file1.txt
 +:q                   # close file2.txt
 +:vsplit file2.txt    # file2.txt is displayed in the same terminal window to the right of file1.txt
 +:CTRL-w l            # change to the right window
 +:CTRL-w h            # change to the left window
 +:CTRL-w j            # change to the bottom window
 +:CTRL-w k            # change to the top window
 +</code>
 +
 +==== Line Numbers ====
 +<code>
 +:set nu              # show line numbers
 +:set nonu            # hide line numbers
 +:set ruler           # show horizontal and vertical cursor position at the bottom right of the terminal
 +:set rnu             # show relative line numbers
 +:set nornu           # hide relative line numbers
 +</code>
 +
 +==== .vimrc example file ====
 +<code>
 +set hidden
 +set ruler
 +set tabstop=4
 +set mouse=r
 +set number                  (set nu)        # Zeilennummern einschalten
 +set relativenumber          (set rnu)       # relative Zeilennummern!!!!)
 +set relativenumber number   (set rnu nu)    # beides
 +set ruler
 +set nocp
 +filetype plugin on
 +set background=dark
 +hi Comment cterm=italic ctermfg=69 gui=italic guifg=#5d6eff
 +hi Constant ctermfg=172
 +hi Function ctermfg=9
 +</code>
 +
 +
 +
 +
computer/software/cheatsheets/vim.1788630871.txt.gz · Last modified: 2026/09/05 17:54 by admin