Skip to content

Instantly share code, notes, and snippets.

@yuya-matsushima
Last active May 2, 2019 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuya-matsushima/594a8199f4031589bbba6e482c996009 to your computer and use it in GitHub Desktop.
Save yuya-matsushima/594a8199f4031589bbba6e482c996009 to your computer and use it in GitHub Desktop.
set fileencodings=utf-8,ucs-bom,euc-jp,iso-2022-jp,sjis,cp932,utf-16,utf-16le
"scriptencoding utf-8
"set verbosefile=~/vimlog
call plug#begin('~/.vim/plugged')
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'ryanolsonx/vim-lsp-javascript'
Plug 'thomasfaingnaert/vim-lsp-neosnippet'
Plug 'Shougo/neosnippet'
Plug 'Shougo/neosnippet-snippets'
Plug 'Shougo/vimproc.vim', {'build':'make'}
Plug 'thinca/vim-quickrun'
Plug 'kana/vim-smartchr'
Plug 'vim-scripts/closetag.vim'
"Go
Plug 'fatih/vim-go'
let g:go_fmt_command = "goimports"
" LSPに任せる機能をOFFにする
let g:go_def_mapping_enabled = 0
let g:go_doc_keywordprg_enabled = 0
"JS
Plug 'othree/yajs.vim'
Plug 'jiangmiao/simple-javascript-indenter'
Plug 'mxw/vim-jsx'
Plug 'posva/vim-vue'
Plug 'leafgarland/typescript-vim'
"Ruby/Rails
Plug 'tpope/vim-endwise'
Plug 'slim-template/vim-slim'
Plug 'tpope/vim-haml'
"HTML/CSS
Plug 'cakebaker/scss-syntax.vim'
Plug 'plasticboy/vim-markdown'
"PHP
Plug 'StanAngeloff/php.vim'
"Docker
Plug 'ekalinin/Dockerfile.vim'
call plug#end()
if executable('go-langserver')
augroup LspGo
au!
au User lsp_setup call lsp#register_server({
\ 'name': 'go-langserver',
\ 'cmd': {server_info->['go-langserver', '-gocodecompletion']},
\ 'whitelist': ['go'],
\ })
au FileType go setlocal omnifunc=lsp#complete
augroup END
endif
if executable('solargraph')
augroup LspRuby
au!
au User lsp_setup call lsp#register_server({
\ 'name': 'solargraph',
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'solargraph stdio']},
\ 'initialization_options': {"diagnostics": "true"},
\ 'whitelist': ['ruby'],
\ })
au FileType ruby setlocal omnifunc=lsp#complete
augroup END
endif
if executable('typescript-language-server')
augroup LspTs
au!
au User lsp_setup call lsp#register_server({
\ 'name': 'javascript support using typescript-language-server',
\ 'cmd': { server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
\ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json'))},
\ 'whitelist': ['javascript', 'javascript.jsx'],
\ })
au FileType javascript,typescript setlocal omnifunc=lsp#complete
augroup END
endif
if executable('intelephense')
augroup LspPhp
au!
au User lsp_setup call lsp#register_server({
\ 'name': 'intelephense',
\ 'cmd': {server_info->['node', expand('/usr/local/lib/node_modules/intelephense/lib/intelephense.js'), '--stdio']},
\ 'initialization_options': {"storagePath": "~/.vim/tmp/intelephense"},
\ 'whitelist': ['php'],
\ })
au FileType php setlocal omnifunc=lsp#complete
augroup END
endif
filetype on
"##### 基本設定 #####
au!
syntax on
colorscheme e2esound
"indent有効化
filetype indent on
"plugin有効化
filetype plugin on
"Popup Color
highlight PMenu ctermbg=0
highlight PMenuSel ctermbg=4
highlight PMenuSbar ctermbg=0
highlight PMenuThumb ctermbg=0
"定義path
let $MYVIMRC=$HOME . '/.vimrc'
let $DICT=$HOME . '/.vim/dict'
"sudoで保存
command! Sudow :w !sudo tee >/dev/null %
"関数定義
"保存時の設定
function! RTrim()
let s:cursor = getpos(".")
if &filetype == "markdown"
match Underlined /\s\{2}$/
%s/\s\+\(\s\{2}\)$/\1/e
else
%s/\s\+$//e
endif
call setpos(".", s:cursor)
endfunction
function! LTrimTabAndSpace()
let s:cursor = getpos(".")
%s/^(\t|\s)\+$//e
call setpos(".", s:cursor)
endfunction
"読点をカンマに変換
function! ToComma()
let s:cursor = getpos(".")
%s/、/, /e
call setpos(".", s:cursor)
endfunction
set noundofile
"Insertモード時にIME OFF
set iminsert=0
"行番号表示
set nonu
"ファイル保存ダイアログの初期ディレクトリをバッファファイル位置に指定
set browsedir=buffer
if has('win32') || has('win64') || has('mac')
set clipboard+=unnamed
endif
"新たに開く場合に変更中のファイルを保存しないで他のファイル表示
set hidden
"インクリメンタルサーチ
set incsearch
"検索時に大文字小文字混合の場合のみ、大文字小文字通りに処理
"それ以外は大文字小文字無視
set smartcase
"検索をループさせない
set wrapscan
"検索時ime停止
set imsearch=0
"検索結果のキーワードがハイライトされた場合、esc連打で消える
set hlsearch
noremap <esc><esc> :nohlsearch<CR><esc>
"タブ文字、行末等の不可視文字非表示
set nolist
augroup displayList
autocmd!
autocmd FileType html,python setlocal list
augroup END
"listの文字指定
set listchars=eol:$,tab:>\ ,extends:<
"※などの文字列を正しく表示させる
set ambiwidth=double
"tabサイズ
set tabstop=2
"1タブをtabstop分のスペースとして扱う
set expandtab
set shiftwidth=2
augroup tabSetting
autocmd!
autocmd FileType php,ctp,html,css setlocal expandtab tabstop=2 shiftwidth=2
autocmd FileType javascript,jade setlocal tabstop=2 shiftwidth=2 expandtab
autocmd FileType markdown setlocal tabstop=4 shiftwidth=4
autocmd FileType html setlocal expandtab tabstop=4 shiftwidth=4
autocmd FileType slim setlocal expandtab tabstop=2 shiftwidth=2
autocmd FileType go setlocal noexpandtab tabstop=2 shiftwidth=2
"php tab indent
"autocmd FileType php,ctp,html,css setlocal noexpandtab tabstop=4 shiftwidth=4
autocmd FileType php setlocal tabstop=4 shiftwidth=4
augroup END
"インデントを現在行と同一化
set autoindent
"C言語型インデント
set cindent
"新しい行は自動インデント
set smartindent
"改行コード
"set fileformat=unix
"backspaceでindent、改行を削除
set backspace=2
"set cursorline
"行頭行末でカーソルを止めない
set whichwrap=b,s,h,l,<,>,[,]
"自動折返しを日本語対応
set formatoptions+=mM
"閉じカッコ挿入時に対応カッコ強調
set showmatch
"swapを作らない
set noswapfile
"backupを作らない
set nobackup
"同時編集しているファイルが更新された場合
"追随して更新する
set autoread
"コマンドライン補完強化
set wildmenu
"コマンドラインの高さ
set cmdheight=2
"コマンドをステータス行に表示
set showcmd
"ステータスライン表示設定
set statusline=\%t\%=\[%l/%L]\[%{&filetype}]\[%{&fileencoding}]
"ステータスライン表示
set laststatus=2
"ありがとう非表示
set notitle
"diff設定
set diffopt=filler,iwhite
"window分割方向
set splitbelow
set splitright
"キーのビープ音及びフラッシュを停止
set visualbell t_vb=
"vimdiff時の不要な表示をしない
set diffopt-=filler diffopt=iwhite,horizontal
"加算を10進数対応にする
set nf=
set completeopt=menuone
"折り畳み設定
set foldenable
set foldmethod=indent
"set foldlevel=1
set fillchars=vert:\1
augroup folding
autocmd!
autocmd FileType gitcommit,hgcommit,ref-refe,ref-phpmanual setlocal nofoldenable
autocmd FileType scss,css setlocal foldmethod=marker foldmarker={,}
autocmd FileType html,xhtml setlocal foldmethod=indent
autocmd FileType ruby setlocal foldmethod=indent
augroup END
"php限定設定
let g:php_baselib = 1
let g:php_htmlInStrings = 1
let g:php_noShortTags = 1
let g:php_sql_query = 1
"##### 基本キーバインド設定 #####
"コロン,セミコロン入替
noremap ; :
noremap : ;
imap <> <><Left>
"##### vimスクリプト設定 #####
let g:closetag_filenames='*.html,,*.php,*.js,*.coffee,*.xml,*.rb,*.erb'
augroup shortcut
autocmd!
autocmd FileType php imap <buffer> <? <?php
autocmd FileType * imap <buffer> , ,
autocmd FileType javascript,coffee,php,c imap <buffer> // //
autocmd FileType ruby imap <buffer> # #
augroup END
"##### 辞書設定 #####
"補完参照先の追加
set complete+=k
"辞書設定
augroup dict
autocmd!
autocmd FileType javascript,coffee setlocal dictionary=$DICT/javascript.dict,$DICT/react.dict
autocmd FileType php setlocal dictionary=$DICT/php.dict
autocmd FileType html,xhtml setlocal dictionary=$DICT/html.dict
autocmd FileType yml,yaml setlocal dictionary=$DICT/yaml.dict
autocmd FileType slim setlocal dictionary=$DICT/slim.dict
autocmd FileType sass setlocal dictionary=$DICT/sass.compass.dict
augroup END
"FileTypeのエイリアス追加
augroup alias
autocmd!
autocmd BufRead,BufNewFile *.md,*.md.erb setlocal filetype=markdown
autocmd BufRead,BufNewFile *.scala.html setlocal filetype=scala
autocmd FileType js setlocal ft=javascript
autocmd BufRead,BufNewFile *.ts set filetype=typescript
autocmd FileType rb,watchr,vagrantfile,Guardfile setlocal ft=ruby
autocmd FileType smarty,tpl,ciunit,ctp setlocal ft=php
autocmd FileType sql setlocal ft=mysql
autocmd FileTYpe scss.css setlocal ft=scss
autocmd FileType .envrc setlocal ft=sh
augroup END
"smartchrの設定
"inoremap <expr> , smartchr#one_of(', ',',')
augroup smartchr
autocmd!
autocmd Filetype php,ruby,eruby,slim,javascript,typescript,coffee,python,perl,c inoremap <expr> = smartchr#one_of(' = ',' == ',' === ','=')
autocmd Filetype php,ruby,eruby,slim,javascript,typescript,coffee,python,perl inoremap <expr> ~ smartchr#one_of('~',' =~ ')
autocmd FileType php inoremap <expr> * smartchr#one_of('* ','/**', '*/', '*')
autocmd Filetype markdown inoremap <expr> _ smartchr#one_of('_','__','\_')
autocmd Filetype markdown inoremap <expr> # smartchr#one_of('# ','## ', '### ', '#### ', '##### ', '###### ', '\#')
autocmd Filetype haml inoremap <expr> ` smartchr#one_of('%','`')
autocmd Filetype javascript inoremap <expr> > smartchr#one_of('>',' => ')
autocmd Filetype go inoremap <expr> = smartchr#one_of(' = ',' == ', '=')
autocmd Filetype go inoremap <expr> : smartchr#one_of(':',' := ')
autocmd Filetype go inoremap <expr> ! smartchr#one_of('!',' != ')
augroup END
augroup bufferEvent
autocmd!
"CD.vim
autocmd BufEnter * execute 'lcd ' fnameescape(expand('%:p:h'))
"au BufWritePre *.php,*.rb,*.feature,*.js,*.bat,*.css,*.sass,*.scss,*.py,*.haml,*.slim,*coffee,*.tpl,*.md,Rakefile,*.go,*.c,*.yml call RTrim()
autocmd BufWritePre * call RTrim()
autocmd BufWritePre * call LTrimTabAndSpace()
"autocmd BufWritePre *.php,*.js,*.html,*.rb,*.css,*.py setlocal ff=unix
autocmd BufWritePre *.md call ToComma()
autocmd BufWritePre *.php,*.js,*.rb,*.py,*.c setlocal fenc=utf-8
augroup END
"ファイル毎に文字数設定
augroup width
autocmd!
autocmd FileType gitcommit,hgcommit setlocal textwidth=72
autocmd FileType rst setlocal textwidth=80
autocmd FileType javascript,coffee setlocal textwidth=80
autocmd FileType php setlocal textwidth=80
if exists('&colorcolumn')
autocmd FileType rst,gitcommit,hgcommit setlocal colorcolumn=+1
endif
augroup END
"quickrun.vim
silent! nmap <unique>qq <Plug>(quickrun)
let g:quickrun_config = {}
let g:quickrun_config['_'] = {'split': 'below'}
npm install -g typescript typescript-language-server
npm -g install intelephense
go get -u github.com/sourcegraph/go-langserver
gem install solargraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment