自分の開発環境を準備するときにDockerfileやAnsibleの処理無いでVimのプラグインインストールを行いたい場合の方法です。
例を書くのが一番早いので自分の場合の最低限の開発環境として以下が導入されたVIMを使える環境を構築してみます。
- scrooloose/nerdtree
- fatih/vim-go
ポイント
ポイントはVIMのコマンドからPlugInstallを打つところを、ターミナルのコマンドラインからインストールを実行することです。
# vim vim -c PlugInstall -c q -c q # neovim nvim -c PlugInstall -c q -c q # or nvim +PlugInstall +q +q
実際Dockerfileの例(Vim)
Dockerfile
FROM ubuntu:18.04 RUN apt-get update && apt-get install -y curl git golang RUN apt-get install -y vim RUN go get -u github.com/klauspost/asmfmt/cmd/asmfmt && \ go get -u github.com/kisielk/errcheck && \ go get -u github.com/davidrjenni/reftools/cmd/fillstruct && \ go get -u github.com/nsf/gocode && \ go get -u github.com/rogpeppe/godef && \ go get -u github.com/zmb3/gogetdoc && \ go get -u golang.org/x/tools/cmd/goimports && \ go get -u github.com/golang/lint/golint && \ go get -u github.com/alecthomas/gometalinter && \ go get -u github.com/fatih/gomodifytags && \ go get -u golang.org/x/tools/cmd/gorename && \ go get -u github.com/jstemmer/gotags && \ go get -u golang.org/x/tools/cmd/guru && \ go get -u github.com/josharian/impl && \ go get -u github.com/dominikh/go-tools/cmd/keyify && \ go get -u github.com/fatih/motion RUN curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim COPY ./vimrc /root/.vimrc RUN vim -c PlugInstall -c q -c q RUN vim -c GoInstallBinaries -c q
vimrc
call plug#begin('~/.vim/plugged') Plug 'fatih/vim-go' Plug 'scrooloose/nerdtree' call plug#end() nnoremap <silent><C-n> :NERDTreeToggle<CR>
実際Dockerfileの例(neovim)
FROM ubuntu:18.04 RUN apt-get update && apt-get install -y curl git golang RUN apt-get install -y neovim RUN go get -u github.com/klauspost/asmfmt/cmd/asmfmt && \ go get -u github.com/kisielk/errcheck && \ go get -u github.com/davidrjenni/reftools/cmd/fillstruct && \ go get -u github.com/nsf/gocode && \ go get -u github.com/rogpeppe/godef && \ go get -u github.com/zmb3/gogetdoc && \ go get -u golang.org/x/tools/cmd/goimports && \ go get -u github.com/golang/lint/golint && \ go get -u github.com/alecthomas/gometalinter && \ go get -u github.com/fatih/gomodifytags && \ go get -u golang.org/x/tools/cmd/gorename && \ go get -u github.com/jstemmer/gotags && \ go get -u golang.org/x/tools/cmd/guru && \ go get -u github.com/josharian/impl && \ go get -u github.com/dominikh/go-tools/cmd/keyify && \ go get -u github.com/fatih/motion RUN curl -fLo /root/.local/share/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim RUN mkdir -p /root/.config/nvim COPY ./init.vim /root/.config/nvim/init.vim RUN nvim +PlugInstall +q +q RUN nvim +GoInstallBinaries +q
init.vim
call plug#begin('~/.local/share/nvim/plugged') Plug 'fatih/vim-go' Plug 'scrooloose/nerdtree' call plug#end() nnoremap <silent><C-n> :NERDTreeToggle<CR>
補足
Dockerfile内で本来ならGoInstallBinaries
でインストールされるGolangのバイナリをインストールしています。
これらを全てGoInstallBinaries
でインストールしようとすると何かの制限に引っかかるのかVim: Error reading input, exiting...
と出てしまうので必要なものは事前にgo get
でインストールしています。
インストールするべきパッケージはこのあたりでき確認できます。
vim-go/go.vim at v1.16 · fatih/vim-go · GitHub
知らないうちにアップデートされていても最後のRUN vim -c GoInstallBinaries -c q
で拾ってくれます。