Feature Request: copy from vim, paste to Cocoa app: Would like menu option to 'Copy with Attributes'

15 views
Skip to first unread message

E. Wing

unread,
Jul 27, 2008, 7:58:41 AM7/27/08
to vim_mac
I was recently writing up some documentation/tutorials and I was doing
my coding/testing in vim. I would then copy and paste my code from Vim
to my word processor (e.g. Pages).

I wanted my documentation to get the font style and syntax coloring
that I have in vim.

But I forgot that Vim copies everything as pure ascii text and there
would be no style information.

I ended up having to go into Xcode and opening up my file there to
copy, but Xcode's syntax highlighting for languages is more limited.

Anyway, I realized that being able to copy text with all the fancy
attributes would be useful. I was thinking a new 'Copy with
Attributes' feature would be handy. This would be somewhat the
analogous counterpart to 'Paste and Match Style'. Perhaps the hot-key
command would also borrow from that: Shift-Cmd-Option-C.

I'm not sure how hard this would be. I presume NSAttributedString is
the best way to transfer fancy text. But I don't know if the vim_mac
code has anything to do with NSAttributedString.

But I thought I would suggest the idea.

Thanks,
Eric

björn

unread,
Jul 27, 2008, 8:54:54 AM7/27/08
to vim...@googlegroups.com
2008/7/27 E. Wing <ewma...@gmail.com>:

Hi Eric,

From the Cocoa perspective this feature is simple to implement: when
copying you can put multiple representations of the text on the
pasteboard. What you're asking for could be achieved by putting the
selection in "rich text" format on the pasteboard. However, (as far
as I know) Vim has no way of giving you the selected text complete
with attributes (such as font, bold, etc.) which makes this feature
hard to implement. In fact, hard enough for me not to want to attempt
it. :-/

Björn

Jjgod Jiang

unread,
Jul 27, 2008, 9:08:39 AM7/27/08
to vim...@googlegroups.com
Hi,

On Sun, Jul 27, 2008 at 8:54 PM, björn <bjorn.w...@gmail.com> wrote:
> From the Cocoa perspective this feature is simple to implement: when
> copying you can put multiple representations of the text on the
> pasteboard. What you're asking for could be achieved by putting the
> selection in "rich text" format on the pasteboard. However, (as far
> as I know) Vim has no way of giving you the selected text complete
> with attributes (such as font, bold, etc.) which makes this feature
> hard to implement. In fact, hard enough for me not to want to attempt
> it. :-/

Well, since we use NSTextStorage (which inherits from NSAttributedString)
to store the text for (at least MMTextView), it might be possible to bypass
the vim process, simply give the text stored in that TextStorage. However,
I do agree there might be some limitations.

- Jiang

Ben Schmidt

unread,
Jul 27, 2008, 1:39:54 PM7/27/08
to vim...@googlegroups.com

Like only being able to copy what's currently in view perhaps?

Particularly for the OP: Have you investigated the :TOhtml command? Its
purpose is to convert a file into HTML using syntax highlighting.

Perhaps also hijacking its functionality could be a way of implementing
this kind of clipboard support. I don't suppose HTML is a flavour you
can put on the pasteboard that other apps will readily recognise is it?
I'd suggest if anything just implementing a Vim command to place
something on the pasteboard with a user-defined flavour and then leave
the rest to Vimscript. Something like

:[range]macyank[!] flavour

to yank text in range (default current line--bang to omit final newline)
into the clipboard with given flavour. Could be quite handy, e.g. you
could possibly even yank bits of binary files as images if desired, etc..

Ben.


E. Wing

unread,
Jul 28, 2008, 4:07:23 AM7/28/08
to vim_mac
> Like only being able to copy what's currently in view perhaps?

That reminds me, I have a lot of problems mouse-selecting a large body
of text. First, I seem to have inconsistent problems with the scroll
speed as I try to drag-select off the top or bottom edge to get more
text. Sometimes it's really slow.

Second, I notice that the cursor position in the editor seems to alter
my selection if I scroll forward or back using the scrollbar or
scrollwheel. For example, if I drag-select text downward so a full
page is highlighted and then I let go of the mouse-button. The cursor
is at the very bottom of the text. Then while the text is still
highlighted, if I scroll up with the scrollbar or scrollwheel, the
cursor moves upward as to not fall off the page. As it does so, it
starts un-highlighting all the text that fell off the bottom of the
page. Conversely, if I scroll down several pages, the cursor gets
stuck at the top of the page and gets pushed down to not fall off the
screen and increases the highlight.

Is there a way to avoid this change in selection? (Maybe the question
needs to be, how do I prevent the cursor from moving on scroll if the
two events aren't separable.)

Thanks,
Eric

Ben Schmidt

unread,
Jul 28, 2008, 9:01:46 AM7/28/08
to vim...@googlegroups.com
> Second, I notice that the cursor position in the editor seems to alter
> my selection if I scroll forward or back using the scrollbar or
> scrollwheel.

This is unavoidable in Vim within its design, as I think you suspected.
Vim always must have the cursor on the screen, and the cursor must
always be either at the beginning or the end of the visual area. So if
the visual area is larger than a page, you must be looking at one end of
it, and since scrolling must move the cursor to keep it on the screen,
this alters the visual area.

If you didn't know already, you may find it handy to learn that you can
use the o key to move the cursor to the other end of the visual area.

I guess one thing that could be considered would be automatically doing
o if scrolling would move the cursor off the screen without doing so,
but not with doing so, i.e. if by simulating o the cursor would stay on
the screen while scrolling. I don't know if this is a very good idea,
though, or whether it would really help that much anyway.

Ben.


dacresni

unread,
Jul 30, 2008, 12:06:55 AM7/30/08
to vim_mac
sounds like a bad idea to me, I think the selection movement is the
result of the selection being directly related to the portion marked
in visual mode. if we could make a meta key (like shift clikc) option

Nico Weber

unread,
Jul 30, 2008, 5:44:31 PM7/30/08
to vim...@googlegroups.com
Hi,

> That reminds me, I have a lot of problems mouse-selecting a large body
> of text. First, I seem to have inconsistent problems with the scroll
> speed as I try to drag-select off the top or bottom edge to get more
> text. Sometimes it's really slow.

in addition to what Ben said, you can click on where you want the
selection to start, hit `ma`, scroll, click at the end, and hit `v'a`
to select the text between the two clicks.

Nico

Reply all
Reply to author
Forward
0 new messages