LoginSignup
0
1

More than 3 years have passed since last update.

[MEMO][開発環境構築] vim

Last updated at Posted at 2020-02-01

はじめに

開発環境

Linux

この記事について

環境構築やエラー解決のHowToが中心のメモです。

VIM

参考記事
https://qiita.com/jnchito/items/5141b3b01bced9f7f48f
https://qiita.com/ahiruman5/items/4f3c845500c172a02935
https://qiita.com/morikooooo/items/9fd41bcd8d1ce917030
https://qiita.com/tekkoc/items/98adcadfa4bdc8b5a6ca

Color Theme

vim plug

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

vimrc

.vimrc
"----------------------------------------------------------
" Vim Plug
"----------------------------------------------------------
call plug#begin('~/.vim/plugged')
" 補完
Plug 'Valloric/YouCompleteMe'
" linter fixer
Plug 'dense-analysis/ale'
" ALE用のlightline拡張
Plug 'maximbaz/lightline-ale'
" ファイルオープンを便利に
Plug 'Shougo/unite.vim'
" Unite.vimで最近使ったファイルを表示できるようにする
Plug 'Shougo/neomru.vim'
" ファイルをtree表示してくれる
Plug 'preservim/nerdtree'
" Gitを便利に使う
Plug 'tpope/vim-fugitive'
" ステータスラインの表示内容強化
Plug 'itchyny/lightline.vim'
" インデントの可視化
Plug 'Yggdroot/indentLine'
" 末尾の全角半角空白文字を赤くハイライト
Plug 'bronson/vim-trailing-whitespace'
" シングルクオートとダブルクオートの入れ替え等
" cs : change string
" ds : delete string
Plug 'tpope/vim-surround'
" Window幅変更
" ctrl+e
Plug 'simeji/winresizer'
" コメントアウト
" gc gcc
Plug 'tpope/vim-commentary'
" emmet
Plug 'mattn/emmet-vim'
" IDEのように(){}[]を補完、削除
Plug 'jiangmiao/auto-pairs'
call plug#end()

"----------------------------------------------------------
" 基本設定
"----------------------------------------------------------
" バックアップファイルを作らない
set nobackup
" スワップファイルを作らない
set noswapfile
" 編集中のファイルが変更されたら自動で読み直す
set autoread
" バッファが編集中でもその他のファイルを開けるように
set hidden
" クラッシュ防止
set synmaxcol=200
" 永続的Undoを有効化
if has('persistent_undo')
  set undodir=~/.config/nvim/undo
  set undofile
endif
" インサートモード
inoremap <silent> jj <ESC>
"クリップボード共有
"インデント時にコメントアウトを連続させない
autocmd FileType * set comments=
"ヤンクをクリップボードに
nnoremap y "+y
vnoremap y "+y


"----------------------------------------------------------
" カラースキーム
"----------------------------------------------------------
set background=dark
colorscheme desert
set t_Co=256
syntax enable " 構文に色を付ける
set guifont=Migu_1M:h14

"----------------------------------------------------------
" ALE
"----------------------------------------------------------
" pythonの実行場所を指定
let g:ycm_path_to_python_interpreter = '/home/hashimo/.pyenv/shims/python'
let g:ale_linters = {
    \  'python' :['flake8'],
    \ }
" 保存時に自動でfixする
"let g:ale_fix_on_save = 1
" sign_columnを常に表示する
"let g:ale_sign_column_always = 1
" 表示の変更
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
" ファイルオープン時にチェック
let g:ale_lint_on_enter = 1

"----------------------------------------------------------
" 文字
"----------------------------------------------------------
set fileencoding=utf-8 " 保存時の文字コード
set fileencodings=ucs-boms,utf-8,euc-jp,cp932 " 読み込み時の文字コードの自動判別. 左側が優先される
set fileformats=unix,dos,mac " 改行コードの自動判別. 左側が優先される
set ambiwidth=double " □や○文字が崩れる問題を解決

"----------------------------------------------------------
" ステータスライン
"----------------------------------------------------------
set laststatus=2 " ステータスラインを常に表示
set showmode " 現在のモードを表示
set showcmd " 打ったコマンドをステータスラインの下に表示
set ruler " ステータスラインの右側にカーソルの位置を表示する

let g:lightline= {}

let g:lightline.component_expand = {
      \  'linter_checking': 'lightline#ale#checking',
      \  'linter_infos': 'lightline#ale#infos',
      \  'linter_warnings': 'lightline#ale#warnings',
      \  'linter_errors': 'lightline#ale#errors',
      \  'linter_ok': 'lightline#ale#ok',
      \ }

let g:lightline.component_type = {
      \     'linter_checking': 'right',
      \     'linter_infos': 'right',
      \     'linter_warnings': 'warning',
      \     'linter_errors': 'error',
      \     'linter_ok': 'right',
      \ }

let g:lightline.active = { 'right': [[ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ]] }

"----------------------------------------------------------
"コマンドモード
"----------------------------------------------------------
set wildmenu " コマンドモードの補完
set history=5000 " 保存するコマンド履歴の数

"----------------------------------------------------------
" タブ・インデント
"----------------------------------------------------------
set expandtab " タブ入力を複数の空白入力に置き換える
set tabstop=4 " 画面上でタブ文字が占める幅
set softtabstop=4 " 連続した空白に対してタブキーやバックスペースキーでカーソルが動く幅
set autoindent " 改行時に前の行のインデントを継続する
set smartindent " 改行時に前の行の構文をチェックし次の行のインデントを増減する
set shiftwidth=4 " smartindentで増減する幅

"----------------------------------------------------------
" 文字列検索
"----------------------------------------------------------
set incsearch " インクリメンタルサーチ. 1文字入力毎に検索を行う
set ignorecase " 検索パターンに大文字小文字を区別しない
set smartcase " 検索パターンに大文字を含んでいたら大文字小文字を区別する
set hlsearch " 検索結果をハイライト

" ESCキー2度押しでハイライトの切り替え
nnoremap <silent><Esc><Esc> :<C-u>set nohlsearch!<CR>

"----------------------------------------------------------
" カーソル
"----------------------------------------------------------
set whichwrap=b,s,h,l,<,>,[,],~ " カーソルの左右移動で行末から次の行の行頭への移動が可能になる
set number " 行番号を表示
set cursorline " カーソルラインをハイライト

" 行が折り返し表示されていた場合、行単位ではなく表示行単位でカーソルを移動する
nnoremap j gj
nnoremap k gk
nnoremap <down> gj
nnoremap <up> gk

" 移動を楽にする
"
" 段落
nnoremap <C-j> }
nnoremap <C-k> {

" 1画面移動
" nnoremap <C-k> <C-b>
" nnoremap <C-j> <C-f>

" バックスペースキーの有効化
set backspace=indent,eol,start


"----------------------------------------------------------
" カッコ・タグの対応
"----------------------------------------------------------
let loaded_matchparen = 1 " カッコのハイライトを消す
"set showmatch " 括弧の対応関係を一瞬表示する
"source $VIMRUNTIME/macros/matchit.vim " Vimの「%」を拡張する

"----------------------------------------------------------
" マウスでカーソル移動とスクロール
"----------------------------------------------------------
" if has('mouse')
"     set mouse=a
"     if has('mouse_sgr')
"         set ttymouse=sgr
"     elseif v:version > 703 || v:version is 703 && has('patch632')
"         set ttymouse=sgr
"     else
"         set ttymouse=xterm2
"     endif
" endif

"----------------------------------------------------------
" クリップボードからのペースト
"----------------------------------------------------------
" 挿入モードでクリップボードからペーストする時に自動でインデントさせないようにする
if &term =~ "xterm"
    let &t_SI .= "\e[?2004h"
    let &t_EI .= "\e[?2004l"
    let &pastetoggle = "\e[201~"

    function XTermPasteBegin(ret)
        set paste
        return a:ret
    endfunction

    inoremap <special> <expr> <Esc>[200~ XTermPasteBegin("")
endif

"----------------------------------------------------------
" スペース系コマンド
"----------------------------------------------------------
noremap <Space>w :w<CR>
noremap <Space>q :wq<CR>
noremap <Space>. :e ~/.vimrc<CR>

"----------------------------------------------------------
" S系コマンド
"----------------------------------------------------------
nnoremap s <Nop> "clコマンドで代用
" Window間の移動
nnoremap sj <C-w>j
nnoremap sk <C-w>k
nnoremap sl <C-w>l
nnoremap sh <C-w>h
" Window自体の移動
nnoremap sJ <C-w>J
nnoremap sK <C-w>K
nnoremap sL <C-w>L
nnoremap sH <C-w>H
" タブ
nnoremap sn gt
nnoremap sp gT
nnoremap st :<C-u>tabnew<CR>
" バッファ
nnoremap sN :<C-u>bn<CR>
nnoremap sP :<C-u>bp<CR>
nnoremap sQ :<C-u>bd<CR>
nnoremap sT :<C-u>Unite tab<CR>
" Window編集
nnoremap ss :<C-u>sp<CR>
nnoremap sv :<C-u>vs<CR>
nnoremap s= <C-w>=
nnoremap sq :<C-u>q<CR>
" Unite
nnoremap sb :<C-u>Unite buffer_tab -buffer-name=file<CR>
nnoremap sB :<C-u>Unite buffer -buffer-name=file<CR>

"----------------------------------------------------------
" 自動的に閉じ括弧を入力
"----------------------------------------------------------
" imap { {}<Left>
" imap ( ()<ESC>
" imap [ []<LEFT>

"----------------------------------------------------------
" NERDTree
"----------------------------------------------------------
map <C-n> :NERDTreeToggle<CR> "ツリーの開閉
let NERDTreeShowHidden = 1 "隠しファイルを表示

"----------------------------------------------------------
" ディレクトリが存在しなければ作成
"----------------------------------------------------------
augroup vimrc-auto-mkdir  " {{{
  autocmd!
  autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
  function! s:auto_mkdir(dir, force)  " {{{
    if !isdirectory(a:dir) && (a:force ||
    \    input(printf('"%s" does not exist. Create? [y/N]', a:dir)) =~? '^y\%[es]$')
      call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
    endif
  endfunction  " }}}
augroup END  " }}}

"----------------------------------------------------------
" emmet
"----------------------------------------------------------
let g:user_emmet_mode='a'    "enable all function in all mode.

"----------------------------------------------------------
" filetypeの自動検出(最後の方に書いた方がいいらしい)
filetype on

0
1
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
0
1