Tech Bloster logo Tech Bloster

How to move the first line to another part of the file?

After deleting the first line with dd, move your cursor to the desired position and type p to paste the deleted line. For example, if you want to place it below a specific line, move to that line and press p.

Vim Command Interface

How to insert text above your cursor position in Vim?

To paste a line above your current cursor position, use the P command. This works similarly to p, but pastes the content above rather than below.

Vim instert mode Command Interface

How to swap two characters or two words in Vim?

Position the cursor under the first character. Type x to delete it, then move the cursor to the new position and type p to place the deleted character after the current cursor position.

To change the order of words, Position the cursor at the start of the word you want to move. You can remove the appropriate delete command, then move the cursor to the target position and use the paste command to place the word in its new location.

Add Text to a File in Vim

How to duplicate a line or a word in Vim?

Position the cursor on the line you want to duplicate. Type yy to yank the line, and then type p to paste it just below the original line.

If you want to duplicate the words "really, really," in the sentence "I really, really, love vim!", place the cursor under the r of the first "really". Then type y2W to yank the two words. Move the cursor to the desired position and type P to paste the duplicate before your cursor.

Save a File in Vim Command

How to undo and redo actions in Vim?

To undo an action, type u. To redo the undone action, press Ctrl-r. For example, if you delete three lines with 3dd, you can undo it with u and redo it with Ctrl-r.

Exit Without Saving Command