remapping different keys to Escape in command mode doesn't work as expected

57 views
Skip to first unread message

Britton Kerin

unread,
Nov 10, 2008, 4:22:06 PM11/10/08
to v...@vim.org

I've been madly remapping vim keys to suit my crazy
notions of the most speedy and ergonomic possible
arrangements. I'm *extremely* impressed with the
graceful and detailed control vim gives you in
this department. I have one mapping that doesn't work
as expected though:

cnoremap js <Esc>

which if I understand correctly is supposed to make 'js'
do what Esc does when typed on the command line. But it
seems to do something slightly different:

:boguscommandjs

results in an error message:

E492: Not an editor command: boguscommand

while

:boguscommand<Esc>

appears to just silently abort the command line.


I don't think I have any other mappings that should interfere
here, but just in case I've attached my .vimrc. Here are all
the mapping commands I have in it:

" Fine point: we don't make these mappings in operator pending mode.
This
" the timeout on the ds map to delete upward with movement via s).
nnoremap s k
vnoremap s k
nnoremap ds s
vnoremap ds s
"nmap js <Nop>
" Including a trailing space in the "to" part of these mappings has an
onoremap js <Esc>
xnoremap js <Esc>
snoremap js <Esc>
inoremap js <Esc>
cnoremap js <Esc>
" This was the old mapping I used, maintained until new mapping is
learned.
inoremap jf <Esc>
noremap <Space> h
noremap , ;
:noremap ;w <C-w>w
noremap ;s :sh<CR>
":noremap ' `
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
"inoremap ( ()<Left>
"inoremap (<CR> (<CR>)<Esc>O
"inoremap (( (
"inoremap () ()
"inoremap [ []<Left>
"inoremap [<CR> [<CR>]<Esc>O
"inoremap [[ [
"inoremap [] []


Thanks in advance for any help,
Britton


vimrc

Tim Chase

unread,
Nov 10, 2008, 4:58:14 PM11/10/08
to vim...@googlegroups.com, v...@vim.org
> cnoremap js <Esc>
>
> which if I understand correctly is supposed to make 'js'
> do what Esc does when typed on the command line. But it
> seems to do something slightly different:
>
> :boguscommandjs
>
> results in an error message:
>
> E492: Not an editor command: boguscommand
>
> while
>
> :boguscommand<Esc>
>
> appears to just silently abort the command line.

As described at

:help c_<esc>

in macros (which I also understand from the evidence you've
presented, to mean "mappings and macros"), the command you've
entered thus far is run.

However, right below that help, you can see how to prevent it
from happening: use CTRL-C

:cnoremap js <c-c>

which seems to do what you're looking for.

-tim

Tony Mechelynck

unread,
Nov 11, 2008, 7:24:01 PM11/11/08
to vim...@googlegroups.com, v...@vim.org
On 10/11/08 22:22, Britton Kerin wrote:
> I've been madly remapping vim keys to suit my crazy
> notions of the most speedy and ergonomic possible
> arrangements. I'm *extremely* impressed with the
> graceful and detailed control vim gives you in
> this department. I have one mapping that doesn't work
> as expected though:
>
> cnoremap js<Esc>
>
> which if I understand correctly is supposed to make 'js'
> do what Esc does when typed on the command line. But it
> seems to do something slightly different:
>
> :boguscommandjs
>
> results in an error message:
>
> E492: Not an editor command: boguscommand
>
> while
>
> :boguscommand<Esc>
>
> appears to just silently abort the command line.

Well, even if it worked, you should be careful: what about

:e scriptname.js

? (I don't write javascript myself, except that user.js and prefs.js are
names for preference files used by Mozilla applications.)

Here you may have to hit the { key six times to create a {{{ fold-marker
(in a file using foldmethod=marker and the default markers)

> inoremap {} {}
> "inoremap ( ()<Left>
> "inoremap (<CR> (<CR>)<Esc>O
> "inoremap (( (
> "inoremap () ()
> "inoremap [ []<Left>
> "inoremap [<CR> [<CR>]<Esc>O
> "inoremap [[ [
> "inoremap [] []
>
>
> Thanks in advance for any help,
> Britton

Well, my help (or rather, my recommendation) is: learn how Vim behaves
natively, it's often more productive than trying to force it to behave
like Netscape, Emacs, gobbledywriter or anything.


Best regards,
Tony.
--
186,282 miles per second:

It isn't just a good idea, it's the law!

bke...@fastmail.fm

unread,
Nov 12, 2008, 8:42:18 PM11/12/08
to vim_use


On Nov 11, 3:24 pm, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
> On 10/11/08 22:22, Britton Kerin wrote:
>
>
>
> > I've been madly remapping vim keys to suit my crazy
> > notions of the most speedy and ergonomic possible
> > arrangements.  I'm *extremely* impressed with the
> > graceful and detailed control vim gives you in
> > this department.  I have one mapping that doesn't work
> > as expected though:
>
> >      cnoremap js<Esc>
>
> > which if I understand correctly is supposed to make 'js'
> > do what Esc does when typed on the command line.  But it
> > seems to do something slightly different:
>
> >      :boguscommandjs
>
> > results in an error message:
>
> >      E492: Not an editor command: boguscommand
>
> > while
>
> >      :boguscommand<Esc>
>
> > appears to just silently abort the command line.
>
> Well, even if it worked, you should be careful: what about
>
>         :e scriptname.js
>
> ? (I don't write javascript myself, except that user.js and prefs.js are
> names for preference files used by Mozilla applications.)

LOL I already hit the javascript issue. Otherwise for english I get:

my_system$ grep 'js' /usr/share/dict/american-english
Ijssel
Ijsselmeer
Ijsselmeer's

which doesn't seem like much of a problem, and for C code:

my_system$ cd dir_full_of_many_blobs_of_code
my_system$ find . -name "*.c" -exec grep 'js' \{\} \; | wc -l
320
my_system$ find . -name "*.c" -exec grep '' \{\} \; | wc -l
1686914

or about 0.019% of lines, making in pretty unpopular in identifiers
too. And lets face it, if you're working with the ghastly monstrosity
that is DOM/JavaScript, you're going to be pretty darn annoyed
anyway :)

Why vim (O'Reilly et. al.) chooses to advertise Esc everywhere
mystifies me.
At least given where Esc falls on modern keyboards. Its about like
emacs
having the backspace key launch you into help by default. Takes an
editor
for which ergonomics is a key advantage and make it look... strangely
clunky.

Britton

Tony Mechelynck

unread,
Nov 12, 2008, 9:06:56 PM11/12/08
to vim...@googlegroups.com
On 13/11/08 02:42, bke...@fastmail.fm wrote:
[...]

> Why vim (O'Reilly et. al.) chooses to advertise Esc everywhere
> mystifies me.
> At least given where Esc falls on modern keyboards. Its about like
> emacs
> having the backspace key launch you into help by default. Takes an
> editor
> for which ergonomics is a key advantage and make it look... strangely
> clunky.
>
> Britton
[...]

If you don't like reaching out to the top-left Esc key, use Ctrl-[ (to
Vim it's the same as Esc). You can reach them with two fingers of your
right hand with very little movement away grom the home position -- if
you got [ right of the P on a QWERTY layout, I think you can reach
Ctrl-[ quite easily with, hm... let's see... I'd say the little finger
on (right) Ctrl and the middle finger on [. Or you can use both hands
and the left Ctrl instead.

Best regards,
Tony.
--
A consultant is a person who borrows your watch, tells you what time it
is, pockets the watch, and sends you a bill for it.

Reply all
Reply to author
Forward
0 new messages