9

in VIM sometimes when saving, I accidentally hit capital W instead of its lowercase brother. I am prompted for my system password, so I assume it is running a sudo command of some sort, but do you know what?

Thank you!

4
  • 1
    in my vim it gives me "E492: Not an editor command: W" if i try to ":W".
    – akira
    May 26, 2010 at 16:10
  • Ahh.. thank you. I got the vimrc from a friend and it was: w !sudo tee % > /dev/null
    – tesmar
    Mar 1, 2017 at 19:50
  • 1
    @tesmar That is sudo write, for when you open a vim instance using a non-elevated user but end up editing a file that you needed sudo vim for; tell your friend that chrisbra/SudoEdit.vim is a better version. That also allows SudoRead. You can still map :W to :SudoWrite for consistency. Oct 4, 2020 at 16:07
  • 1
    Also, in case anyone else stumbles on this, the fzf fuzzy finder plugin defines :Windows which may pop up for :W. Oct 4, 2020 at 16:08

5 Answers 5

17

As others have said, :W isn't defined in vanilla vim (7.0 here), so it sounds like some plugin you've installed has added it.

:command W will tell you what it does.

6

I guess you have a common mapping for :W in your .vimrc to save the file as typing :w does. Often people press too long the shift key for the colon and make the typo but actually wanting to type :w. You've possibly got this mapping by copy and paste of snippets into your vimrc or by using a pre-configured vim setup such as spf13-vim distribution.

.vimrc:

command! W  write

However, as pointed out by Sam Stokes checking the meaning of commands via

:command W

and for keycombos:

:verbose map < C-j>

is a general approach to find out what a command or keycombo does.

5

You can test this line

{Cursor}It's the test
  • {Cursor}: Cursor position in normal mode
  • w: will move word which separated by " ,./?"
    • You will end up at 's …
  • W: will move word which separated by " " only
    • You will end up at the …
0

That's strange. The normal mapping of "W" advances by a WORD, where WORD is defined by a sequence of non-blank characters.

2
  • 3
    @bentsai: OP is not in control-mode but in ex-mode, as in "instead of :w he uses :W"
    – akira
    May 26, 2010 at 15:59
  • @akira that makes more sense.
    – bentsai
    May 26, 2010 at 16:00
0

:W doesn't do anything in my copy of VIM (6.4), for what that's worth. What does :help :W tell you? (For me, it just takes me to the help for :w, which wouldn't be, um, help-ful for you. :-) )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .