I use MacVim.

I write-to-file frequently using ":w".

I often have some lines selected visually when I do this, and get an annoying "Write partial file" dialogue (which more annoyingly doesn't tab out to "No").

Writing a partial file is something I do very seldom.

What are your recommendations to make the default skip "Write partial file" and just write the entire file?

Of course I'd like to develop a new mapping for the default functionality (in case I do need it).

I tried:

command w <esc>w

However, I could not save that command because "User defined commands must start with capital letters".

Next, I tried this, but get "Not an editor command ^[w"

command! WriteIgnoreVisual <esc>w
cabbrev w <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'WriteIgnoreVisual' : 'w')<CR>

You were pretty close. It's easier to use an <expr> mapping. You just have to check that the cmdline equals the string '<,'>w, and if so, delete the existing command line and replace it with a plain :w.

cabbrev <expr> w getcmdtype()==':' && getcmdline() == "'<,'>w" ? '<c-u>w' : 'w'
  • Nice, thank you so much that worked sweetly. I don't grok what the "c-u" does though? I thought I had to do <esc>, why "c-u" is preferred? Jul 12 '18 at 19:03
  • <c-u> deletes the existing cmdline. you need to stay in cmdline to issue :w, but <esc> would drop you out into normal mode instead.
    – Mass
    Jul 12 '18 at 19:10
  • Ah, now I get it. I was leaving command mode with <esc>. You the man, Mass! Jul 12 '18 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.