How to cut, copy and paste the VIM-way

2007-03-25 Thread Eric Leenman

Hi,

I'm used to cut, copy and paste the windows-way.
Meaning, selecting text and then press CTRL-X, CTRL-C or CTRL-V.

In VIM (and correct me if I'm wrong) you
yank (y) for copy
put (p) for paste
. for cut

With this in mind, how to cut, copy and paste the VIM-way?
Because when I select text and see select-mode in the lowest line
and then press y, I see a letter y in my text and the selected text is gone.
How come?

Rgds,
Eric

_
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/




Re: How to cut, copy and paste the VIM-way

2007-03-25 Thread A.J.Mechelynck

Eric Leenman wrote:

Hi,

I'm used to cut, copy and paste the windows-way.
Meaning, selecting text and then press CTRL-X, CTRL-C or CTRL-V.

In VIM (and correct me if I'm wrong) you
yank (y) for copy
put (p) for paste
. for cut

With this in mind, how to cut, copy and paste the VIM-way?
Because when I select text and see select-mode in the lowest line
and then press y, I see a letter y in my text and the selected text is 
gone.

How come?

Rgds,
Eric


The Vim names for cut, copy and paste are delete, yank and put, respectively. 
By default, they use the unnamed register, which is good enough when the 
cut/copy and the paste happen within a single instance of Vim. To use the 
clipboard, specify register + by using either a + prefix to the Normal-mode 
commands y d p P or by postfixing a + argument to the :y[ank] :d[elete] and 
:pu[t] Ex-commands (which accept a range).


The difference between Select mode and Visual mode is that in Select mode, any 
printable-character key hit causes the character in question to replace the 
selection. All the Normal-mode commands and Ex-commands mentioned above are 
for Normal or Visual modes, not for Select or Insert/Replace.


To create a Visual (not Select) -mode selection, hit v at one end of the 
selection, then move the cursor to the other end.


See
:help y
:help d
:help p
:help P
:help {motion}
:help motion.txt
:help registers
:help :yank
:help :delete
:help :put
:help :range

Examples:

:%y +
copy the whole file to the clipboard

dd
delete the current line into the default register

+5yy
yank 5 lines (starting at current line) into the clipboard

p
put the default register after the cursor

+P
put the clipboard before the cursor

y$
yank from the cursor to the end of the line

:$put +
add the clipboard after the last line of the file

etc.


Best regards,
Tony.
--
When one woman was asked how long she had been going to symphony
concerts, she paused to calculate and replied, Forty-seven years --
and I find I mind it less and less.
-- Louise Andrews Kent



RE: How to cut, copy and paste the VIM-way

2007-03-25 Thread Sibin P. Thomas

-Original Message-
From: Eric Leenman [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 25, 2007 3:40 PM
To: vim@vim.org
Subject: How to cut, copy and paste the VIM-way

Hi,

I'm used to cut, copy and paste the windows-way.
Meaning, selecting text and then press CTRL-X, CTRL-C or CTRL-V.

In VIM (and correct me if I'm wrong) you
yank (y) for copy
put (p) for paste
. for cut

With this in mind, how to cut, copy and paste the VIM-way?
Because when I select text and see select-mode in the lowest line
and then press y, I see a letter y in my text and the selected text is gone.
How come?

Rgds,
Eric

_
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/




When you press y after selecting text you will replace the entire text with
the y; this is because you are in the select mode. This is the kind of
behaviour you would get in, lets say Notepad or most other editors.

What you want is, to be in the visual mode before pressing y.
There are two ways - 
1. After selecting text (you can see a '---SELECT---' at the bottom of your
screen.) press CTRL-g, that is 'Ctrl + g' to toggle between visual and
select mode.
:h v_CTRL-G

2. Whenever you select text you can directly enter visual mode by default,
instead of the select mode by setting the 'selectmode' options appropriately.
:h selectmode

Regards,
Sibin


DISCLAIMER:
This message (including attachment if any) is confidential and may be 
privileged. Before opening attachments please check them for viruses and 
defects. MindTree Consulting Limited (MindTree) will not be responsible for any 
viruses or defects or any forwarded attachments emanating either from within 
MindTree or outside. If you have received this message by mistake please notify 
the sender by return  e-mail and delete this message from your system. Any 
unauthorized use or dissemination of this message in whole or in part is 
strictly prohibited.  Please note that e-mails are susceptible to change and 
MindTree shall not be liable for any improper, untimely or incomplete 
transmission.


Re: How to cut, copy and paste the VIM-way

2007-03-25 Thread Russell Bateman

(Stupid plain text problem...)

Russell Bateman wrote:

Eric Leenman wrote:

Hi,

I'm used to cut, copy and paste the windows-way.
Meaning, selecting text and then press CTRL-X, CTRL-C or CTRL-V.

In VIM (and correct me if I'm wrong) you
yank (y) for copy
put (p) for paste
. for cut

With this in mind, how to cut, copy and paste the VIM-way?
Because when I select text and see select-mode in the lowest line
and then press y, I see a letter y in my text and the selected text 
is gone.

How come?

Rgds,
Eric


Eric,

Just in case you don't think Sibin's reply was what you were after, 
let me answer more simply the question you asked. You were trying to 
erect a naive list of equivalents between common other-world actions 
and vi/Vim.


There are two ways to copy content to a buffer. y is used to yank a 
copy of it (essentially leaving the text intact--what Sibin refers to 
as replacing the text with itself) and d is used to delete that text 
keeping a copy of it in the buffer. (I'm sorry, when I say buffer 
here, I'm referring not the larger buffer between Vim and the file, 
but to a clipboard. I do not myself know the correct terminology that 
has grown up in the Vim community because I've always been more 
interested in consumingvi/Vim as a productivity tool than in its 
development.) And, yes, p for paste after, P for paste before cursor.


Additionally, and this is a delight that you do not have in Windoz, 
you can choose any of many named buffers (clipboards if you will) to 
put the text, so you can copy up a bunch of discontiguous chunks of 
text into buffers a, b, c, ... etc.:


Mark the beginning of the selection (Vim has a more advanced, visual 
mode for this--I'm only talking vi here) using m + some anchor mark 
(anything from a, b, c, ..., z and maybe more), then move the cursor 
to the end (or beginning if you marked the end) and yank or delete the 
text into the buffer of your choosing:


mx
(movement commands to get somewhere else)
ay'x (or ad'x)

--interpreted as choose () buffer a (a) yank (y) from mark (') x (x). 
(Or, choose buffer a and delete text from current position to mark 
keeping it in that buffer.)


Then you go where you want to paste the text and use the following 
incantation to spit it out:


(movement somewhere)
ap

--interpreted as choose () buffer a (a) and put out (p). Now, if you 
hadn't yanked or deleted any other text in the meantime, you didn't 
need to indicate the named buffer because it would have been the last 
one so you could simply have done


(movement somewhere)
p


Last, if you use the back-tick or grave in place of the single quote 
in the yank or delete commands, you will get not the whole line, but 
the range of characters only. Experimenting with all of this will 
quickly clue you in:


mx
(movement)
ad`x
(movement)
ap

Because I'm a now ancient vi user only dipping a toe intothe wonderful 
world of Vim, the most beautiful, performant and fully featured editor 
in the known universe, I miss out on the cooler stuff, but this is how 
I've always done it.


I strongly suggest input from other Vimmers and would not mind being 
corrected, put in place, growled at for being so unenlightened, etc.


Russ