Advertisement
efxtv

Most used VI / VIM commands

Apr 3rd, 2025 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | Cybersecurity | 0 0
  1. ⚡ Mosr used VI commands in Linux (VIM text Editor)
  2.  
  3. 💎 Things we are going to learn:
  4. - Quick Navigation
  5. - Text Replacement
  6. - Find match
  7. - Jump to line number
  8. - Highlight match
  9. - Deleting lines
  10. - Enable Line number
  11.  
  12. ##################################################################
  13. Join our telegram channel for more : https://t.me/LinuxClassesEFXTv
  14. ##################################################################
  15.  
  16. 🔹 Replace Text in Vi/Vim 📝
  17. ✅ Replace first occurrence in a line:
  18. :s/old_text/new_text/
  19.  
  20. ✅ Replace all occurrences in a line:
  21. :s/old_text/new_text/g
  22.  
  23. ✅ Replace in the entire file:
  24. :%s/old_text/new_text/g
  25.  
  26. ✅ Replace with confirmation:
  27. :%s/old_text/new_text/gc
  28.  
  29. ✅ Replace in specific lines (e.g., 10-20):
  30. :10,20s/old_text/new_text/g
  31.  
  32. ✅ Replace using regex (e.g., digits → NUMBER):
  33. :%s/[0-9]/NUMBER/g
  34.  
  35. ✅ Replace text containing / using # as a delimiter:
  36. :%s#path/to/old#path/to/new#g
  37.  
  38. ✅ Find a match
  39. /match
  40.  
  41. ✅ Jump to next match
  42. n
  43.  
  44. ✅ Jump to previous match
  45. N
  46.  
  47. ✅ Enable Search Highlighting
  48. :set hlsearch
  49.  
  50. 🔄 Disable Highlighting
  51. :nohlsearch
  52.  
  53. ✅ Search and Highlight a Word
  54. /word
  55.  
  56. ✅ Delete a Single Line
  57. 10d
  58.  
  59. 🔄 Delete Multiple Lines from the Current Position
  60. 5dd
  61.  
  62. 🔥 Delete All Lines
  63. :%d
  64.  
  65. ✅ Temporarily Enable Line Numbers
  66. :set number
  67.  
  68. ❌ Disable Line Numbers
  69. :set nonumber
  70.  
  71. 🔄 Enable Relative Line Numbers (Useful for navigation)
  72. :set relativenumber
  73.  
  74. 🚀 Make Line Numbers Permanent
  75. To enable line numbers every time Vim starts, add this to your nano ~/.vimrc
  76. set number
  77.  
  78.  
  79. 🏷️ Delete a Range of Lines
  80. 10,20d
  81.  
  82. 📷 Delete the Current Line
  83. dd
  84.  
  85. ⚡ Undo changes (deletion)
  86. [ESC]+u
  87.  
  88. 🔁 Redo an Undo
  89. ctrl + r
  90.  
  91. ✅ Copy a Specific Line (10th line)
  92. :10y
  93.  
  94. ✅ Paste last copy (This pastes below the cursor, P above the cursor)
  95. [ESC] + p
  96.  
  97. ✅ Copying the Current Line
  98. :yy
  99.  
  100. ⚡ To copy lines 10 to 20, use
  101. :10,20y
  102.  
  103. ⚡ Add 5 lines
  104. (- O 5 lines after existing line
  105. - o 5 lines before the existing line)
  106. ESC 5O ESC
  107. ESC 5o ESC
  108.  
  109. 🔹 Jump to Specific Lines number
  110. 🔸 Jump to line 50: :50
  111. 🔸 Jump to first line: :1
  112. 🔸 Jump to last line: :$
  113. 🔸 Open a file at line 100:
  114. vi +100 file.txt
  115.  
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement