Created
June 30, 2017 07:34
-
-
Save makotoshimazu/0c9d787741770d8d38a1ff5c3eff6470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Enable modern Vim features not compatible with Vi spec. | |
set nocompatible | |
" Use the 'google' package by default (see http://go/vim/packages). | |
let google_vim = "/usr/share/vim/google/google.vim" | |
if filereadable(google_vim) | |
execute 'source' fnameescape(google_vim) | |
endif | |
" release autogroup in MyAutoCmd | |
augroup MyAutoCmd | |
autocmd! | |
augroup END | |
"""""""""" | |
" Global Key Settings | |
"""""""""" | |
let mapleader = "," | |
""""""""" | |
" Search | |
""""""""" | |
set ignorecase " 大文字小文字を区別しない | |
set smartcase " 検索文字に大文字がある場合は大文字小文字を区別 | |
set incsearch " インクリメンタルサーチ | |
set hlsearch " 検索マッチテキストをハイライト (2013-07-03 14:30 修正) | |
" バックスラッシュやクエスチョンを状況に合わせ自動的にエスケープ | |
cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/' | |
cnoremap <expr> ? getcmdtype() == '?' ? '\?' : '?' | |
""""""""" | |
" Edit | |
""""""""" | |
set shiftround " '<'や'>'でインデントする際に'shiftwidth'の倍数に丸める | |
set infercase " 補完時に大文字小文字を区別しない | |
set virtualedit=all " カーソルを文字が存在しない部分でも動けるようにする | |
set hidden " バッファを閉じる代わりに隠す(Undo履歴を残すため) | |
set switchbuf=useopen " 新しく開く代わりにすでに開いてあるバッファを開く | |
set showmatch " 対応する括弧などをハイライト表示する | |
set matchtime=3 " 対応括弧のハイライト表示を3秒にする | |
" 対応括弧に'<'と'>'のペアを追加 | |
set matchpairs& matchpairs+=<:> | |
" バックスペースでなんでも消せるようにする | |
set backspace=indent,eol,start | |
" クリップボードをデフォルトのレジスタとして指定。後にYankRingを使うので | |
" 'unnamedplus'が存在しているかどうかで設定を分ける必要がある | |
if has('unnamedplus') | |
" set clipboard& clipboard+=unnamedplus " 2013-07-03 14:30 unnamed 追加 | |
set clipboard& clipboard+=unnamedplus,unnamed | |
else | |
" set clipboard& clipboard+=unnamed,autoselect 2013-06-24 10:00 autoselect 削除 | |
set clipboard& clipboard+=unnamed | |
endif | |
" Swapファイル?Backupファイル?前時代的すぎ | |
" なので全て無効化する | |
set nowritebackup | |
set nobackup | |
set noswapfile | |
""""""""" | |
" Display | |
""""""""" | |
set list " 不可視文字の可視化 | |
set number " 行番号の表示 | |
set wrap " 長いテキストの折り返し | |
set textwidth=80 " 自動的に改行を入れる | |
"set colorcolumn=80 " その代わり80文字目にラインを入れる | |
" 前時代的スクリーンベルを無効化 | |
set t_vb= | |
set novisualbell | |
" デフォルト不可視文字は美しくないのでUnicodeで綺麗に | |
set listchars=tab:»-,trail:-,extends:»,precedes:«,nbsp:%,eol:↲ | |
""""""""" | |
" Macro/Keys | |
""""""""" | |
" 入力モード中に素早くjjと入力した場合はESCとみなす | |
inoremap jj <Esc> | |
" ESCを二回押すことでハイライトを消す | |
nmap <silent> <Esc><Esc> :nohlsearch<CR> | |
" カーソル下の単語を * で検索 | |
vnoremap <silent> * "vy/\V<C-r>=substitute(escape(@v, '\/'), "\n", '\\n', 'g')<CR><CR> | |
" 検索後にジャンプした際に検索単語を画面中央に持ってくる | |
nnoremap n nzz | |
nnoremap N Nzz | |
nnoremap * *zz | |
nnoremap # #zz | |
nnoremap g* g*zz | |
nnoremap g# g#zz | |
" j, k による移動を折り返されたテキストでも自然に振る舞うように変更 | |
nnoremap j gj | |
nnoremap k gk | |
" vを二回で行末まで選択 | |
vnoremap v $h | |
" TABにて対応ペアにジャンプ | |
nnoremap <Tab> % | |
vnoremap <Tab> % | |
" Ctrl + hjkl でウィンドウ間を移動 | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
" Shift + 矢印でウィンドウサイズを変更 | |
nnoremap <S-Left> <C-w><<CR> | |
nnoremap <S-Right> <C-w>><CR> | |
nnoremap <S-Up> <C-w>-<CR> | |
nnoremap <S-Down> <C-w>+<CR> | |
" T + ? で各種設定をトグル | |
nnoremap [toggle] <Nop> | |
nmap T [toggle] | |
nnoremap <silent> [toggle]s :setl spell!<CR>:setl spell?<CR> | |
nnoremap <silent> [toggle]l :setl list!<CR>:setl list?<CR> | |
nnoremap <silent> [toggle]t :setl expandtab!<CR>:setl expandtab?<CR> | |
nnoremap <silent> [toggle]w :setl wrap!<CR>:setl wrap?<CR> | |
" make, grep などのコマンド後に自動的にQuickFixを開く | |
autocmd MyAutoCmd QuickfixCmdPost make,grep,grepadd,vimgrep copen | |
" QuickFixおよびHelpでは q でバッファを閉じる | |
autocmd MyAutoCmd FileType help,qf nnoremap <buffer> q <C-w>c | |
" w!! でスーパーユーザーとして保存(sudoが使える環境限定) | |
cmap w!! w !sudo tee > /dev/null % | |
" :e などでファイルを開く際にフォルダが存在しない場合は自動作成 | |
function! s: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 | |
autocmd MyAutoCmd BufWritePre * call s:mkdir(expand('<afile>:p:h'), v:cmdbang) | |
" vim 起動時のみカレントディレクトリを開いたファイルの親ディレクトリに指定 | |
autocmd MyAutoCmd VimEnter * call s:ChangeCurrentDir('', '') | |
function! s:ChangeCurrentDir(directory, bang) | |
if a:directory == '' | |
lcd %:p:h | |
else | |
execute 'lcd' . a:directory | |
endif | |
if a:bang == '' | |
pwd | |
endif | |
endfunction | |
" ~/.vimrc.localが存在する場合のみ設定を読み込む | |
let s:local_vimrc = expand('~/.vimrc.local') | |
if filereadable(s:local_vimrc) | |
execute 'source ' . s:local_vimrc | |
endif | |
" encoding | |
set fileencoding=utf-8 | |
set fileencodings=utf-8,iso-2022-jp,euc-jp,cp932 | |
set fileformats=unix,dos,mac | |
set encoding=utf-8 | |
" statusline | |
set statusline=%<%f\ %m%r%h%w%y%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%4v\ %l/%L | |
set laststatus=2 | |
" 編集中のファイル名を表示 | |
" 画面の左側に常時''行番''を表示する。 | |
" ルーラーを表示する。 | |
set title | |
" set number | |
set ruler | |
" タブの見掛けの表示幅を4文字分にする。 | |
" オートインデント時に使用するインデントの深さも4文字分にする。 | |
" 自身がタブを入力時した際に、タブの代わりに4文字の半角スペースに置き換える | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 | |
" タブが挿入された文章を編集する場合、タブの代わりに半角スペースに置き換えるようにする。 | |
" 行頭の余白内でTabを打ち込むと'shiftwidth'の数だけインデントする。 | |
set expandtab | |
set smarttab | |
" 高度な自動インデントを行う | |
set smartindent | |
" インクリメンタルサーチ | |
set incsearch | |
" 対括弧の表示 | |
" モード表示 | |
set showmode | |
" コメントを見やすい色へ変更 | |
hi Comment cterm=bold ctermbg=black | |
" 全角スペースを視覚化 | |
highlight ZenkakuSpace cterm=underline ctermfg=lightblue guibg=white | |
match ZenkakuSpace / / | |
autocmd FileType c :set dictionary=~/.vim.d/dics/c-mode | |
autocmd FileType cpp :set dictionary=~/vim.d/dics/c++-mode | |
autocmd FileType java :set dictionary=~/vim.d/dics/java-mode | |
autocmd FileType ruby :set dictionary=~/vim.d/dics/ruby-mode | |
autocmd FileType python :set dictionary=~/vim.d/dics/python-mode | |
" autocmd FileType rcs :set dictionary=~/vim.d/dics/rcs-mode | |
syntax on | |
colorscheme elflord | |
"""""""""" | |
" Neo Bundle | |
"""""""""" | |
let s:noplugin = 0 | |
let s:bundle_root = expand('~/.vim/bundle') | |
let s:neobundle_root = s:bundle_root . '/neobundle.vim' | |
if !isdirectory(s:neobundle_root) || v:version < 702 | |
" NeoBundleが存在しない、もしくはVimのバージョンが古い場合はプラグインを一切 | |
" 読み込まない | |
let s:noplugin = 1 | |
else | |
" NeoBundleを'runtimepath'に追加し初期化を行う | |
if has('vim_starting') | |
execute "set runtimepath+=" . s:neobundle_root | |
endif | |
call neobundle#rc(s:bundle_root) | |
" NeoBundle自身をNeoBundleで管理させる | |
NeoBundleFetch 'Shougo/neobundle.vim' | |
" 非同期通信を可能にする | |
" 'build'が指定されているのでインストール時に自動的に | |
" 指定されたコマンドが実行され vimproc がコンパイルされる | |
NeoBundle "Shougo/vimproc.vim", { | |
\ "build": { | |
\ "windows" : "make -f make_mingw32.mak", | |
\ "cygwin" : "make -f make_cygwin.mak", | |
\ "mac" : "make -f make_mac.mak", | |
\ "unix" : "make -f make_unix.mak", | |
\ }} | |
" NeoBundle "Shougo/neocomplete.vim" | |
" NeoBundle 'Shougo/unite.vim' | |
NeoBundle 'Shougo/vimfiler.vim' | |
" NeoBundle 'Shougo/neosnippet.vim' | |
NeoBundle 'Shougo/neosnippet-snippets' | |
NeoBundle 'Shougo/vimshell.vim' | |
NeoBundle 'thinca/vim-template' | |
NeoBundle 'vim-scripts/YankRing.vim' | |
NeoBundle 'flazz/vim-colorschemes' | |
" NeoBundle 'git://github.com/tpope/vim-surround.git' | |
" NeoBundle 'git://github.com/tpope/vim-repeat.git' | |
" " NeoBundle 'git://github.com/Shougo/neocomplcache.git' | |
" " NeoBundle 'git://github.com/Shougo/neocomplcache-snippets-complete.git' | |
" NeoBundle 'git://github.com/Shougo/vimproc.git' | |
" NeoBundle 'git://github.com/Shougo/vimshell.git' | |
" NeoBundle 'git://github.com/thinca/vim-quickrun.git' | |
" NeoBundle 'git://github.com/mattn/zencoding-vim.git' | |
" NeoBundle 'git://github.com/c9s/perlomni.vim.git' | |
" NeoBundle 'git://github.com/altercation/vim-colors-solarized.git' | |
" NeoBundle 'git://github.com/Lokaltog/vim-powerline.git' | |
" NeoBundle 'git://github.com/scrooloose/syntastic.git' | |
" NeoBundle 'git://github.com/othree/eregex.vim.git' | |
" NeoBundle 'L9' | |
" NeoBundle 'FuzzyFinder' | |
" NeoBundle 'QuickBuf' | |
" NeoBundle 'git://github.com/thinca/vim-ref.git' | |
" インストールされていないプラグインのチェックおよびダウンロード | |
NeoBundleCheck | |
endif | |
" ファイルタイププラグインおよびインデントを有効化 | |
" これはNeoBundleによる処理が終了したあとに呼ばなければならない | |
filetype plugin indent on | |
" if has('lua') && v:version > 703 && has('patch825') | |
" if has('lua') && v:version >= 703 && has('patch825') | |
if has('lua') && v:version >= 703 && has('patch885') | |
NeoBundleLazy "Shougo/neocomplete.vim", { | |
\ "autoload": { | |
\ "insert": 1, | |
\ }} | |
" 2013-07-03 14:30 NeoComplCacheに合わせた | |
let g:neocomplete#enable_at_startup = 1 | |
let s:hooks = neobundle#get_hooks("neocomplete.vim") | |
function! s:hooks.on_source(bundle) | |
let g:acp_enableAtStartup = 0 | |
let g:neocomplet#enable_smart_case = 1 | |
" NeoCompleteを有効化 | |
" NeoCompleteEnable | |
endfunction | |
else | |
NeoBundleLazy "Shougo/neocomplcache.vim", { | |
\ "autoload": { | |
\ "insert": 1, | |
\ }} | |
let g:neocomplcache_enable_at_startup = 1 | |
let s:hooks = neobundle#get_hooks("neocomplcache.vim") | |
function! s:hooks.on_source(bundle) | |
let g:acp_enableAtStartup = 0 | |
let g:neocomplcache_enable_smart_case = 1 | |
" NeoComplCacheを有効化 | |
" NeoComplCacheEnable | |
endfunction | |
endif | |
"""""""""" | |
" VIM-TEMPLATE | |
"""""""""" | |
" テンプレート中に含まれる特定文字列を置き換える | |
autocmd MyAutoCmd User plugin-template-loaded call s:template_keywords() | |
function! s:template_keywords() | |
silent! %s/<+DATE+>/\=strftime('%Y-%m-%d')/g | |
silent! %s/<+FILENAME+>/\=expand('%:r')/g | |
endfunction | |
" テンプレート中に含まれる'<+CURSOR+>'にカーソルを移動 | |
autocmd MyAutoCmd User plugin-template-loaded | |
\ if search('<+CURSOR+>') | |
\ | silent! execute 'normal! "_da>' | |
\ | endif | |
"""""""""" | |
" Unite | |
"""""""""" | |
NeoBundleLazy "Shougo/unite.vim", { | |
\ "autoload": { | |
\ "commands": ["Unite", "UniteWithBufferDir"] | |
\ }} | |
nnoremap [unite] <Nop> | |
nmap U [unite] | |
nnoremap <silent> [unite]f :<C-u>UniteWithBufferDir -buffer-name=files file<CR> | |
nnoremap <silent> [unite]b :<C-u>Unite buffer<CR> | |
nnoremap <silent> [unite]r :<C-u>Unite register<CR> | |
nnoremap <silent> [unite]m :<C-u>Unite file_mru<CR> | |
nnoremap <silent> [unite]c :<C-u>Unite bookmark<CR> | |
nnoremap <silent> [unite]o :<C-u>Unite outline<CR> | |
nnoremap <silent> [unite]t :<C-u>Unite tab<CR> | |
nnoremap <silent> [unite]w :<C-u>Unite window<CR> | |
let s:hooks = neobundle#get_hooks("unite.vim") | |
function! s:hooks.on_source(bundle) | |
" start unite in insert mode | |
let g:unite_enable_start_insert = 1 | |
" use vimfiler to open directory | |
call unite#custom_default_action("source/bookmark/directory", "vimfiler") | |
call unite#custom_default_action("directory", "vimfiler") | |
call unite#custom_default_action("directory_mru", "vimfiler") | |
autocmd MyAutoCmd FileType unite call s:unite_settings() | |
function! s:unite_settings() | |
imap <buffer> <Esc><Esc> <Plug>(unite_exit) | |
nmap <buffer> <Esc> <Plug>(unite_exit) | |
nmap <buffer> <C-n> <Plug>(unite_select_next_line) | |
nmap <buffer> <C-p> <Plug>(unite_select_previous_line) | |
endfunction | |
endfunction | |
"""""""""" | |
" vimfiler | |
"""""""""" | |
NeoBundleLazy "Shougo/vimfiler", { | |
\ "depends": ["Shougo/unite.vim"], | |
\ "autoload": { | |
\ "commands": ["VimFilerTab", "VimFiler", "VimFilerExplorer"], | |
\ "mappings": ['<Plug>(vimfiler_switch)'], | |
\ "explorer": 1, | |
\ }} | |
nnoremap <Leader>e :VimFilerExplorer<CR> | |
" close vimfiler automatically when there are only vimfiler open | |
autocmd MyAutoCmd BufEnter * if (winnr('$') == 1 && &filetype ==# 'vimfiler') | q | endif | |
let s:hooks = neobundle#get_hooks("vimfiler") | |
function! s:hooks.on_source(bundle) | |
let g:vimfiler_as_default_explorer = 1 | |
let g:vimfiler_enable_auto_cd = 1 | |
let g:vimfiler_ignore_pattern = "\%(^\..*\|\.pyc$\)" | |
" vimfiler specific key mappings | |
autocmd MyAutoCmd FileType vimfiler call s:vimfiler_settings() | |
function! s:vimfiler_settings() | |
" ^^ to go up | |
nmap <buffer> ^^ <Plug>(vimfiler_switch_to_parent_directory) | |
" use R to refresh | |
nmap <buffer> R <Plug>(vimfiler_redraw_screen) | |
" overwrite C-l | |
nmap <buffer> <C-l> <C-w>l | |
endfunction | |
endfunction | |
"""""""""" | |
" snippets | |
"""""""""" | |
NeoBundleLazy "Shougo/neosnippet.vim", { | |
\ "depends": ["honza/vim-snippets"], | |
\ "autoload": { | |
\ "insert": 1, | |
\ }} | |
let s:hooks = neobundle#get_hooks("neosnippet.vim") | |
function! s:hooks.on_source(bundle) | |
" Plugin key-mappings. | |
imap <C-k> <Plug>(neosnippet_expand_or_jump) | |
smap <C-k> <Plug>(neosnippet_expand_or_jump) | |
xmap <C-k> <Plug>(neosnippet_expand_target) | |
" SuperTab like snippets behavior. | |
imap <expr><TAB> neosnippet#expandable_or_jumpable() ? | |
\ "\<Plug>(neosnippet_expand_or_jump)" | |
\: pumvisible() ? "\<C-n>" : "\<TAB>" | |
smap <expr><TAB> neosnippet#expandable_or_jumpable() ? | |
\ "\<Plug>(neosnippet_expand_or_jump)" | |
\: "\<TAB>" | |
" For snippet_complete marker. | |
if has('conceal') | |
set conceallevel=2 concealcursor=i | |
endif | |
" Enable snipMate compatibility feature. | |
let g:neosnippet#enable_snipmate_compatibility = 1 | |
" Tell Neosnippet about the other snippets | |
let g:neosnippet#snippets_directory=s:bundle_root . '/vim-snippets/snippets' | |
endfunction | |
"""""""""" | |
" vim-django-support | |
"""""""""" | |
" Djangoを正しくVimで読み込めるようにする | |
NeoBundleLazy "lambdalisue/vim-django-support", { | |
\ "autoload": { | |
\ "filetypes": ["python", "python3", "djangohtml"] | |
\ }} | |
"""""""""" | |
" vim-virtualenv | |
"""""""""" | |
" Vimで正しくvirtualenvを処理できるようにする | |
NeoBundleLazy "jmcantrell/vim-virtualenv", { | |
\ "autoload": { | |
\ "filetypes": ["python", "python3", "djangohtml"] | |
\ }} | |
"""""""""" | |
" jedi-vim | |
"""""""""" | |
NeoBundleLazy "davidhalter/jedi-vim", { | |
\ "autoload": { | |
\ "filetypes": ["python", "python3", "djangohtml"], | |
\ }, | |
\ "build": { | |
\ "mac": "pip install jedi", | |
\ "unix": "pip install jedi", | |
\ }} | |
let s:hooks = neobundle#get_hooks("jedi-vim") | |
function! s:hooks.on_source(bundle) | |
" jediにvimの設定を任せると'completeopt+=preview'するので | |
" 自動設定機能をOFFにし手動で設定を行う | |
let g:jedi#auto_vim_configuration = 0 | |
" 補完の最初の項目が選択された状態だと使いにくいためオフにする | |
let g:jedi#popup_select_first = 0 | |
" dotを入れても有効にならない | |
let g:jedi#popup_on_dot = 0 | |
" quickrunと被るため大文字に変更 | |
let g:jedi#rename_command = '<Leader>R' | |
let g:jedi#goto_assignments_command = '<Leader>G' | |
let g:jedi#documentation_command = "K" | |
let g:jedi#show_call_signatures = "1" | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment