my vim golang programming environment

Tags golang vim docker

2021-02-14 23:35:19

If you are also suffered from vim emulation or facked vim such as ideavim or vscodevim. Today we will show you a new golang development environment under docker or use it out of the box. And easy to tweak by our public dockerfile and built image from docker hub public image. Here’s a list of features in the following article.


Autocomplete by language server without import package we need. While showing function parameters and documents.


We use onedark color theme as the basic vim color solution. Here we give two everyday operations examples as below.

  1. Rename variable
  2. Add tags to struct


The example below use ETCD as demo project show the following feature:

  1. tini for container init process
  2. auto complete
  3. go to definition
  4. FZF search file


Of course gopls (which is a golang toolchain we depend on) use over 40 seconds to scan so large project. But gopls also have a cache feature accelerate open project in the next time.

how to use it

pull the docker image by command:

docker pull lijianying10/golangdev:21Feb7-01

docker run by following command

docker run -it --rm -v $PWD/etcd:/root/etcd lijianying10/golangdev:21Feb7-01 /bin/bash

Attention: alter the dir mapping to your project path, and we highly recommend using gomod as the project manager.


ref link:

vim dot file

ref link:

shortcut keys (key maps)

start from LOC 79 of dot file.

nmap <M-p> :TagbarToggle<CR> " view tag bar
imap <M-p> <esc>:TagbarToggle<CR>i
nmap <M-u> :NERDTreeToggle<CR> " view file list
imap <M-u> <esc>:NERDTreeToggle<CR>
nmap <C-c> :q<CR> " exit 
nmap <M-o> :tabn<CR> " tab next
imap <M-o> <esc>:tabn<CR>
nmap <M-i> :tabp<CR> " tab previous
imap <M-i> <esc>:tabp<CR>
nmap <M-l> :w<CR>:GoMetaLinter<CR> " linter 
nmap <M-n> <Plug>(coc-definition) " go to definition
nmap <C-z> :undo<CR> " undo
nmap <M-y> :GoErrCheck<CR> " go error check
nmap <C-s> :w<CR> " save
imap <C-s> <esc>:w<CR>
imap <M-c> <esc>:pc<CR>
nmap <M-c> :pc<CR> " close preview window
nmap <leader>r :Ack<space> " search hole project document:
nmap <leader>t :FZF<CR> " zfz file search

example key mapping:

  1. M-p means Meta + p Option key for mac and alt key for windows keyboard
  2. C-s means Ctrl + s
  3. <leader>t means press \ and then press t

本人博客文章采用CC Attribution-NonCommercial协议: CC Attribution-NonCommercial 必须保留原作者署名,并且不允许用于商业用途,其他行为都是允许的。