mapping :W to :w...

18 views
Skip to first unread message

tu...@posteo.de

unread,
Feb 23, 2021, 11:06:34 PM2/23/21
to vim...@googlegroups.com
Hi,

if my PC is heavily compiling things and I am editing and saving
things repeatedly if often hit :W instead of :w (that is, I am
still pressing SHIFT when hitting w.

So I tried to map :W to :w...but it does not work for me.

I tried

[n]map W w
and
[n]map :W :w

.

Is there any way to map the accidentally hit :W
command to :w somehow?

Cheers!
mcc

Salman Halim

unread,
Feb 23, 2021, 11:11:41 PM2/23/21
to Vim Users
I actually prefer to never hit shift, so map ; to : instead. 

You could simply define a command called W to do what you want:

command! W w

--

Salman

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210224040623.p4fmrhjxbiyf5e5n%40solfire.

tu...@posteo.de

unread,
Feb 23, 2021, 11:33:49 PM2/23/21
to vim...@googlegroups.com
Hi Salman,

oh! :)

The first is genious and while reading the second one I had
the distinctive feeling of flat-hand-against-my-fronthead... ;)
Of course!

Thank you very much! That helps me a lot!

Cheers!
mcc
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEcDbZWngA-58DHuvdG_fesuz5%3DCxUh_LBmOqFTzx7YTTA%40mail.gmail.com.

Tony Mechelynck

unread,
Feb 24, 2021, 2:19:39 AM2/24/21
to vim_use
Like Salman said, you could define a user-comand W executing just w ;
but the reason your nmap didn't work is that by the time you'tr typing
the W, you aren't in Normal mode anymore, but in Command-line mode;
OTOH you don't want any W in the middle of a command's parameters to
always lowercased; so another possibility is a command-mode
abbreviation, as follows:

:cabbrev <expr> W ((getcmdtype() == ':' && getcmdpos() <= 4)? 'w' : 'W')

Testing getcmdtype() avoids lowercasing the W in a search command, and
testing getcmdpos() allows doing it only near the left margin. A
user-command is more elegant however; but in order to make it behave
like the w command you may want to define that :W command with the
appropriate parameters, as follows (untested):

:command -nargs=* -complete=file -range=% -bang -bar W
<line1>,<line2>w<bang> <args>

which, after all, makes it somewhat less elegant; so you may choose a
command or an abbrev to suit youor taste.

Best regards,
Tony.

Tony Mechelynck

unread,
Feb 24, 2021, 2:33:37 AM2/24/21
to vim_use
P.S. My solution to a similar problem was a little different:

map <F3> :wa|wv<CR>
map! <F3> <C-O>:wa|wv<CR>

Best regards,
Tony.

Salman Halim

unread,
Feb 24, 2021, 2:54:17 AM2/24/21
to Vim Users
I use <f2> in much the same way and just call :update. I also save automatically when the Vim window loses focus. 

--

Salman

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

rwmit...@gmail.com

unread,
Feb 24, 2021, 6:17:43 AM2/24/21
to vim_use
"I use <f2> in much the same way and just call :update. I also save automatically when the Vim window loses focus."

Tell me more about this.

aro...@vex.net

unread,
Feb 24, 2021, 8:59:37 AM2/24/21
to vim...@googlegroups.com

> the distinctive feeling of flat-hand-against-my-fronthead... ;)
>

Aka (Also known as:) a face-palm. :-)*

tu...@posteo.de

unread,
Feb 24, 2021, 9:11:23 AM2/24/21
to vim...@googlegroups.com
On 02/24 08:59, aro...@Vex.Net wrote:
>
> > the distinctive feeling of flat-hand-against-my-fronthead... ;)
> >
>
> Aka (Also known as:) a face-palm. :-)*

Ok :) another face-palm (this time correctly spoke...I am no native
speaker...sorry...

But...how can I ensure, that I am talking about my face and
someone else face...?


>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/03b0da16fc3d8e12971a9d203ee0b12d.squirrel%40webmail.vybenetworks.com.
>

Lifepillar

unread,
Feb 24, 2021, 9:20:09 AM2/24/21
to vim...@googlegroups.com
>>On 02/23 11:11, Salman Halim wrote:
>> I actually prefer to never hit shift, so map ; to : instead.
>>
>On 2021-02-24, tu...@posteo.de <tu...@posteo.de> wrote:
> Hi Salman,
>
> oh! :)
>
> The first is genious

Keep in mind that ; is a useful mapping in Vim. Sure, you can remap it
to :, but, in my experience, in the long term it is better not to change
Vim's default mappings (this is a matter of personal taste, of course),
except when their functionality is replicated by other mappings (as in
the next paragraph).


Reply all
Reply to author
Forward
0 new messages