Monday, January 30, 2012

Vim Visual Mode

Assume - You know VIM to some degree
Assume - You want to make your life easier


Believe it or not, there is something -- somewhat reasonable in VIM and that's visual mode -- NO NOT ANOTHER MODE !!! Isn't Command mode and Normal (ya right normal) mode Insert mode enough!!!

Well, relax, Visual mode is actually intuitive and easy to access.  Anytime you are in Normal mode (press ESC to get to it, type:

---------------------------------------------------
v
---------------------------------------------------

(For Visual mode of course) When in Visual mode, any movement key you press -- including cursor keys will highlight text!  That's right, you can see what you are doing. Remember all the commands I'm going to give you require you to first highlight the text.

Well, here are my favorite things to do in Visual mode (you do know to highlight some text right???)

Cut/Copy/Paste
When you have your text highlighted -- do that of course first -- press
---------------------------
d
----------------------------
That deletes text but it does more than that -- it sticks it into the copy buffer for you to use later (sort of like copy and paste)
-------------------------
y
-------------------------
Yank (y) will take your highlighted text and stuff it into the copy buffer keeping the original on screen.

ONCE you have done either command...move the cursor somewhere else and press:
------------------------
p
-------------------------
This will paste it into your document.  There you have cut/copy/paste...but there is one more.

Indent
Nothing is more important or more frustrating that looking at code where someone refuses to indent.  You know the type:

if ($Fred == 5)
{
echo ("Foo");
if ($Bob == 4)
{
echo ("Stew");
}
}
Hideous!!!
Now highlight all the text you WANT TO INDENT.  Once you do that type:

<< OR >>
All the text moves giving us something like this:

if ($Fred == 5)
{
      echo ($Foo);
      if ($Bob == 4)
     {
          echo $Stew;
      }
}
Much more readable.  Good luck!

No comments:

Post a Comment