all I want to do is save a file!

18 views
Skip to first unread message

urbanpcguru

unread,
Jun 8, 2011, 2:30:58 PM6/8/11
to vim_dev
I can open vim with sudo vim /etc/hosts for example.. But how do I
save and close it? I can't seem to find the answer to this
anywhere!? Why would one easy question be so freaking hard to
find??!!!

How do I save a file? <--- Is this too easy a question to be
answered? I have been driven mad for 3 hours trying to find this one
simple thing!!
please

Gary Johnson

unread,
Jun 8, 2011, 5:48:42 PM6/8/11
to vim_dev

The command is :write, abbreviated :w. You can read about it and
its variations here:

:help save-file

To quit, or to write and quit, see the commands here:

:help write-quit

Regards,
Gary

tux.

unread,
Jun 8, 2011, 5:50:53 PM6/8/11
to vim...@googlegroups.com
urbanpcguru wrote:
> I can open vim with sudo vim /etc/hosts for example.. But how do I
> save and close it?

First, this is probably the wrong place to ask that.
Second, I advise you to go through the vimtutor first...

:wq

Tony Mechelynck

unread,
Jun 8, 2011, 5:53:24 PM6/8/11
to vim...@googlegroups.com, urbanpcguru

:help write-quit


HTH,
Tony.
--
"There was an interesting development in the CBS-Westmoreland trial:
both sides agreed that after the trial, Andy Rooney would be allowed to
talk to the jury for three minutes about little things that annoyed him
during the trial."
-- David Letterman

Christian Brabandt

unread,
Jun 9, 2011, 3:07:26 AM6/9/11
to vim_dev
Hi urbanpcguru!

On Mi, 08 Jun 2011, urbanpcguru wrote:

> I can open vim with sudo vim /etc/hosts for example.. But how do I
> save and close it? I can't seem to find the answer to this
> anywhere!? Why would one easy question be so freaking hard to
> find??!!!

Because you are using the one and only true editor. We don't want, that
anybody simply can use our editor. After all, we don't provide
documentation or man pages, have no wiki don't distribute plugins and of
course won't answer questions. Drat, how did you even find our mailing
list?

> How do I save a file? <--- Is this too easy a question to be
> answered? I have been driven mad for 3 hours trying to find this one
> simple thing!!

Yes, this is too easy. Remember, you are using an editor, not a saver.
We don't save our files, we edit them! But here is a trick, you can use
to convince vim to save your file:

:w !tee %

to save and quit, we use:

:exe 'w !tee %' | exe '!kill -9' getpid()

I've heard, some people have mapped the former to :w and the latter to
:wq but that must be rumours, after all this is the true editor. There
is no easier way to do what you want than using it's builtin functions.

SCNR,
Christian

Adrien "Axioplase" Piérard

unread,
Jun 9, 2011, 4:25:12 AM6/9/11
to vim...@googlegroups.com
2011/6/9 urbanpcguru <urban...@gmail.com>:

> I can open vim with sudo vim /etc/hosts  for example..  But how do I
> save and close it?

The same way you close it when you run it without sudo!

>  I can't seem to find the answer to this
> anywhere!?

Most people here did find the answer somewhere.

> Why would one easy question be so freaking hard to
> find??!!!

What if that question was, in fact, "freaking easy"?

> How do I save a file?   <--- Is this too easy a question to be
> answered?

I don't know. What about asking politely before asking angrily?

>  I have been driven mad for 3 hours trying to find this one
> simple thing!!
> please

http://lmgtfy.com/?q=vim+save+and+quit

My pleasure.

P!

--
Français, English, 日本語, 한국어

Tony Mechelynck

unread,
Jun 9, 2011, 2:57:56 PM6/9/11
to vim_dev
On 09/06/11 09:07, Christian Brabandt wrote:
[...]

> to save and quit, we use:
>
> :exe 'w !tee %' | exe '!kill -9' getpid()
[...]

Wow! Christian, you're a genius! It might even work. But maybe not on
Windows (or have the "tee and "kill" commands been added since I left?).

Best regards,
Tony.
--
Man is the only animal that blushes -- or needs to.
-- Mark Twain

Christian Brabandt

unread,
Jun 9, 2011, 3:26:37 PM6/9/11
to vim_dev
Hi Tony!

On Do, 09 Jun 2011, Tony Mechelynck wrote:

> On 09/06/11 09:07, Christian Brabandt wrote:
> [...]
> >to save and quit, we use:
> >
> >:exe 'w !tee %' | exe '!kill -9' getpid()
> [...]
>
> Wow! Christian, you're a genius! It might even work. But maybe not
> on Windows (or have the "tee and "kill" commands been added since I
> left?).

Yeah, I haven't mastered the one and only editor on Windows yet.

regards,
Christian

Xavier Wang

unread,
Jun 10, 2011, 9:25:33 AM6/10/11
to vim...@googlegroups.com


在 2011-6-10 上午2:57,"Tony Mechelynck" <antoine.m...@gmail.com>写道:
>
> On 09/06/11 09:07, Christian Brabandt wrote:
> [...]
>
>> to save and quit, we use:
>>
>> :exe 'w !tee %' | exe '!kill -9' getpid()
>
> [...]
>
> Wow! Christian, you're a genius! It might even work. But maybe not on Windows (or have the "tee and "kill" commands been added since I left?).
>

And windows doesn't have sudo yet  :)

> Best regards,
> Tony.
> --
> Man is the only animal that blushes -- or needs to.
>                -- Mark Twain
>
>

> --
> You received this message from the "vim_dev" 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

Reply all
Reply to author
Forward
0 new messages