1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VimにPythonコードの補完機能を設定する

1
Posted at

プラグインマネージャー(vim-plug)をインストールする

ターミナルで、以下のコマンドを実行し、vim-plugをダウンロードしてください。

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

プラグインと補完の基本設定を追記する

Vimで .vimrc を開き、以下の設定を追記し、保存してください。

" プラグインの追加
call plug#begin()
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
call plug#end()

" Tabキーで補完候補を選択できるようにする設定
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

プラグインをインストールする

Vimを一度再起動するか、ノーマルモードで :source ~/.vimrc を実行して設定を読み込ませた後、以下のコマンドを実行してください。
画面が分割され、Done! と表示されればプラグインの導入は完了です(:q で画面を閉じてください)。

:PlugInstall

言語サーバー(Language Server)をインストールする

Pythonの補完データ(言語サーバー)をインストールします。
HTMLやTypeScriptなどの各言語専用の補完データ(言語サーバー)をインストールしたい場合は、対象の言語のファイル(例:index.html)をVimで開き、ノーマルモードで以下のコマンドを実行してください。

:LspInstallServer

画面の指示に従うと、自動的にPython用のサーバーがインストールされます。同様に .js や .ts 、 .css ファイルを開いた状態でも :LspInstallServer を実行することで、それぞれの言語に対応した補完が有効になります。
 
これで、インサートモードで文字を入力し始めると自動的に補完候補のポップアップが表示され、Tab キーで選択できるようになります。

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?