suda.vim


Ⅰ. 插件描述

An alternative sudo.vim for Vim and Neovim, limited support sudo in Windows

Ⅱ. 基本信息

创建日期:  2017-11-24
使用用户:  63
Github星:  144
插件作者:  Alisue

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'lambdalisue/suda-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'lambdalisue/suda-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'lambdalisue/suda-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/lambdalisue/suda.vim

Ⅳ. 文档说明

suda.vim

MIT License
Doc

suda is a plugin to read or write files with sudo command.

This plugin was built while :w !sudo tee % > /dev/null trick does not work on [neovim][].

https://github.com/neovim/neovim/issues/1716

This plugin is strongly inspired by [sudo.vim][] but the interfaces was aggressively modified for modern Vim script.

Usage

Use suda:// prefix in read, edit, write, or saveas commands.

" Open a current file with sudo
:e suda://%

" Save a current file with sudo
:w suda://%

" Edit /etc/sudoers
:e suda:///etc/sudoers

" Read /etc/sudoers (insert content under the cursor)
:r suda:///etc/sudoers

" Read /etc/sudoers at the end
:$r suda:///etc/sudoers

" Write contents to /etc/profile
:w suda:///etc/profile

" Save contents to /etc/profile
:saveas suda:///etc/profile

You can change the protocol prefix with g:suda#prefix.

let g:suda#prefix = 'suda://'
" multiple protocols can be defined too
let g:suda#prefix = ['suda://', 'sudo://', '_://']

Smart edit

When let g:suda_smart_edit = 1 is written in your vimrc, suda automatically switch a buffer name when the target file is not readable or writable.

In short,

$ vim /etc/hosts

or

:e /etc/shadow

Will open suda:///etc/hosts or suda:///etc/shadow instead of /etc/hosts or /etc/shadow because that files are not writable or not readable.

Windows

Install mattn/sudo to enable this plugin in Windows.
Make sure that the following shows 1.

: echo executable('sudo')

添加新评论