1

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> 

1 Answer 1

4

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' 
3
  • 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? Commented Jul 12, 2018 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. Commented Jul 12, 2018 at 19:10
  • Ah, now I get it. I was leaving command mode with <esc>. You the man, Mass! Commented Jul 12, 2018 at 19:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.