I'm using mvim on my Mac OS X 10.7.
How can I mark text to do copy, paste, delete, etc operations? From gvim on Windows I'm used to use the shift key for this, but that doesn't work on the Mac.
I'm using mvim on my Mac OS X 10.7.
How can I mark text to do copy, paste, delete, etc operations? From gvim on Windows I'm used to use the shift key for this, but that doesn't work on the Mac.
On windows, GVim uses a special script designed to make it easier to use. The flip side is that you can go a (not very) long way without learning Vim properly.
There are two basic ways to "yank", "put" and "delete" some arbitrary text in Vim:
Using visual selection
This works more or less like what you are used to, well, everywhere: you select a portion of text with visual feedback then act on it.
In normal mode, place your cursor at one end of the text you want to do something with.
Enter visual mode with v
.
Move the cursor to the the other end.
Hit y
to copy the selected text, d
to delete it, c
to delete it and enter insert mode, P
to replace it with the content of the default register.
Done.
v
has two very useful variants: V
to enter visual line mode and <C-v>
to enter visual block mode.
Here is an example with the sequence v<left><left>…<left><left>y
(there are more efficient ways, of course):
See :help visual-mode
.
Using motions and text-objects
This one is very different from the norm and also extremely efficient.
In normal mode, place your cursor at one end of the text you want to do something with. Some text-objects/motions don't require that.
Hit y
(or d
or c
).
Define a range or target on which to act with i(
or f"
.
Done.
Here is an example with this sequence dta
:
See :help motion.txt
.
Of course, it works the same on Windows, Linux and Mac OS X and, of course, you can mix and match these two methods to suit your needs.
The "yanking" example could be achieved with vbbby
, v4by
, v2Fiy
, v?ip<esc>y
, y2Fi
, etc. depending on the number of words/lines you are dealing with and the "deleting" example could be achieved with v<right><right>…<right><right>d
, vll…lld
, vwwwhd
, vfad
, etc.