기존 리눅스 개발환경에서는 ctags와 vi만을 사용했었습니단 이번에 파이썬을 공부하면서 더 나은(?) 개발환경을 구축해야겠다고 생각했습니다.

 

원래 계획은 vim을 사용해서 개발환경을 구축할 계획이었지만 자료를 찾아보던중 vim보다는 neovim을 이용해 개발환경을 구축하는 것이 더 나을 것이라 생각이들었습니다.

 

neovim을 선택한 이유는 vim은 python 없이 vim을 컴파일 했을 경우 python을 사용하기 위해 다시 재컴파일 해야한다는 단점이 있었지만 neovim은 pip3 install neovim 처럼 불리된 형태로 설치할 수 있었기 때문입니다.(기존의 vim도 git에서 소스를 받아 python3옵션을 추가해 컴파일하면 python3를 사용가능합니다.)

또한 neovim은 버퍼로 터미널을 쓸수도 있다. [ :bel sp 50 | resize 10 | terminal ]

 

설치

brew install nvim
brew install cmake
brew install luarocks
brew install pkg-config

#nodeJs 설치
brew install node

#yarn 설치
brew install yarn

#vim-plug설치
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

pip3 install --user pynvim

neovim 설정 및 coc.nvim설치

환경파일 작성

mkdir -p ~/.config/nvim

cat > ~/.config/nvim/init.vim

"----------------------------------------------------------------------------------
"-- config
"----------------------------------------------------------------------------------
" set UTF-8 encoding
set enc=utf-8
set fenc=utf-8
set termencoding=utf-8

set hlsearch
set ignorecase

set nocompatible        " disable vi compatibility (emulation of old bugs)
set autoindent  " use indentation of previous line
set smartindent " use intelligent indentation for C

" configure tabwidth and insert spaces instead of tabs
set tabstop=4        " tab width is 4 spaces
set shiftwidth=4     " indent also with 4 spaces
set expandtab        " expand tabs to spaces
" wrap lines at 120 chars. 80 is somewaht antiquated with nowadays displays.
set textwidth=120
" turn syntax highlighting on
set t_Co=256
syntax on
" colorscheme wombat256
set number      " turn line numbers on
set showmatch   " highlight matching braces

set comments=sl:/*,mb:\ *,elx:\ */      " intelligent comments


"----------------------------------------------------------------------------------
"-- keyboard mappings
"----------------------------------------------------------------------------------
" switch between header/source with F4
map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>
" goto definition with F12
map <F12> <C-]>


"----------------------------------------------------------------------------------
"-- plugins
"----------------------------------------------------------------------------------
call plug#begin('~/.config/nvim/plugged')
" Use release branch
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Or latest tag
Plug 'neoclide/coc.nvim', {'tag': '*', 'branch': 'release'}
" Or build from source code by use yarn: https://yarnpkg.com
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}
call plug#end()


"----------------------------------------------------------------------------------
"-- plugin config
"----------------------------------------------------------------------------------

 

설정파일 생성 후 플러그인 설치

nvim +PlugInstall

설치가 끝나면 이제  coc환경설정 파일을 만들어 주어야합니다.

#~/.config/nvim/coc-settings.json이 열립니다
nvim +CocConfig
{
  "languageserver": {
    "golang": {
      "command": "gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"]
    },
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "objc", "objcpp"],
      "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "initializationOptions": {
         "cache": {
           "directory": "/tmp/ccls"
         }
       }
    },
    "python": {
   "command": "python",
   "args": [
     "-mpyls",
     "-vv",
     "--log-file",
     "/tmp/lsp_python.log"
   ],
   "trace.server": "verbose",
   "filetypes": [
     "python"
   ],
   "settings": {
     "pyls": {
       "enable": true,
       "trace": {
         "server": "verbose"
       },
       "commandPath": "",
       "configurationSources": [
         "pycodestyle"
       ],
       "plugins": {
         "jedi_completion": {
           "enabled": true
         },
         "jedi_hover": {
           "enabled": true
         },
         "jedi_references": {
           "enabled": true
         },
         "jedi_signature_help": {
           "enabled": true
         },
         "jedi_symbols": {
           "enabled": true,
           "all_scopes": true
         },
         "mccabe": {
           "enabled": true,
           "threshold": 15
         },
         "preload": {
           "enabled": true
         },
         "pycodestyle": {
           "enabled": true
         },
         "pydocstyle": {
           "enabled": false,
           "match": "(?!test_).*\\.py",
           "matchDir": "[^\\.].*"
         },
         "pyflakes": {
           "enabled": true
         },
         "rope_completion": {
           "enabled": true
         },
         "yapf": {
           "enabled": true
        }
      }
    }
  }
}
  }
}

설정파일 저장후 nvim에서 :CocInstall coc-python 입력하면 설치가 완료된다.

 

 

참고

https://www.joinc.co.kr/w/man/12/neovim

https://yamoe.tistory.com/534

https://github.com/junegunn/vim-plug

'개발환경' 카테고리의 다른 글

Mac Os에서 ctags 설치 & 사용법  (0) 2020.02.09
.vimrc 파일 저장(수정중)  (0) 2020.02.09
Homebrew의 bundle로 Mac한번에 셋팅하기  (0) 2019.11.11
Homebrew Cask 설치하기  (0) 2019.11.11
MacOS에서 Homebrew 설치하기  (0) 2019.11.10