| View previous topic :: View next topic |
| Author |
Message |
blackst0ne n00b


Joined: 14 Jul 2007 Posts: 6 Location: YS, Russia
|
Posted: Fri Apr 06, 2012 6:02 am Post subject: [solved] Need a little help with vim + sudo |
|
|
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 |
|
 |
86me n00b


Joined: 20 Jul 2009 Posts: 20
|
Posted: Sun Apr 08, 2012 4:14 am Post subject: |
|
|
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 |
|
 |
blackst0ne n00b


Joined: 14 Jul 2007 Posts: 6 Location: YS, Russia
|
Posted: Sun Apr 08, 2012 8:15 am Post subject: |
|
|
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 |
|
 |
|