> As recommended by other people I have 'inoremap jj <ESC>' defined in
> my vimrc and it works well for most of the time.
I would recommend something other than mapping jj to Esc (e.g. external
to Vim, map CapsLock to Esc), but to each his own.
> A few days ago when I copy-n-paste a lot of text into vim, the result
> was always wrong. It took me quite a while before I figured out that
> there was a substring "jj" included in the text to be pasted. For now
> I often :set paste before copying large text to avoid unexpected
> behavior.
>
> So I wonder if the `jj' mapping can be ignored when doing copy-n-paste
> and only work when I'm typing from a keyboard.
Not in the general case, no. Vim running under a terminal doesn't
necessarily have a way to detect that you're copy-pasting (rather than
typing).
One thing that makes this easier is the 'pastetoggle' option (short=
'pt'). It allows you to assign a key to put you in 'paste' mode (where
lots of options are turned off).
See:
:help 'paste'
:help 'pastetoggle'
--
Best,
Ben
If you do this often, you might want to map something else. I have to
admit that the times I've had to paste anything with jj in it are
rather rare, but it's become a habit for me to do :set paste before
dumping in really odd pieces of non-language text just in case. For my
purposes it is essentially never a problem. But YMMV.
c
How are you copy-n-pasting? If you are using a vim with the X11 and
xterm-clipboard features enabled, have mouse=a, and are pasting with
a mouse in a suitable terminal such as GNOME Terminal or xterm, Vim
will detect that you are pasting and disable mappings.
> So I wonder if the `jj' mapping can be ignored when doing copy-n-paste and only
> work when I'm typing from a keyboard.
This is automatic if Vim is properly configured and used with a
proper terminal.
Regards,
Gary
On Sun, Jan 29, 2012 at 9:01 PM, Clark J. Wang <dear...@gmail.com> wrote:
> As recommended by other people I have 'inoremap jj <ESC>' defined in my
> vimrc and it works well for most of the time.
>
> A few days ago when I copy-n-paste a lot of text into vim, the result was
> always wrong. It took me quite a while before I figured out that there was a
> substring "jj" included in the text to be pasted. For now I often :set paste
> before copying large text to avoid unexpected behavior.If you do this often, you might want to map something else. I have to
admit that the times I've had to paste anything with jj in it are
rather rare,
but it's become a habit for me to do :set paste before
dumping in really odd pieces of non-language text just in case. For my
purposes it is essentially never a problem. But YMMV.
c
On 2012-01-29, Clark J. Wang wrote:
> As recommended by other people I have 'inoremap jj <ESC>' defined in my vimrc
> and it works well for most of the time.
>
> A few days ago when I copy-n-paste a lot of text into vim, the result was
> always wrong. It took me quite a while before I figured out that there was a
> substring "jj" included in the text to be pasted. For now I often :set paste
> before copying large text to avoid unexpected behavior.How are you copy-n-pasting? If you are using a vim with the X11 and
xterm-clipboard features enabled, have mouse=a, and are pasting with
a mouse in a suitable terminal such as GNOME Terminal or xterm, Vim
will detect that you are pasting and disable mappings.
Interesting. I was about to suggest setting 'timeoutlen' to 100. But,
that's the opposite of what you're looking for. (It will wait up to 100
milliseconds for the next keystroke.)
I like the idea of 'mapwait', because it seems like the false-positive
rate could be very low (problems w/ spotty internet?), but the
true-positives that it would catch would be pretty numerous. Maybe set
it much lower, though, around 10ms. I'm an okay typist (60 WPM
according to an online test¹), but testing it via some Perl², my minimum
time between keystrokes was around the 50ms mark.
On the other hand, probably a less error-prone approach would be to
provide (or fix?) support for bracketed paste mode³. It's been
available in XTerm for a long time, and it's also supported by
rxvt-unicode. Unsure of its support in derivatives of either. And it
was disabled by default for a long time (might still be?).
--
Best,
Ben
¹: http://patorjk.com/typing-speed-test/
²: perl -MTerm::ReadKey -MTime::HiRes=time -lwe 'my $stop = "="; print "Type $stop to exit"; ReadMode 4; END { ReadMode 0 } my @times; while (1) { next unless defined($k = ReadKey -1); push @times, time; last if $k eq $stop; } print for map { int(1000 * ($times[$_]-$times[$_-1])) } 1..$#times'
³: http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode
> On Sun, 29 Jan 2012, Clark J. Wang wrote:
>
>> On Monday, January 30, 2012 2:24:55 PM UTC+8, Markus Osterhoff wrote:
>>>
>>> * Clark J. Wang <dear...@gmail.com> [120130 07:01]:
>>>> So I wonder if the `jj' mapping can be ignored when doing copy-n-paste and only work when I'm typing from a keyboard.
>>> :set paste
>>> do your paste
>>> :set nopaste
I am not sure if this is possible or the syntax you would use but could you use a mapping to the effect of:
map <c-v> set paste<c-v>set nopaste
You need something to stop the infinite loop and you may want to restrict it to insert mode. I think this makes the above mapping into something like:
inoremap <c-v> set paste<c-v>set nopaste
But I am not sure so please check before you use. You also need to be in command mode for the 'set' 's. This might be possible using something like 'normal:' so again if someone better at these things than me could refine or reject this then that would be great.
Good Luck
On 30 Jan 2012, at 07:18, Benjamin R. Haskell wrote:I am not sure if this is possible or the syntax you would use but could you use a mapping to the effect of:
> On Sun, 29 Jan 2012, Clark J. Wang wrote:
>
>> On Monday, January 30, 2012 2:24:55 PM UTC+8, Markus Osterhoff wrote:
>>>
>>> * Clark J. Wang <dear...@gmail.com> [120130 07:01]:
>>>> So I wonder if the `jj' mapping can be ignored when doing copy-n-paste and only work when I'm typing from a keyboard.
>>> :set paste
>>> do your paste
>>> :set nopaste
map <c-v> set paste<c-v>set nopaste
You need something to stop the infinite loop and you may want to restrict it to insert mode. I think this makes the above mapping into something like:
inoremap <c-v> set paste<c-v>set nopaste
What do you mean by "a terminal"? Are you not in an X11
environment, or are you just using a vim without X11? If the
latter, that's your problem. Vim doesn't have to run as gvim to
take advantage of X11 features. Try using "gvim -v" instead of
"vim", with mouse=a, and see if that helps. That will give you a
terminal-mode vim with X11 features enabled.
Copying and pasting works fine for me using either xterm or GNOME
Terminal, whether using screen or not, and whether TERM is set to
xterm, xterm-color or screen. I've never used dtterm--I just built
xterm for Solaris.
Regards,
Gary
On 2012-01-29, Clark J. Wang wrote:What do you mean by "a terminal"? Are you not in an X11
> On Monday, January 30, 2012 2:56:37 PM UTC+8, Gary Johnson wrote:
>
> On 2012-01-29, Clark J. Wang wrote:
> > As recommended by other people I have 'inoremap jj <ESC>' defined in my
> vimrc
> > and it works well for most of the time.
> >
> > A few days ago when I copy-n-paste a lot of text into vim, the result was
> > always wrong. It took me quite a while before I figured out that there
> was a
> > substring "jj" included in the text to be pasted. For now I often :set
> paste
> > before copying large text to avoid unexpected behavior.
>
> How are you copy-n-pasting? If you are using a vim with the X11 and
> xterm-clipboard features enabled, have mouse=a, and are pasting with
> a mouse in a suitable terminal such as GNOME Terminal or xterm, Vim
> will detect that you are pasting and disable mappings.
>
>
> I usually use vim without X11 from a terminal and the TERM var may be set to
> linux (for Linux), dtterm (for Solaris), xterm-color (for OS X) or screen
> (within GNU screen).
environment, or are you just using a vim without X11?
If the
latter, that's your problem. Vim doesn't have to run as gvim to
take advantage of X11 features. Try using "gvim -v" instead of
"vim", with mouse=a, and see if that helps. That will give you a
terminal-mode vim with X11 features enabled.
Copying and pasting works fine for me using either xterm or GNOME
Terminal, whether using screen or not, and whether TERM is set to
xterm, xterm-color or screen.
I've never used dtterm--I just built
xterm for Solaris.
Regards,
Gary
That depends on how you have Vim configured. See
:help CTRL-V
:help mswin.vim
That particular mapping does have syntax issues, though. For normal
mode I think it would have to be
:nnoremap <C-V> :set paste<CR>"+gP:set nopaste<CR>
but that's off the top of my head and I haven't tested it. Insert
mode is a little trickier. See the help references for more.
Regards,
Gary
Oh, PuTTY. Now I understand. I've never been able to configure
PuTTY to behave like a real xterm--I'm not sure it's even possible--
but I seldom use it in a situation where I need to copy and paste so
I'm not very motivated. When I have to paste, I do what you've
done: :set paste; paste; :set nopaste.
> I've never used dtterm--I just built
> xterm for Solaris.
>
>
> Could you tell me how to build xterm for Solaris? I find TERM=xterm does not
> work well by default on Solaris 11 and TERM=dtterm works fine.
From my notes (from 2005), it was pretty simple:
cd /home/garyjohn/src/SunOS/xterm-165
tar zxf xterm.tar.gz
cd xterm-165/
./configure --prefix=/home/garyjohn/src/SunOS/xterm-165
make
ln -s /home/garyjohn/src/SunOS/xterm-165/xterm-165/xterm ~/bin
I wasn't allowed to install anything in the official places on that
system.
The Solaris system I used also did not support color xterms, so
there were no color xterm terminfo entries. I installed xterm's
terminfo entries under TERMINFO=$HOME/terminfo. An easier solution
may be to put the proper terminfo/termcap definitions in your
~/.vimrc.
Regards,
Gary
> it's become a habit for me to do :set paste before
> dumping in really odd pieces of non-language text just in case.
Why only non-language text--and what do you mean by "non-language"?
If I use vim primarily, almost exclusively, to compose and edit prose, do I need to be concerned? Haven't done any copying and pasting in vim, but do a fair bit of pasting from vim to other apps.
Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eew...@bellsouth.net
"A man should be in the world as though he were not in it
so that it will be no worse because of his life."
- Wendell Berry
I think you'll be fine. Can you think of any words that have 'jj' in
it? That's why we pick that mapping. If you picked, say, 'oo', then
every time you typed the word 'book' or 'school', you would exit insert
mode, which is clearly not the desired behavior. 'jj' is picked because
it should rarely, if ever, come up in normal typing.
Because unless I am pasting some kind of computer generated jibberish
rather than text made of words (language), the sequence 'jj' doesn't
appear-- in English it exists in only one word (and a couple of its
variations), and those are actually, in my experience, usually
misspelled so as not to contain the 'jj' sequence anyway.
So if, for some reason, I'm copying non-language text, I just
automatically paste/nopaste. But it's so rare that it's hardly a
burden.
c
--
Chris Lott <ch...@chrislott.org>
>>> it's become a habit for me to do :set paste before
>>> dumping in really odd pieces of non-language text just in case.
>>
>> Why only non-language text--and what do you mean by "non-language"?
>
> Because unless I am pasting some kind of computer generated jibberish
> rather than text made of words (language), the sequence 'jj' doesn't
> appear-- in English it exists in only one word (and a couple of its
> variations), and those are actually, in my experience, usually
> misspelled so as not to contain the 'jj' sequence anyway.
Thanks, Chris. Seems to be as I guess it might.
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA USA
eew...@bellsouth.net