Quantcast

<Esc> backspaces leaving Insert mode

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

<Esc> backspaces leaving Insert mode

NickC-3

I've put up with this for years.  Whenever I leave Insert mode by typing
the Esc key, the cursor backtracks one char.  I almost always have to
right-arrow, so I would like to change the behaviour so that the cursor
stays where it is.

Is this behaviour built in, or have I got a key mapping somewhere that is
screwing it up?

Many thanks,

--
NickC

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: <Esc> backspaces leaving Insert mode

John Beckett-2
NickC wrote:
> I've put up with this for years.  Whenever I leave Insert
> mode by typing the Esc key, the cursor backtracks one char.
> I almost always have to right-arrow, so I would like to
> change the behaviour so that the cursor stays where it is.
>
> Is this behaviour built in, or have I got a key mapping
> somewhere that is screwing it up?

This is "by design" and won't be fixed. Sometimes people suggest
getting into the habit of pressing a (append) instead of i
(insert). Pressing Esc then gives no surprise.

I have used i and Esc for a long time and don't really have any
trouble finding the Esc key. However, while fixing the following
tip, I became enchanted with the "more elaborate" version of the
"Using the Enter key" section. Much to my astonishment, I have
been using it ever since. There are occasional glitches (I have
to press Ctrl-Enter in quickfix windows and at other times), and
it took a couple of days to get used to it, but it's been good.

http://vim.wikia.com/wiki/Avoid_the_escape_key

John

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

NickC-3
On Fri, 21 May 2010 17:48:14 +1000, John Beckett wrote:


> enchanted with the "more elaborate" version of the "Using the Enter key"
> section. Much to my astonishment, I have been using it ever since. There
> are occasional glitches (I have to press Ctrl-Enter in quickfix windows
> and at other times), and it took a couple of days to get used to it, but
> it's been good.
>
> http://vim.wikia.com/wiki/Avoid_the_escape_key
>
> John

Thanks for that.  Looks like a useful fix.

--
NickC

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Bee-9
In reply to this post by John Beckett-2
On May 21, 12:48 am, "John Beckett" <[hidden email]> wrote:
> NickC wrote:
> > I've put up with this for years.  Whenever I leave Insert
> > mode by typing the Esc key, the cursor backtracks one char.
>
> http://vim.wikia.com/wiki/Avoid_the_escape_key

I tried the "Improving the Esc key" on that page.

inoremap <Esc> <Esc>`^

In Mac terminal and Linux urxvt it has side effects for the arrow
keys.

The arrow keys up, down, right, left produce A, B, C, D respectively.

Hmmm, vim keycodes:
up     ^[OA
down   ^[OB
right  ^[OC
left   ^[OD

Since ^[ is the same as <esc>
is ^[ doing <esc>`^
as though it were typed?

It seems up arrow is now doing:
^[  exit insert mode
O   Begin a new line above the cursor and insert text
A   type the letter "A"

Why?
.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

James  Cole
In reply to this post by John Beckett-2
Hi,

On May 21, 5:48 pm, "John Beckett" <[hidden email]> wrote:
> NickC wrote:
> > I've put up with this for years.  Whenever I leave Insert
> > mode by typing the Esc key, the cursor backtracks one char.
> > I almost always have to right-arrow, so I would like to
> > change the behaviour so that the cursor stays where it is.
[...]
>
> This is "by design" and won't be fixed. Sometimes people suggest
> getting into the habit of pressing a (append) instead of i
> (insert). Pressing Esc then gives no surprise.

I also find this behavior a pain.  It causes me to extra work - more
than just having to press 'a' instead of 'i'.

For example, when I'm using Vim to draft prose, I'll often use
indentation to organise the structure of the text.  So different
paragraphs are at different levels of indentation.  And then I might
take a paragraph I've written and break it into a number of double-
spaced lines so I can more easily see the paragaph's
internal structure.

So if the above paragraph was indented like this

    For example, when I'm using Vim to draft prose, I'll often use
    indentation to organise the structure of the text.  So different
    paragraphs are at different levels of indentation.  And then I
    might take a paragraph I've written and break it into a
    number of double-spaced lines so I can more easily see the
    paragraph's internal structure.

So I might break up like this:

    For example, when I'm using Vim to draft prose,

    I'll often use indentation to organise the structure of the
text.

    So different paragraphs are at different levels of indentation.

    And then I might take a paragraph I've written and

    break it into a number of double-spaced lines so I can

    more easily see the paragraph's internal structure.

Exactly where I break things up depends on the structure of the
sentence, so I have to break it up manually.  Often I'll insert line
breaks after commas or at the ends of sentences. So in the latter case
I'd use ')' to jump to the next sentence, press 'i' then insert two
carriage-returns, then press <ESC>.

Say then the next break I want to put in is at the end of the sentence
I've just moved to the start of its own line.  If <ESC> left the
cursor where it was, the cursor would be at the start of the sentence
and I could just press ')' to go to the ned.  But since <ESC> moves
the cursor back one, I have to press ')' once to get to the start of
the sentence I was just at, and then again to move to the next
sentence (or I could of course type '2)' but either way it's extra
work).

The problem I'm describing tends to occur when you insert some
characters before some pre-existing text and then want to move
forwards in some chunk - such in the aforementioned case of using ')'
but also with things like 'w'.

Hopefully I've convinced you that the behavior of <ESC> moving the
cursor back one position can create needless extra work.  I can't see
any benefit to making <ESC> move the cursor back one like it does (not
saying there isn't, but it's not apparent to me) so I'm wondering why
it does that "by design", as mentioned above?

At least it would be nice if Vim had an option for controlling how
<ESC> effected the cursor position.  i.e. if you could do something
like

    :set noEscMovesCursor

Regards,
James.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Andrei Kulakov
On 05/22/2010 10:23 PM, James Cole wrote:
> Hi,
>
> On May 21, 5:48 pm, "John Beckett" [hidden email] wrote:
>> NickC wrote:
>>> I've put up with this for years.  Whenever I leave Insert
>>> mode by typing the Esc key, the cursor backtracks one char.
>>> I almost always have to right-arrow, so I would like to
>>> change the behaviour so that the cursor stays where it is.
> [...]
>>
>> This is "by design" and won't be fixed. Sometimes people suggest
>> getting into the habit of pressing a (append) instead of i
>> (insert). Pressing Esc then gives no surprise.
>
> I also find this behavior a pain.  It causes me to extra work - more
> than just having to press 'a' instead of 'i'.
>
> For example, when I'm using Vim to draft prose, I'll often use
> indentation to organise the structure of the text.  So different
> paragraphs are at different levels of indentation.  And then I might
> take a paragraph I've written and break it into a number of double-
> spaced lines so I can more easily see the paragaph's
> internal structure.
>
> So if the above paragraph was indented like this
>
>     For example, when I'm using Vim to draft prose, I'll often use
>     indentation to organise the structure of the text.  So different
>     paragraphs are at different levels of indentation.  And then I
>     might take a paragraph I've written and break it into a
>     number of double-spaced lines so I can more easily see the
>     paragraph's internal structure.
>
> So I might break up like this:
>
>     For example, when I'm using Vim to draft prose,
>
>     I'll often use indentation to organise the structure of the
> text.
>
>     So different paragraphs are at different levels of indentation.
>
>     And then I might take a paragraph I've written and
>
>     break it into a number of double-spaced lines so I can
>
>     more easily see the paragraph's internal structure.
>
> Exactly where I break things up depends on the structure of the
> sentence, so I have to break it up manually.  Often I'll insert line
> breaks after commas or at the ends of sentences. So in the latter case
> I'd use ')' to jump to the next sentence, press 'i' then insert two
> carriage-returns, then press <ESC>.
>
> Say then the next break I want to put in is at the end of the sentence
> I've just moved to the start of its own line.  If <ESC> left the
> cursor where it was, the cursor would be at the start of the sentence
> and I could just press ')' to go to the ned.  But since <ESC> moves
> the cursor back one, I have to press ')' once to get to the start of
> the sentence I was just at, and then again to move to the next
> sentence (or I could of course type '2)' but either way it's extra
> work).
>
> The problem I'm describing tends to occur when you insert some
> characters before some pre-existing text and then want to move
> forwards in some chunk - such in the aforementioned case of using ')'
> but also with things like 'w'.
>
> Hopefully I've convinced you that the behavior of <ESC> moving the
> cursor back one position can create needless extra work.  I can't see
> any benefit to making <ESC> move the cursor back one like it does (not
> saying there isn't, but it's not apparent to me) so I'm wondering why
> it does that "by design", as mentioned above?
>
> At least it would be nice if Vim had an option for controlling how
> <ESC> effected the cursor position.  i.e. if you could do something
> like
>
>     :set noEscMovesCursor
>
> Regards,
> James.
>


When in insert mode, cursor is between two chars. When in command mode,
cursor is on top of a char, to make it possible to perform char
operations. When you press escape, cursor either has to move back one
char or forward one char. It can't stay in the place because it's in the
middle and that makes no sense in command mode. If you were at the end
of line, obviously cursor would not be able to move ahead one char which
means behaviour would be inconsistent.

That's the reason in the nutshell. I should not that current behaviour
works just fine for me and if it does not for you, you can always map
esc in ins. mode to do esc and then move forward. -ak

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Christian Brabandt
In reply to this post by James Cole
Hi James!

On Sa, 22 Mai 2010, James Cole wrote:

> At least it would be nice if Vim had an option for controlling how
> <ESC> effected the cursor position.  i.e. if you could do something
> like
>
>     :set noEscMovesCursor

Can't you do something like this:
:inoremap <ESC> <ESC>l
and possibly also
:set ve=onemore

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

NickC-3
In reply to this post by Andrei Kulakov
On Sat, 22 May 2010 23:07:24 -0400, AK wrote:
> That's the reason in the nutshell. I should not that current behaviour
> works just fine for me and if it does not for you, you can always map
> esc in ins. mode to do esc and then move forward. -ak

I also have Bee's problem with unwanted A B C D if I remap <Esc>.

What I did was remap jj (which was already in my vimrc; I just never used
it) to 'imap jj <Esc><Right>', which works perfectly.  So now I have Esc
and jj, best of both worlds perhaps.

James Cole, this might be a workable solution for you.

--
NickC

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Tony Mechelynck
In reply to this post by Bee-9
On 21/05/10 17:58, Bee wrote:

> On May 21, 12:48 am, "John Beckett"<[hidden email]>  wrote:
>> NickC wrote:
>>> I've put up with this for years.  Whenever I leave Insert
>>> mode by typing the Esc key, the cursor backtracks one char.
>>
>> http://vim.wikia.com/wiki/Avoid_the_escape_key
>
> I tried the "Improving the Esc key" on that page.
>
> inoremap<Esc>  <Esc>`^
>
> In Mac terminal and Linux urxvt it has side effects for the arrow
> keys.
>
> The arrow keys up, down, right, left produce A, B, C, D respectively.
>
> Hmmm, vim keycodes:
> up     ^[OA
> down   ^[OB
> right  ^[OC
> left   ^[OD
>
> Since ^[ is the same as<esc>
> is ^[ doing<esc>`^
> as though it were typed?
>
> It seems up arrow is now doing:
> ^[  exit insert mode
> O   Begin a new line above the cursor and insert text
> A   type the letter "A"
>
> Why?
> .
>

Probably because Vim is not discriminating between mappings and keyboard
sequences. I recommend the following:

        :set timeout timeoutlen=5000 ttimeoutlen=100

where:
        'timeout' (boolean) enables timeout on mappings and keycodes
        'timeoutlen' (milliseconds) is the timeout for mappings. It should be
longer than your slowest typing rate (when hesitating about what to type
next as part of a multikey mapping).
        'ttimeoutlen' (milliseconds) is the timeout for keycodes. It should be
shorter than your fastest typing rate but longer than the rate at which
your keyboard driver sends the successive bytes of a multibyte keycode.

The timeouts may be longer or shorter depending on your typing speed and
the line speed between your keyboard and the computer where Vim is
running (which will usually be the computer next to you, but in some
cases it may be a remote computer accessed via X forwarding or ssh).


Best regards,
Tony.
--
A poem:                read aloud:

<> !*''#               Waka waka bang splat tick tick hash,
^"`$$-                 Caret quote back-tick dollar dollar dash,
!*=@$_                 Bang splat equal at dollar under-score,
%*<> ~#4               Percent splat waka waka tilde number four,
&[]../                 Ampersand bracket bracket dot dot slash,
|{,,SYSTEM HALTED      Vertical-bar curly-bracket comma comma CRASH.

Fred Bremmer and Steve Kroese (Calvin College & Seminary of Grand
Rapids, MI.)

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Bee-9
Tony Mechelynck wrote:

> On 21/05/10 17:58, Bee wrote:
> > On May 21, 12:48 am, "John Beckett"<[hidden email]>  wrote:
> >> NickC wrote:
> >>> I've put up with this for years.  Whenever I leave Insert
> >>> mode by typing the Esc key, the cursor backtracks one char.
> >>
> >> http://vim.wikia.com/wiki/Avoid_the_escape_key
> >
> > I tried the "Improving the Esc key" on that page.
> >
> > inoremap <Esc> <Esc>`^
> >
> > In Mac terminal and Linux urxvt it has side effects for the arrow
> > keys.
> >
> > The arrow keys up, down, right, left produce A, B, C, D respectively.
> >...
> > Why?
>
> Probably because Vim is not discriminating between mappings and keyboard
> sequences. I recommend the following:
>
> :set timeout timeoutlen=5000 ttimeoutlen=100

That does not help. Tried with:

vim -N -i NONE -u NONE

Still getting:
The arrow keys up, down, right, left produce A, B, C, D respectively.

Possibly a vim bug?

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

James  Cole
In reply to this post by Andrei Kulakov
Hi,

> When in insert mode, cursor is between two chars. When in command mode,
> cursor is on top of a char, to make it possible to perform char
> operations. When you press escape, cursor either has to move back one
> char or forward one char. It can't stay in the place because it's in the
> middle and that makes no sense in command mode.

Thanks for the explanation, I wasn't aware of that.

>                                                  If you were at the end of
> line, obviously cursor would not be able to move ahead one char which
> means behaviour would be inconsistent.

True, but I don't think that'd be a problem.  At the end of the line
it could move the cursor back one instead of forwards.  Vim's current
behavior is actually just as 'inconsistent'.  It always moves the
cursor back one when returning to normal mode... except when the
cursor is at the start of a line, in which case it instead moves it
forwards one.

Personally I feel that moving the cursor forwards when returning to
normal mode would be a more useful default.  I think that after the
user has finished inserting some text the next thing they will want to
do is more likely to be concerning text located *after* what they've
just inserted (and thus less likely that they will want to do things
concerning the last character they've entered or ones prior to that).
But anyway, that is just based on my intuitive feel, not any empirical
data :)

James.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

James  Cole
In reply to this post by Christian Brabandt
Hi Christian,

> > At least it would be nice if Vim had an option for controlling how
> > <ESC> effected the cursor position.  i.e. if you could do something
> > like
>
> >     :set noEscMovesCursor
>
> Can't you do something like this:
> :inoremap <ESC> <ESC>l
> and possibly also
> :set ve=onemore

Thanks for the info.

It does feel to me to be something for which a built-in option would
be useful (obviously there are various trade-offs as to whether
something is worth putting in as a built-in option or not.. just
IMO).

James.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <Esc> backspaces leaving Insert mode

Andrei Kulakov
In reply to this post by James Cole
On 06/03/2010 12:48 AM, James Cole wrote:
> Hi,
>
>> When in insert mode, cursor is between two chars. When in command mode,
>> cursor is on top of a char, to make it possible to perform char
>> operations. When you press escape, cursor either has to move back one
>> char or forward one char. It can't stay in the place because it's in the
>> middle and that makes no sense in command mode.
>
> Thanks for the explanation, I wasn't aware of that.
>
>>                                                  If you were at the end of
>> line, obviously cursor would not be able to move ahead one char which
>> means behaviour would be inconsistent.
>
> True, but I don't think that'd be a problem.  At the end of the line
> it could move the cursor back one instead of forwards.  Vim's current
> behavior is actually just as 'inconsistent'.  It always moves the
> cursor back one when returning to normal mode... except when the
> cursor is at the start of a line, in which case it instead moves it
> forwards one.


That's of course true, but in normal usage I would say you're about 50
times more likely to hit escape at the end of line rather than at the
start (unless you prefer to type your text backwards). Inconsistency is
a concern here mostly not because it would look or feel strange, but for
things like mappings, macros, etc.

In fact I remember there was a very long protracted argument about this
on #vim irc channel and there were some really great arguments made for
why going back is less inconsistent, I think it involved newlines and
empty lines but I don't remember exactly now.

>
> Personally I feel that moving the cursor forwards when returning to
> normal mode would be a more useful default.  I think that after the
> user has finished inserting some text the next thing they will want to
> do is more likely to be concerning text located *after* what they've
> just inserted (and thus less likely that they will want to do things
> concerning the last character they've entered or ones prior to that).


I don't think that's true, the only time I run into this is when I want
to enclose something in a new function call:

int(something) => int(round(something))

I have a mapping for enclosing in brackets and then entering insert
mode, so when I remember to use that, I do brackets first and then add
the function call.

The issue here is that when going backwards is what you need, you don't
notice it, but when you want to go forward, you do notice. Do the
mapping to <esc>l and I think you'll find it's not always what you need,
either.  -ak

--
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
Loading...