Creating a file in Vim editor and performing certain operations

Creating a file in Vim editor and performing certain operations

Step 1 : Creating a file

  1. Open terminal.

  2. Vi <filename>.txt

  3. Press i to insert the data in the file.

Step 2: Yanking or Copy

1. Press ESC first to exit the inserting mode.

2. Take the cursor on the line which is to be copied.

3. yy – Yank (copy) the current line, including the newline character.

4. 3yy – Yank (copy) three lines, starting from the line where the cursor is positioned.

5. y$ – Yank (copy) everything from the cursor to the end of the line.

6. y^ – Yank (copy) everything from the cursor to the start of the line.

7. yw – Yank (copy) to the start of the next word.

8. yiw – Yank (copy) the current word.

9. y% – Yank (copy) to the matching character. By default supported pairs are (), {}, and []. Useful to copy text between matching brackets

Step 3 : Paste

  1. Press ESC first to exit the inserting mode.

  2. Take the cursor on the line which is to be pasted.

  3. Command for pasting data in file is press <p>

Step 4 : Delete or Cut

  1. Press ESC first to exit the inserting mode.

  2. Take the cursor on the line which is to be deleted.

  3. Command for deleting the data is press <dd>

  4. <3dd> for deleting 3 lines from where the cursor is.

  5. <d$> for deleting everything to the end line from where the cursor is.

Step 5 : Undo

  1. Press ESC first to exit the inserting mode.

Similar Posts