> ## Content Index
> Fetch the complete content index at: https://blog.hacking.pub/llms.txt
> Use this file to discover other available public pages before exploring further.

# vim-go debug
- URL: https://blog.hacking.pub/2018/07/16/vim-go-debug/
- Published: 2018-07-16T18:35:40.000Z
- Updated: 2018-09-04T12:57:02.000Z
- Author: chainhelen
- Tags: vim, go, go语言, golang, debug

**2018.09.04**

```
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'Shougo/echodoc.vim'
Plugin 'fatih/vim-go', {'do': ':GoUpdateBinaries'}
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'mklabs/vim-json'
"Plugin 'majutsushi/tagbar'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'leafgarland/typescript-vim'
Plugin 'crooloose/nerdtree'
Plugin 'easymotion/vim-easymotion'
Plugin 'sickill/vim-monokai'
Plugin 'Valloric/YouCompleteMe', {'do': './install.sh --clang-completer --go-completer --js-completer --rust-completer'}
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }

call vundle#end()           
"###### simple 
set nu
set nopaste
filetype plugin indent on
syntax enable
set sw=4
set ts=4
set hlsearch
let mapleader=","

"##### tarbar gotags
"nmap <C-f> :TagbarToggle<CR>
"let ctagsbin = 'gotags'
"let GOPATH = '/root/workspace/go'
"let g:tagbar_type_go = {
"	\ 'ctagstype' : 'go',
"	\ 'kinds'     : [
"		\ 'p:package',
"		\ 'i:imports:1',
"		\ 'c:constants',
"		\ 'v:variables',
"		\ 't:types',
"		\ 'n:interfaces',
"		\ 'w:fields',
"		\ 'e:embedded',
"		\ 'm:methods',
"		\ 'r:constructor',
"		\ 'f:functions'
"	\ ],
"	\ 'sro' : '.',
"	\ 'kind2scope' : {
"		\ 't' : 'ctype',
"		\ 'n' : 'ntype'
"	\ },
"	\ 'scope2kind' : {
"		\ 'ctype' : 't',
"		\ 'ntype' : 'n'
"	\ },
"	\ 'ctagsbin'  : 'gotags',
"	\ 'ctagsargs' : '-sort -silent'
"	\ }

"######vim-monokai
syntax enable
colorscheme monokai

"###### apiline_powerline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='luna'
set t_Co=256
nnoremap <tab> :bn <cr>
nnoremap <S-tab> :bp <cr>

"##### LeaderF
let g:Lf_ShortcutF = '<C-P>'
noremap <c-f> :LeaderfFunction<cr>
noremap <leader><c-f> :LeaderfFunctionAll<cr>
noremap <C-n> :LeaderfMru<cr>
noremap <C-l> :LeaderfLine<cr>
noremap <leader><C-l> :LeaderfLineAll<cr>

"##### YouCompleteme
let g:ycm_add_preview_to_completeopt = 0
set completeopt=menu,menuone
let g:ycm_filetype_whitelist = { 
			\ "go": 1, 
			\ "js": 1, 
			\ "c": 1,
		   	\ "cpp": 1
			\}
nnoremap <leader>gc :YcmCompleter GoToDeclaration<CR> 
nnoremap <leader>gd :YcmCompleter GoToDefinition<CR> 
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_goto_buffer_command = 'horizontal-split'

"let g:ycm_rust_src_path = '/usr/local/rust/src'
autocmd BufNewFile,BufRead *rs set filetype=rust
let g:ycm_rust_src_path = '/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src'

"#### nerdtree
map <C-e> :NERDTreeToggle<CR>

"#### echodoc
set noshowmode

"#### vim-gutentags
let g:gutentags_project_root = ['.gosrcroot']
let g:gutentags_ctags_tagfile = '.tags'

let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
if !isdirectory(s:vim_tags)
    silent! call mkdir(s:vim_tags, 'p')
endif
set tags=./.tags;,.tags

"##### vim-go
"let g:go_metalinter_autosave = 1
"let g:go_metalinter_autosave_enabled = ['vet', 'golint', 'errcheck']
"let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
let g:go_fmt_autosave = 1
let g:go_fmt_command = "gofmt"
let g:go_fmt_options = {
     \ 'gofmt': '-s',
     \ 'goimports': '-local mycompany.com',
     \ }

"##### f5-f11
function SetEnv(envs) 
	let envKeys = keys(a:envs)
	for envKey in envKeys
		exec 'let $' . envKey . '="' . a:envs[envKey] . '"'
	endfor
endfunction

function Run(modelname) 
	let l:debugConfigFile = expand('%:h') . '/.ch.json'
	let l:debugConfigList = readfile(l:debugConfigFile)
	let l:debugConfigStr = join(l:debugConfigList, '')
	let l:debugConfigJson = JSON#parse(l:debugConfigStr)
	let l:debugCs = l:debugConfigJson['configurations']
	for singleCs in l:debugCs 
		if 'debug' == a:modelname && 'debug' == singleCs['name']
			call SetEnv(singleCs['env'])
			call ClearMapKeysInNotDebugModelForGo()
			exec 'GoDebugStart ' . singleCs['program'] . ' ' . singleCs['argv']
			return
		elseif 'runexe' == a:modelname && 'runexe' == singleCs['name']
			call SetEnv(singleCs['env'])
			call ClearMapKeysInNotDebugModelForGo()
			exec 'GoRun ' . singleCs['program'] . ' ' . singleCs['argv']
			return
		endif
	endfor
	echoerr 'Sorry can\"t not found the valid ' . a:modelname . ' model configurations'
endfunction

function! g:ClearMapKeysInNotDebugModelForGo () 
	augroup vim-go-debug-mp
		autocmd!
	augroup END
	augroup! vim-go-debug-mp
endfunction

function! g:MapKeysInNotDebugModelForGo () 
	augroup vim-go-debug-mp
		autocmd!
		autocmd FileType go nmap <buffer> <F8>  <Plug>(go-debug-stop)
		autocmd FileType go nmap <buffer> <F7> :call Run("debug") <cr>
		autocmd FileType go nmap <buffer> <F5> :call Run("runexe") <cr>
	augroup END
	doautocmd vim-go-debug-mp FileType go
endfunction

call MapKeysInNotDebugModelForGo()

let g:go_debug_windows = {
      \ 'stack': 'leftabove 30vnew',
      \ 'out':   'botright 10new',
      \ 'vars':  'leftabove 30vnew',
\ }
" <F5>  (go-debug-continue)
" <F6>  (go-debug-print)
" <F7>  (go-debug-start)
" <F8>  (go-debug-stop)
" <F9>  (go-debug-breakpoint)
" <F10> (go-debug-next)
" <F11> (go-debug-step)

" for js
autocmd BufNewFile,BufRead *.html,*.htm,*.css,*.js set noexpandtab tabstop=2 shiftwidth=2 

```

**2018.07.19**

```
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'Shougo/echodoc.vim'
Plugin 'fatih/vim-go', {'do': ':GoUpdateBinaries'}
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'mklabs/vim-json'
Plugin 'majutsushi/tagbar'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'crooloose/nerdtree'
Plugin 'easymotion/vim-easymotion'
Plugin 'sickill/vim-monokai'
Plugin 'Valloric/YouCompleteMe', {'do': './install.sh --clang-completer --go-completer --js-completer --rust-completer'}
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }

call vundle#end()           
"###### simple 
set nu
set nopaste
filetype plugin indent on
syntax enable
set sw=4
set ts=4
let mapleader=","

"##### tarbar gotags
nmap <C-f> :TagbarToggle<CR>
let ctagsbin = 'gotags'
let GOPATH = '/root/workspace/go'
let g:tagbar_type_go = {
        \ 'ctagstype' : 'go',
        \ 'kinds'     : [
                \ 'p:package',
                \ 'i:imports:1',
                \ 'c:constants',
                \ 'v:variables',
                \ 't:types',
                \ 'n:interfaces',
                \ 'w:fields',
                \ 'e:embedded',
                \ 'm:methods',
                \ 'r:constructor',
                \ 'f:functions'
        \ ],
        \ 'sro' : '.',
        \ 'kind2scope' : {
                \ 't' : 'ctype',
                \ 'n' : 'ntype'
        \ },
        \ 'scope2kind' : {
                \ 'ctype' : 't',
                \ 'ntype' : 'n'
        \ },
        \ 'ctagsbin'  : 'gotags',
        \ 'ctagsargs' : '-sort -silent'
        \ }

"######vim-monokai
syntax enable
colorscheme monokai

"###### apiline_powerline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='luna'
set t_Co=256

"##### LeaderF
let g:Lf_ShortcutF = '<C-P>'
noremap <F2> :LeaderfFunction!<cr>
noremap <c-n> :LeaderfMru<cr>

"##### YouCompleteme
let g:ycm_add_preview_to_completeopt = 0
set completeopt=menu,menuone
let g:ycm_filetype_whitelist = { 
                        \ "go": 1, 
                        \ "js": 1, 
                        \ "c": 1,
                        \ "cpp": 1
                        \}
nnoremap <leader>gc :YcmCompleter GoToDeclaration<CR> 
nnoremap <leader>gd :YcmCompleter GoToDefinition<CR> 
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_goto_buffer_command = 'horizontal-split'

"#### nerdtree
map <C-e> :NERDTreeToggle<CR>

"#### echodoc
set noshowmode

"#### vim-gutentags
let g:gutentags_project_root = ['.gosrcroot']
let g:gutentags_ctags_tagfile = '.tags'

let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
if !isdirectory(s:vim_tags)
    silent! call mkdir(s:vim_tags, 'p')
endif
set tags=./.tags;,.tags

"##### vim-go
"let g:go_metalinter_autosave = 1
"let g:go_metalinter_autosave_enabled = ['vet', 'golint', 'errcheck']
"let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
let g:go_fmt_autosave = 1
let g:go_fmt_command = "gofmt"
let g:go_fmt_options = {
     \ 'gofmt': '-s',
     \ 'goimports': '-local mycompany.com',
     \ }

"##### f2-f10
nnoremap <F2> :call asyncrun#quickfix_toggle(6)<cr>
function SetEnv(envs) 
        let envKeys = keys(a:envs)
        for envKey in envKeys
                exec 'let $' . envKey . '="' . a:envs[envKey] . '"'
        endfor
endfunction

function Run(modelname) 
        let l:debugConfigFile = expand('%:h') . '/.ch.json'
        let l:debugConfigList = readfile(l:debugConfigFile)
        let l:debugConfigStr = join(l:debugConfigList, '')
        let l:debugConfigJson = JSON#parse(l:debugConfigStr)
        let l:debugCs = l:debugConfigJson['configurations']
        for singleCs in l:debugCs 
                if 'debug' == a:modelname && 'debug' == singleCs['name']
                        call SetEnv(singleCs['env'])
                        call ClearMapKeysInNotDebugModelForGo()
                        exec 'GoDebugStart ' . singleCs['program'] . ' ' . singleCs['argv']
                        return
                elseif 'runexe' == a:modelname && 'runexe' == singleCs['name']
                        call SetEnv(singleCs['env'])
                        call ClearMapKeysInNotDebugModelForGo()
                        exec 'GoRun ' . singleCs['program'] . ' ' . singleCs['argv']
                        return
                endif
        endfor
        echoerr 'Sorry can\"t not found the valid ' . a:modelname . ' model configurations'
endfunction

function! g:ClearMapKeysInNotDebugModelForGo () 
        augroup vim-go-debug-mp
                autocmd!
        augroup END
        augroup! vim-go-debug-mp
endfunction

function! g:MapKeysInNotDebugModelForGo () 
        augroup vim-go-debug-mp
                autocmd!
                autocmd FileType go nmap <buffer> <F8>  <Plug>(go-debug-stop)
                autocmd FileType go nmap <buffer> <F7> :call Run("debug") <cr>
                autocmd FileType go nmap <buffer> <F5> :call Run("runexe") <cr>
        augroup END
        doautocmd vim-go-debug-mp FileType go
endfunction

call MapKeysInNotDebugModelForGo()

let g:go_debug_windows = {
      \ 'stack': 'leftabove 30vnew',
      \ 'out':   'botright 10new',
      \ 'vars':  'leftabove 30vnew',
\ }
" <F5>  (go-debug-continue)
" <F6>  (go-debug-print)
" <F7>  (go-debug-start)
" <F8>  (go-debug-stop)
" <F9>  (go-debug-breakpoint)
" <F10> (go-debug-next)
" <F11> (go-debug-step)

```

---

**2018.07.17**  
为了让 **F5** 在非debug模式下，作为`GoRun`使用，修改.vimrc如下

```
"##### f2-f10
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'Shougo/echodoc.vim'
Plugin 'fatih/vim-go', {'do': ':GoUpdateBinaries'}
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'mklabs/vim-json'
Plugin 'majutsushi/tagbar'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'crooloose/nerdtree'
Plugin 'easymotion/vim-easymotion'
Plugin 'sickill/vim-monokai'
Plugin 'Valloric/YouCompleteMe', {'do': './install.sh --clang-completer --go-completer --js-completer --rust-completer'}
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }

call vundle#end()           
"###### simple 
set nu
set nopaste
filetype plugin indent on
syntax enable
set sw=4
set ts=4

"##### tarbar gotags
nmap <C-f> :TagbarToggle<CR>
let ctagsbin = 'gotags'
let GOPATH = '/root/workspace/go'
let g:tagbar_type_go = {
        \ 'ctagstype' : 'go',
        \ 'kinds'     : [
                \ 'p:package',
                \ 'i:imports:1',
                \ 'c:constants',
                \ 'v:variables',
                \ 't:types',
                \ 'n:interfaces',
                \ 'w:fields',
                \ 'e:embedded',
                \ 'm:methods',
                \ 'r:constructor',
                \ 'f:functions'
        \ ],
        \ 'sro' : '.',
        \ 'kind2scope' : {
                \ 't' : 'ctype',
                \ 'n' : 'ntype'
        \ },
        \ 'scope2kind' : {
                \ 'ctype' : 't',
                \ 'ntype' : 'n'
        \ },
        \ 'ctagsbin'  : 'gotags',
        \ 'ctagsargs' : '-sort -silent'
        \ }

"######vim-monokai
syntax enable
colorscheme monokai

"###### apiline_powerline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='luna'
set t_Co=256

"##### LeaderF
let g:Lf_ShortcutF = '<C-P>'
noremap <F2> :LeaderfFunction!<cr>
noremap <c-n> :LeaderfMru<cr>

"##### YouCompleteme
let g:ycm_add_preview_to_completeopt = 0
set completeopt=menu,menuone
let g:ycm_filetype_whitelist = { 
                        \ "go": 1, 
                        \ "js": 1, 
                        \ "c": 1,
                        \ "cpp": 1
                        \}

"#### nerdtree
map <C-e> :NERDTreeToggle<CR>

"#### echodoc
set noshowmode

"#### vim-gutentags
let g:gutentags_project_root = ['.gosrcroot']
let g:gutentags_ctags_tagfile = '.tags'

let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
if !isdirectory(s:vim_tags)
    silent! call mkdir(s:vim_tags, 'p')
endif
set tags=./.tags;,.tags

"##### vim-go
let g:go_fmt_autosave = 1
let g:go_fmt_command = "gofmt"

  let g:go_fmt_options = {
      \ 'gofmt': '-s',
      \ 'goimports': '-local mycompany.com',
      \ }

"##### f2-f10
nnoremap <F2> :call asyncrun#quickfix_toggle(6)<cr>
function SetEnv(envs) 
        let envKeys = keys(a:envs)
        for envKey in envKeys
                exec 'let $' . envKey . '="' . a:envs[envKey] . '"'
        endfor
endfunction

function Run(modelname) 
        let l:debugConfigFile = expand('%:h') . '/.ch.json'
        let l:debugConfigList = readfile(l:debugConfigFile)
        let l:debugConfigStr = join(l:debugConfigList, '')
        let l:debugConfigJson = JSON#parse(l:debugConfigStr)
        let l:debugCs = l:debugConfigJson['configurations']
        for singleCs in l:debugCs 
                if 'debug' == a:modelname && 'debug' == singleCs['name']
                        call SetEnv(singleCs['env'])
                        call ClearMapKeysInNotDebugModelForGo()
                        exec 'GoDebugStart ' . singleCs['program'] . ' ' . singleCs['argv']
                        return
                elseif 'runexe' == a:modelname && 'runexe' == singleCs['name']
                        call SetEnv(singleCs['env'])
                        call ClearMapKeysInNotDebugModelForGo()
                        exec 'GoRun ' . singleCs['program'] . ' ' . singleCs['argv']
                        return
                endif
        endfor
        echoerr 'Sorry can\"t not found the valid ' . a:modelname . ' model configurations'
endfunction

function! g:ClearMapKeysInNotDebugModelForGo () 
        augroup vim-go-debug-mp
                autocmd!
        augroup END
        augroup! vim-go-debug-mp
endfunction

function! g:MapKeysInNotDebugModelForGo () 
        augroup vim-go-debug-mp
                autocmd!
                autocmd FileType go nmap <buffer> <F8>  <Plug>(go-debug-stop)
                autocmd FileType go nmap <buffer> <F7> :call Run("debug") <cr>
                autocmd FileType go nmap <buffer> <F5> :call Run("runexe") <cr>
        augroup END
        doautocmd vim-go-debug-mp FileType go
endfunction

call MapKeysInNotDebugModelForGo()

let g:go_debug_windows = {
      \ 'stack': 'leftabove 30vnew',
      \ 'out':   'botright 10new',
      \ 'vars':  'leftabove 30vnew',
\ }
" <F5>  (go-debug-continue)
" <F6>  (go-debug-print)
" <F7>  (go-debug-start)
" <F8>  (go-debug-stop)
" <F9>  (go-debug-breakpoint)
" <F10> (go-debug-next)
" <F11> (go-debug-step)

```

**1**.修改 [debug.vim#L263](https://github.com/fatih/vim-go/blob/0a2fc710b9ccf4c98231de04078a8ac0ef0d63d8/autoload/go/debug.vim?ref=blog.hacking.pub#L263)为

```
  augroup vim-go-debug
    autocmd!
  augroup END 
  augroup! vim-go-debug
  call MapKeysInNotDebugModelForGo()

```

**2**.修改`.debug.json`为`.ch.json`  
**3**.并支持`debug`、`run`环境变量载入

```
$ cat .ch.json 
{
        "configurations": [
                {
                        "name": "debug",
                        "type":"go",
                        "program": "main.go",
                        "env" : {
                                "SL_ENV": "DEV",
                                "sss":"vvv"
                        },
                        "argv": "-s wjs sdf"
                },
                {
                        "name": "runexe",
                        "type":"go",
                        "program": "main.go",
                        "env" : {
                                "SL_ENV": "DEV"
                        },
                        "argv": "hahaha"
                }
        ]
}

```

---

**2018.07.11**

```
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'Shougo/echodoc.vim'
Plugin 'fatih/vim-go', {'do': ':GoUpdateBinaries'}
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'mklabs/vim-json'
Plugin 'majutsushi/tagbar'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'crooloose/nerdtree'
Plugin 'easymotion/vim-easymotion'
Plugin 'sickill/vim-monokai'
Plugin 'Valloric/YouCompleteMe', {'do': './install.sh --clang-completer --go-completer --js-completer --rust-completer'}
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }

call vundle#end()           
"###### simple 
set nu
set nopaste
filetype plugin indent on
syntax enable
set sw=4
set ts=4

"##### tarbar gotags
nmap <C-f> :TagbarToggle<CR>
let ctagsbin = 'gotags'
let GOPATH = '/root/workspace/go'
let g:tagbar_type_go = {
        \ 'ctagstype' : 'go',
        \ 'kinds'     : [
                \ 'p:package',
                \ 'i:imports:1',
                \ 'c:constants',
                \ 'v:variables',
                \ 't:types',
                \ 'n:interfaces',
                \ 'w:fields',
                \ 'e:embedded',
                \ 'm:methods',
                \ 'r:constructor',
                \ 'f:functions'
        \ ],
        \ 'sro' : '.',
        \ 'kind2scope' : {
                \ 't' : 'ctype',
                \ 'n' : 'ntype'
        \ },
        \ 'scope2kind' : {
                \ 'ctype' : 't',
                \ 'ntype' : 'n'
        \ },
        \ 'ctagsbin'  : 'gotags',
        \ 'ctagsargs' : '-sort -silent'
        \ }

"######vim-monokai
syntax enable
colorscheme monokai

"###### apiline_powerline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='luna'
set t_Co=256

"##### LeaderF
let g:Lf_ShortcutF = '<C-P>'
noremap <F2> :LeaderfFunction!<cr>
noremap <c-n> :LeaderfMru<cr>

"##### YouCompleteme
let g:ycm_add_preview_to_completeopt = 0
set completeopt=menu,menuone
let g:ycm_filetype_whitelist = { 
                        \ "go": 1, 
                        \ "js": 1, 
                        \ "c": 1,
                        \ "cpp": 1
                        \}

"#### nerdtree
map <C-e> :NERDTreeToggle<CR>

"#### echodoc
set noshowmode

"#### vim-gutentags
let g:gutentags_project_root = ['.gosrcroot']
let g:gutentags_ctags_tagfile = '.tags'

let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
if !isdirectory(s:vim_tags)
    silent! call mkdir(s:vim_tags, 'p')
endif
set tags=./.tags;,.tags

"##### vim-go
let g:go_fmt_autosave = 1
let g:go_fmt_command = "gofmt"

  let g:go_fmt_options = {
      \ 'gofmt': '-s',
      \ 'goimports': '-local mycompany.com',
      \ }

"##### f2-f10
nnoremap <F2> :call asyncrun#quickfix_toggle(6)<cr>
function RunDebug() 
        let l:debugConfigFile = expand('%:h') . '/.debug.json'
        let l:debugConfigList = readfile(l:debugConfigFile)
        let l:debugConfigStr = join(l:debugConfigList, '')
        let l:debugConfigJson = JSON#parse(l:debugConfigStr)
        let l:debugCs = l:debugConfigJson['configurations']
        for singleCs in l:debugCs 
                if 'debug' == singleCs['name'] 
                        let debugEnv = singleCs['env']
                        let envKeys = keys(debugEnv)
                        for envKey in envKeys
                                exec 'let $' . envKey . '="' . debugEnv[envKey] . '"'
                        endfor
                        exec 'GoDebugStart ' . singleCs['program'] . ' ' . singleCs['argv']
                        return
                endif
        endfor
        echoerr 'Sorry can\"t not found the debug model configurations'
endfunction

augroup vim-go-debug-self
        autocmd!
        autocmd FileType go nmap <buffer> <F8>  <Plug>(go-debug-stop)
augroup END

nnoremap <F7> :call RunDebug() <cr>
let g:go_debug_windows = {
      \ 'stack': 'leftabove 30vnew',
      \ 'out':   'botright 10new',
      \ 'vars':  'leftabove 30vnew',
\ }
" <F5>  (go-debug-continue)
" <F6>  (go-debug-print)
" <F7>  (go-debug-start)
" <F8>  (go-debug-stop)
" <F9>  (go-debug-breakpoint)
" <F10> (go-debug-next)
" <F11> (go-debug-step)

```

如果文件路径上出现了软连接，debug会出现问题  
需要将`vim-go autoload/go/debug.vim`类似地方做如下修改

```
let l:filename = fnamemodify(expand('%'), ':p:gs!\\!/!')
=====>  
  let l:filename = ""
  if expand('%')[0:0] == "/" 
    let filename = expand('%')
  else 
    if system("pwd")[-2:-1] == "\r\n"
      let filename = system("pwd")[0:-3] . "/" . expand('%')
    elseif system("pwd")[-1:-1] == "\n"
      let filename = system("pwd")[0:-2] . "/" . expand('%')
    endif
  endif

```

在项目根目录，新建配置文件`.debug.json`如下

```
{
        "configurations": [
                {
                        "name": "debug",
                        "type":"go",
                        "program": "main.go",
                        "env" : {
                                "SL_ENV": "DEV",
                                "sss":"vvv"
                        },
                       "argv": "-address 0.0.0.0:28899 -ca 10.33.1.132:8500 -cp preview/service/comments/"
                }
        ]
}

```

> 参考  
> [Vim 执行异步任务](https://www.jianshu.com/p/e94e6c7ea341?ref=blog.hacking.pub)