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
![Tweet says: "I've been using Vim for about 2 years now, mostly because I can't figure out how to exit it."](https://res.cloudinary.com/practicaldev/image/fetch/s--5lgaDOXl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://testfbdotblog.files.wordpress.com/2019/11/exit_vi.jpg%3Fw%3D574)
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)