For a text like the following:
This is the line I want to move.
This line should be the first line.
In order to move the first line down, in normal mode* (not edit or insert mode), follow these steps:
- place the cursor at the beginning of the line you want to move – in this case, the first line
- hit
dd
– the line will disappear (it’s the same as using “cut” on a regular text editor) - move the cursor to where the line should be – in this case, after the second line
- hit
p
Voilà!
This line should be the first line.
This is the line I want to move.
NOTES:
- If you are in edit mode and want to go back to normal mode, just hit
ESC
For the sake of completeness, if you need to exit vi and save the changes, hit :
, followed by w
(meaning “write”), followed by q
(meaning “quit”). And if you need to exit without saving , hit :
, followed by q
, followed by !
The post _TIL: How to move a line in Vim was originally published at _flaviabastos.ca
Top comments (0)