iferr


Ⅰ. 插件描述

Generate "if err != nil {" block

Ⅱ. 基本信息

创建日期:  2018-02-04
使用用户:  1
Github星:  57
插件作者:  MURAOKA Taro

Ⅲ. 安装方法

使用Vundle管理器安装

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

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

使用NeoBundle管理器安装

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

使用VimPlug管理器安装

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

使用Pathogen管理器安装

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

Ⅳ. 文档说明

# Generate "if err != nil {" block

Generate if err != nil { block for current function.

Usage

Install and update by

$ go get -u github.com/koron/iferr

Run, it get if err != nil { block for the postion at 1234 bytes.

$ iferr -pos 1234 < main.go
if err != nil {
    return ""
}

Vim plugin

Copy vim/ftplugin/go/iferr.vim as ~/.vim/ftplugin/go/iferr.vim.

It defines :IfErr command for go filetype. It will insert if err != nil {
block at next line of the cursor.

Before:

package foo

import "io"

func Foo() (io.Reader, error) { // the cursor on this line.
}

Run :IfErr then you will get:

package foo

import "io"

func Foo() (io.Reader, error) {
    if err != nil {
        return nil, err
    }
} // new cursor is at here.

添加新评论