DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

FlΓ‘via Bastos
FlΓ‘via Bastos

Posted on • Originally published at flaviabastos.ca on

TIL: How to move a line in Vim

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."
Twitter profile mocking how non-intuitive is exiting the Vim editor.

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)

Dream Big


Use any Linode offering to create something unique or silly in the DEV x Linode Hackathon 2022 and win the Wacky Wildcard category.

β†’ Join the Hackathon <-