Tuesday, March 30, 2010

Re: CTRL-C not working with gvim even after sourcing mswin.vim?!

On 30/03/10 12:21, Delyan Kalchev wrote:
> I have a bit strange problem. CTRL-C does nothing (just deselects the
> selected text and does not copy anything, and does not change the
> current content of the clipboard) when used in gvim, while CTRL-V and
> CTRL-X work just fine. When I had used gvim in the past I remember (or
> maybe I'm wrong) it has been working correctly.
> But when vim is executed in the gnome-terminal CTRL-C works perfectly
> and it is not because of any help form the gnome-terminal. I cannot
> explain it currently and can't solve it. So I need some help.
>
> I am using Ubuntu 9.10 with vim installed from the official repo:
> version 7.2.245 or as Ubuntu names it - 2:7.2.245-2ubuntu2
>
> Here is my .vimrc:
>
> set nocompatible
> source $VIMRUNTIME/mswin.vim
> behave mswin
>
> set tabstop=4
> set shiftwidth=4
> set expandtab
> set shiftround
> set hls
> set wildmenu
> set showcmd
> set showmatch
> set ignorecase
> set mouse=a
> set background=dark
>
> set list listchars=tab:»-,trail:·,extends:>,precedes:<
>
> match ErrorMsg '\%>80v.\+'
>
> let NERDTreeMouseMode=1
>
> let g:netrw_browse_split=4
> let g:netrw_hide=0
>
> And here is my .gvimrc:
>
> colorscheme desert
> set guifont=monospace\ 13
>
> Thanks
>

Using Ctrl-C, Ctrl-X and Ctrl-V for copy, cut and paste has nothing to
do with ":behave mswin" (which is just a kind of abbreviation for ":set
selectmode=mouse,key mousemodel=popup keymodel=startsel,stopsel
selection=exclusive"), it has everything to do with sourcing mswin.vim
(which you also do in your vimrc). It ought to work even in gvim, unless
something else is at work.

To see if something else is overriding mswin.vim's mapping, try

:verbose map <C-C>

in a running gvim.

In any case I don't recommend sourcing mswin.vim, which masks useful Vim
key bindings; instead, in Vim it helps to keep in mind that the
clipboard is "register-plus" and to use the following:

- To move data to and from the clipboard, for copy / cut / paste to and
from other applications:

Normal commands
"+x delete (cut) one character to the clipboard
"+d{motion} delete to the clipboard
"+dd delete <count> lines to clipboard
{Visual}"+d delete selection to clipboard
"+y{motion} yank (copy) to the clipboard
"+yy yank <count> lines to the clipboard
{Visual}"+y yank selection to clipboard
"+P put (paste) clipboard before cursor
"+p put clipboard after cursor
Ex-commands (always linewise)
:[range]yank +
:[range]delete +
:[range]put +
which can be abbreviated to :y :d and :pu respectively. For :d and :y
the [range] is the set of (consecutive) lines to be cut or copied, for
:put the [range] is the single line after which to paste (or $ for
"after last line" or 0 for "before first line" or omitted for "after
current line" etc.); or with bang (i.e. :put! +) it is the line before
which to paste.

In gvim you can also use the Edit=>Copy, Edit=>Cut and Edit=>Paste menu
items.

If you hit the colon key in Visual mode, Vim prefills the command-line
with :'<,'> which means "from first to last line of the latest Visual
selection" -- just the range that you need in this case.

To move data within a single Vim, the clipboard isn't needed (and then
it works even in the Linux console, which has no access to X): normally
one would use the "unnamed register" by omitting the "+ before Normal
commands or the + after Ex-commands. Or you can use any one of the 26
"letter registers" by replacing the plus sign by a lowercase letter, or,
for yank and delete, by an uppercase letter to append to the register
instead of replacing its contents.


Notes:
- This vimrc will give you errors if ever you try to use it in a Vim
version missing one or more of the +eval +mouse +wildmenu features, and
this gvimrc will give an error if used in a gvim with any GUI other than
GTK2; but I suppose you don't mind these limitations -- at least for now.
- If 7.2.245 is the "latest" Vim Ubuntu has to offer, then they are
taking their time upgrading: the latest "official" patchlevel is
currently 7.2.411 -- IOW you're missing almost half the bugfixes already
published for Vim 7.2; see http://ftp.vim.org/pub/vim/patches/7.2/README
for a list of what these patches are all about, and (if desired)
http://users.skynet.be/antoine.mechelynck/vim/compunix.htm for a HowTo
page about compiling Vim on Unix/Linux. Also
http://vim.wikia.com/wiki/Build_Vim_with_your_name_included which is
less detailed than the above-mentioned HowTo but has a paragraph about
building Vim on Ubuntu.


Best regards,
Tony.
--
Unfair animal names:

-- tsetse fly -- bullhead
-- booby -- duck-billed platypus
-- sapsucker -- Clarence
-- Gary Larson

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments:

Post a Comment