0からcentosにneovim-go開発環境をインストール

13313 ワード

一、GO環境の配置
自分の環境変数にgoのpathを配置する
 77 export GOROOT=/usr/local/go
 78 export PATH=$PATH:$GOROOT/bin
 79 export GOPATH=/data/gowork

二、nvimを取り付ける
1.公式サイトでnvim-linux 64をダウンロードする.tar.gzというインストールパッケージtar-zxvf nvim-linux 64.tar.gz解凍後ln-sを使用してリンクを確立
ln -s /root/nvim/nvim-linux64/bin/nvim nvim

#          , nvim     
export PATH=$PATH:/root/nvim/nvim-linux64/bin

そしてvimを使うようにnvimを使うことができます
三、nodejs&pythone 3のインストール
後でインストールするコード補完プラグインの中には、この2つのコンポーネントのサポートが必要なものがありますので、事前にインストールしてください.
1.nodejsのインストール
1.まずはhttps://npm.taobao.org/mirror...へ.tar zxvfは、保存したいファイルディレクトリの下に解凍する./etc/profileファイルで宣言
export PATH=$PATH:/root/node/node-v14.16.1-linux-x64/bin

4.リンクの設定
ln -s  /root/node/node-v14.16.1-linux-x64/bin/npm ~/npm
ln -s  /root/node/node-v14.16.1-linux-x64/bin/node ~/node
#source     path  
source /etc/profile
[root@VM-0-16-centos ~]# npm -v
6.14.12
[root@VM-0-16-centos ~]# node -v
v14.16.1


           

2.python 3のインストール
1.pythonインストールパッケージhttps://www.python.org/ftp/py...をダウンロード
2.tar -xzf Python-3.8.6rc1.tgz3.解凍したディレクトリに入ると、インストールしたいpyパスにパスするコマンドが実行されます./configure --prefix="/root/python3.8"4.実行が完了するまで、解凍したディレクトリの下でmakemake install 5を順次実行する.コンパイルが完了したら環境変数に追加
alias python3=/root/python3.8/bin/python3.8
alias pip3=/root/python3.8/bin/pip3.8

次にpthone 3-vpip 3-vを確認してインストールに成功しました
四、nvimのプラグインをインストールする
1.mkdir-p~/./を作成するconfig/nvimフォルダを~//config/nvimで作成
  • init.vimファイル(プロファイルに相当)
  • pulggedフォルダ(プロファイルにプラグインのダウンロード保存場所を設定)
  • autoloadフォルダ(plug.vimを置く)
  • 2.git clone https://github.com/junegunn/v... vim-plugディレクトリに入るplug.vimこのファイルは作成したautoloadフォルダにコピーされます
    3.nvim開くinit.vim入力
    "        
    call plug#begin('~/.vim/plugged')
    
    Plug 'fatih/vim-go', { 'tag': '*' }
    Plug 'neoclide/coc.nvim',{'branch':'release'}
    Plug 'Valloric/YouCompleteMe'
    "        ,          
    call plug#end()

    この3つはgoのメインプラグインです
    これはvim-go関連の構成であり、initにも書かれています.vimでいいです.(プラグインの内容と混同しないでください)
    " vim-go
    let g:go_fmt_command = 'goimports'
    let g:go_autodetect_gopath = 1
    " let g:go_bin_path = '$GOBIN'
    
    let g:go_highlight_types = 1
    let g:go_highlight_fields = 1
    let g:go_highlight_functions = 1
    let g:go_highlight_function_calls = 1
    let g:go_highlight_extra_types = 1
    let g:go_highlight_generate_tags = 1
    
    " Open :GoDeclsDir with ctrl-g
    nmap  :GoDeclsDir
    imap  :GoDeclsDir
    
    augroup go
      autocmd!
      autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
    augroup END

    4.次にnvimウィンドウを開き、コマンドモードでPlugInstallプラグインを入力します.
    5.インストールが完了してからコマンドモードでGoInstallBinariesを入力してvim-goをインストールするために必要なプラグインの一部このデフォルトはgobinディレクトリにインストールされています.ダウンロードに失敗した場合はexport GOPROXY=https://goproxy.io,directを入力して再試行します.
    6.nvimを再度開いてコマンドモードでCocInstall coc-go coc-json coc-snippets coc-yamlを入力してcoc関連のプラグインをインストールする
    最後はいくつかのinitです.vimの構成
    "==============================================================================
    " vim      
    "==============================================================================
    "    
    set number
    
    "      
    set syntax=on
    
    "   unix       "
    set fileformat=unix
    
    "  table  
    set tabstop=4
    
    "  
    set shiftwidth=4
    
    "    
    set fenc=utf-8
    
    "    
    set mouse=a
    
    "       
    "set cursorline
    
    "    
    set encoding=utf-8
    
    "    
    set autoindent
    
    set softtabstop=4
    
    "              
    set shiftwidth=4
    set expandtab
    
    "==============================================================================
    " vim plug 
    "==============================================================================
    
    call plug#begin('~/.vim/plugged')
    Plug 'scrooloose/nerdtree'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'mhinz/vim-startify'
    Plug 'fatih/vim-go'
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    
    call plug#end()
    
    "==============================================================================
    " vim plug config 
    "==============================================================================
    
    
    
    "----------------------------------------------------------------------------
    " NERDTree config
    "----------------------------------------------------------------------------
     " F2         
     map  :NERDTreeToggle
     "   vim ,         NERDTree       ,     ,     :q!
     autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
     "   vim     NERDTree
     autocmd vimenter * NERDTree
     "   NERDTree     
     let g:NERDTreeWinSize = 25
    
    "----------------------------------------------------------------------------
    " vim-go config
    "----------------------------------------------------------------------------
    let g:go_fmt_command = 'goimports'
    let g:go_autodetect_gopath = 1
    " let g:go_bin_path = '$GOBIN'
    
    let g:go_highlight_types = 1
    let g:go_highlight_fields = 1
    let g:go_highlight_functions = 1
    let g:go_highlight_function_calls = 1
    let g:go_highlight_extra_types = 1
    let g:go_highlight_generate_tags = 1
    
    " Open :GoDeclsDir with ctrl-g
    nmap  :GoDeclsDir
    imap  :GoDeclsDir
    
    augroup go
      autocmd!
      autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
    augroup END
    
    
    "----------------------------------------------------------------------------
    " coc.vim config
    "----------------------------------------------------------------------------
    " TextEdit might fail if hidden is not set.
    set hidden
    
    " Some servers have issues with backup files, see #649.
    set nobackup
    set nowritebackup
    
    " Give more space for displaying messages.
    set cmdheight=2
    
    " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
    " delays and poor user experience.
    set updatetime=300
    
    " Don't pass messages to |ins-completion-menu|.
    set shortmess+=c
    
    " Always show the signcolumn, otherwise it would shift the text each time
    " diagnostics appear/become resolved.
    if has("patch-8.1.1564")
      " Recently vim can merge signcolumn and number column into one
      set signcolumn=number
    else
      set signcolumn=yes
    endif
    
    " Use tab for trigger completion with characters ahead and navigate.
    " NOTE: Use command ':verbose imap ' to make sure tab is not mapped by
    " other plugin before putting this into your config.
    inoremap  
          \ pumvisible() ? "\" :
          \ check_back_space() ? "\" :
          \ coc#refresh()
    inoremap  pumvisible() ? "\" : "\"
    
    function! s:check_back_space() abort
      let col = col('.') - 1
      return !col || getline('.')[col - 1]  =~# '\s'
    endfunction
    
    " Use  to trigger completion.
    if has('nvim')
      inoremap   coc#refresh()
    else
      inoremap   coc#refresh()
    endif
    
    " Use  to confirm completion, `u` means break undo chain at current
    " position. Coc only does snippet and additional edit on confirm.
    "  could be remapped by other vim plugin, try `:verbose imap `.
    if exists('*complete_info')
      inoremap   complete_info()["selected"] != "-1" ? "\" : "\u\"
    else
      inoremap   pumvisible() ? "\" : "\u\"
    endif
    
    " Use `[g` and `]g` to navigate diagnostics
    " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
    nmap  [g (coc-diagnostic-prev)
    nmap  ]g (coc-diagnostic-next)
    
    " GoTo code navigation.
    nmap  gd (coc-definition)
    nmap  gy (coc-type-definition)
    nmap  gi (coc-implementation)
    nmap  gr (coc-references)
    
    " Use K to show documentation in preview window.
    nnoremap  K :call show_documentation()
    
    function! s:show_documentation()
      if (index(['vim','help'], &filetype) >= 0)
        execute 'h '.expand('')
      else
        call CocAction('doHover')
      endif
    endfunction
    
    " Highlight the symbol and its references when holding the cursor.
    autocmd CursorHold * silent call CocActionAsync('highlight')
    
    " Symbol renaming.
    nmap rn (coc-rename)
    
    " Formatting selected code.
    xmap f  (coc-format-selected)
    nmap f  (coc-format-selected)
    
    augroup mygroup
      autocmd!
      " Setup formatexpr specified filetype(s).
      autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
      " Update signature help on jump placeholder.
      autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
    augroup end
    
    " Applying codeAction to the selected region.
    " Example: `aap` for current paragraph
    xmap a  (coc-codeaction-selected)
    nmap a  (coc-codeaction-selected)
    
    " Remap keys for applying codeAction to the current buffer.
    nmap ac  (coc-codeaction)
    " Apply AutoFix to problem on the current line.
    nmap qf  (coc-fix-current)
    
    " Map function and class text objects
    " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
    xmap if (coc-funcobj-i)
    omap if (coc-funcobj-i)
    xmap af (coc-funcobj-a)
    omap af (coc-funcobj-a)
    xmap ic (coc-classobj-i)
    omap ic (coc-classobj-i)
    xmap ac (coc-classobj-a)
    omap ac (coc-classobj-a)
    
    " Use CTRL-S for selections ranges.
    " Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
    nmap   (coc-range-select)
    xmap   (coc-range-select)
    
    " Add `:Format` command to format current buffer.
    command! -nargs=0 Format :call CocAction('format')
    
    " Add `:Fold` command to fold current buffer.
    command! -nargs=? Fold :call     CocAction('fold', )
    
    " Add `:OR` command for organize imports of the current buffer.
    command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
    
    " Add (Neo)Vim's native statusline support.
    " NOTE: Please see `:h coc-status` for integrations with external plugins that
    " provide custom statusline: lightline.vim, vim-airline.
    set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
    
    " Mappings for CoCList
    " Show all diagnostics.
    nnoremap  a  :CocList diagnostics
    " Manage extensions.
    nnoremap  e  :CocList extensions
    " Show commands.
    nnoremap  c  :CocList commands
    " Find symbol of current document.
    nnoremap  o  :CocList outline
    " Search workspace symbols.
    nnoremap  s  :CocList -I symbols
    " Do default action for next item.
    nnoremap  j  :CocNext
    " Do default action for previous item.
    nnoremap  k  :CocPrev
    " Resume latest coc list.
    nnoremap  p  :CocListResume

    参照:https://pokitpeng.github.io/p... https://learnku.com/articles/...