DEV Community

Flávia Bastos
Flávia Bastos

Posted on • Originally published at flaviabastos.ca on

3 2

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

Give your career some juice. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay