Wednesday, July 9, 2025

Vi Editor

 vi editor

move in the editor : h right j up k  down l left

move top shift +g

gg down line of the file

:8 go to line 8

/string - search

n keyword to search next

? for backward


delete operation


d+w - delete word

u undo


copy operation

word

yw -copy

p - paste

:10 jump to 10th line

:2 jump to 2nd line

set line number

set number 

to remove line number

set nonu

to make permanent line numbers

e ~/vimrc

vim sample.txt +8

vim sample.txt +/search text

vim +1,2d,wq sample.txt  - d for delete

delete 1 to 2 lines and save

vim +4d,wq sample.txt  - d for delete

it will delete 4th line

vim -d r1.txt r2.txt

In the "Diff mode" video, here are the key takeaways:

  • Using Diff Mode: You can compare two versions of a file using Vim's built-in diff mode with the -d switch (e.g., vim -d file1.txt file2.txt).
  • Navigating Differences: Move between the windows showing differences using Control + W + W.
  • Copying Changes: Use D + O to copy a line from one file to another and D + P to put a line from one file to another.
  • Vertical Split: You can set Vim to show differences in a vertical split by using :vert diffsplit file2.txt and making it persistent by adding set diffopt+=vertical to your .vimrc file.



No comments:

Post a Comment

Vi Editor

 vi editor move in the editor : h right j up k  down l left move top shift +g gg down line of the file :8 go to line 8 /string - search n ke...