VIM Notes
Generating Number Sequences Quickly
In VIM, you can easily generate number sequences using the following commands:
To generate a sequence from 1 to 5:
:put=range(1,5)
To generate a sequence from 10 to 1 in reverse order:
:put=range(10,1,-1)
Editing
If you ever need to undo/redo an action, you can use the following shortcut:
undo => u
redo => ctrl+r
Selection
To select the entire content in VIM, you can use the following steps:
- Move the cursor to the desired location.
- Enter visual mode by typing
V
. - Type
ip
to select the entire content.
Line Numbers
To display line numbers in VIM, use the command :set nu
. If you want to hide the line numbers, use :set nonu
.
Search Highlighting
To enable search highlighting in VIM, use the command :set hlsearch
. If you want to disable the search highlighting, use :nohlsearch
.
Windows
Opening a New Window
To open a new window in VIM, you can use the following commands:
- To split the window horizontally:
:split
- To split the window horizontally with a specific file:
:split filename
- To split the window vertically:
:vsplit
Closing a Window
To close the current window in VIM, use the command :q
.
Switching Between Windows
To switch between windows in VIM, use the following shortcuts:
- To move to the window on the left:
ctrl+w h
- To move to the window on the right:
ctrl+w l
- To move to the window above:
ctrl+w k
- To move to the window below:
ctrl+w j
Resizing Windows
You can adjust the size of windows in VIM using the following shortcuts:
- To make all windows equal in size:
ctrl+w =
- To maximize the current window:
ctrl+w _
- To increase the height of the current window:
ctrl+w +
- To decrease the height of the current window:
ctrl+w -
- To increase the width of the current window:
ctrl+w >
- To decrease the width of the current window:
ctrl+w <
- To set the window size to a specific value:
:resize 3
- To adjust the window size by a specific value:
:resize +3
- To keep a certain number of lines visible above and below the cursor:
:set scrolloff=3
Moving the Screen
If you need to navigate the screen in VIM, you can use the following shortcuts:
ctrl + y
to move the screen up one linectrl + e
to move the screen down one linez + z
to move the current line to the center of the screenz + t
to move the current line to the top of the screenz + b
to move the current line to the bottom of the screen
For more information on moving the screen in VIM, you can refer to this article.
Clipboard
In VIM, you can copy content to the system clipboard using the command "+y
. This allows you to easily paste the content outside of VIM.
Hope you find these VIM tips helpful in your daily workflow.