Skip to content


Moving text around in vim

Are you still having problems moving text around in vim? Here are some pointers.

Cheat sheet

move lines with dd and p

Getting started with block mode

  • moving around with o and O
  • delete with x or d
  • yank with y – then put before with P and put after with p
  • yank and put after some short lines y$p
  • insert text into multiple lines with A and I

View the register with :registers

Indent an entire file with gg=G

Posted in Geek Vids.

Tagged with .


6 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. François Beausoleil says

    Thanks a lot! More Vim, please.

  2. Lucas d'Acampora Prim says

    good post! I´m getting to know vim, this was very useful!
    would love to see some screencasts on tim pope´s plugins, they seem great!

  3. kblake says

    Great job. Practical and useful. Will be using these commands today! Thank you!

  4. kossnocorp says

    Awesome!

  5. jjulian says

    Great job, Bryan! I used to teach vi way back in the day. Here are some more tips for manipulating text:

    You can preface many commands with a number, indicating the number of chars or words or lines you want to work on.

    5dd (delete the next 5 lines)
    10yy (yank the next 10 lines)
    p (put the yanked/deleted lines below the caret)

    Working with words – you can change words or delete words

    3cw (puts you in edit mode to overwrite the next 3 words)
    5dw (delete the next 5 words)

    'u' is Undo

    Joining lines – use capital J on a line to pull up the next line

    Doing the same thing over and over again? Hit period to repeat the last command. Works really well when deleting indentation – 4x (delete 4 spaces), then down arrow, period, down arrow, period, etc

    Capital G is “go”. So 30G goes to line 30. ctrl-g shows you status (current line #)

    You can specify blocks using numbers too. Bryan, you touched on this with g and G. If you want to work on lines 5 thru 16, you could type :5,16d (to delete them for example)

    This was always one of my favorite vi cheatsheets: http://www.eec.com/business/vi.html

    Have fun in vim! BTW, I use vim all the time, but for serious coding I stay in TextMate. :)

  6. tcol says

    The geek vids are great. Thanks!



Some HTML is OK

or, reply to this post via trackback.

blog comments powered by Disqus


Blog WebMastered by All in One Webmaster.