2009-07-23

Vim: Visual Modes

I realized that in my last post, I mentioned the Visual and Visual Line modes in Vim without actually mentioning what you would use these for. The visual modes are used for selecting text and doing things like cutting and copying text, or in vim-speak deleting and yanking text, and for running commands on the selected text. Once you change to visual mode, moving the cursor around will automatically select text. Visual line mode works much like visual mode, only you can only select entire lines.

Cutting and copying in visual modes:
  • y - yanks (copies) the selected text

  • d - deletes (cuts) the selected text

Cutting, copying, and pasting in normal mode
  • :y or yy or Y - yanks the current line

  • :ny - yanks line number n

  • :n,my - yanks line numbers n through m, inclusive

  • :d or dd - deletes the current line

  • D - deletes from the current cursor position to the end of the line

  • :nd - deletes line number n

  • :n,md - deletes from line number n through m, inclusive

  • p - puts (pastes) text from the clip board starting to the right of the cursor, or below the cursor if putting entire lines of text

  • P - puts text from the clip board starting to the left of the cursor, or above the cursor if putting entire lines of text

Another important thing when you are editing anything is to know how to undo and redo changes made. This is really easy to do in Vim:
  • u - undo the most recent change

  • U - undo all of the most recent changes to the current line

  • Ctrl + r - redo the last undone change

That pretty much does it for this post. See you next time

No comments:

Post a Comment