Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] Need a little help with vim + sudo
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
blackst0ne
n00b
n00b


Joined: 14 Jul 2007
Posts: 6
Location: YS, Russia

PostPosted: Fri Apr 06, 2012 6:02 am    Post subject: [solved] Need a little help with vim + sudo Reply with quote

Hello all!

I'd like to configure my vim to save a file using sudo.
Searching Internet I found a solution:
Code:
command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!


It's working, but I'd like to use w! command, not W.

How do I get this work?

Thanks.


Last edited by blackst0ne on Sun Apr 08, 2012 8:15 am; edited 1 time in total
Back to top
View user's profile Send private message
86me
n00b
n00b


Joined: 20 Jul 2009
Posts: 20

PostPosted: Sun Apr 08, 2012 4:14 am    Post subject: Reply with quote

Quick answer: you can't.

Longer answer: the "!" (bang) is a modifier that forces a command in some cases, and toggles a command in others. I think "W" is a clear and sensible choice.

It's definitely handy in those situations when you've made a bunch of changes to a readonly file and don't want to lose/redo, but if you find yourself needing to use this command a lot, you might want to look into changing the permissions of the file, or adding yourself to a more privileged group.
Back to top
View user's profile Send private message
blackst0ne
n00b
n00b


Joined: 14 Jul 2007
Posts: 6
Location: YS, Russia

PostPosted: Sun Apr 08, 2012 8:15 am    Post subject: Reply with quote

Sorry, guys, I have already solved this problem.
The solution is:

Code:
command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!
:cnoreabbrev w! W
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum