Skip to content

Instantly share code, notes, and snippets.

@sphingu
Last active December 27, 2021 15:19
Show Gist options
  • Save sphingu/5add27163528d7feda0075ff25d9be04 to your computer and use it in GitHub Desktop.
Save sphingu/5add27163528d7feda0075ff25d9be04 to your computer and use it in GitHub Desktop.
Mastering the vi and Vim Editors on the Linux, Unix, Mac, and Windows Operating Systems

Essential Navigation Commands

:q - quit :q! - force quit

:wq - write & quit

:23 - go to line No. 23

:$ - go to last line

:set ruler - set vim setting to show ruler

:set noruler - set vim setting to hide ruler

:set ruler! - set vim setting to toggle ruler

j - move down

k - move up

h - move left

l - move right

ctrl+f - move page down

ctrl+b - move page up

w - word forward

b - word backword

W - word forward with considering whitespace only

B - word backward with considering whitespace only

0 - go to start of the line

^ - go to first word of line

$ - go to last word of line

gg - go to first line

G - go to last line

29gg - go to 29th line

29G - go to 29th line

ctrl+G - display status line at bottom

@sphingu
Copy link
Author

sphingu commented Dec 27, 2021

Search, find, join, replace, Substritute

fb - search for 'b' character forward in current line
Fb - search for 'b' character backward in current line
; - repeat search same direction
, - repeat search opposite direction

tb - move to before first occurance of 'b' forward in current line (only if it is not before searched character)
;b - move to before first occurance of 'b' forward in current line (can repeat unlike tb command)
Tb - backward to tb command

dtw - delete till 'w' character found
dt[space] - delete till space found

/test - search for 'test' word in entire file forward
?test - search for 'test' word in entire file backward

* - search for current cursor word in entire file forward
# - search for current cursor word in entire file backward

n - for next search same direction
N - for next search opposite direction

d => /This - will delete text untill it find 'This' word
"ay => /z - will copy text till it find 'z' character

:set is? - check whether (insearch) is enable or not
:set is - enable (insearch)
:set hls? - check whether (hlsearch) is enable or not
:nohls - remove highlights

Substitute - :[range]s/old/new/[flags]

:1s/is/isnot/ - in first line, 'is' will replace by 'isnot'
:1,5s/for/FOR/g - in first five lines, 'for' will replace by 'FOR' for all occurance in line
:%s/for/FOR/g = :1,$s/for/FOR/g - same as above but for all lines
:/Test1/,/Test2/s/net/org/g - replace 'net' with 'org' for all occurance between 'Test1' and 'Test2'
:s#one/two#three/four# - used here '#' sign to ignore conflict with '/'. can use any character instad of '#' as seperator

:set nu - turn on line numbering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment