Created
July 9, 2020 02:42
-
-
Save nagae/6581016e48eb13c5d792b0bddf70471a 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
"set nocompatible | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'VundleVim/Vundle.vim' | |
" 導入したいプラグインを以下に列挙 | |
" Plugin '[Github Author]/[Github repo]' の形式で記入 | |
Plugin 'airblade/vim-gitgutter' | |
Plugin 'kien/ctrlp.vim' | |
Plugin 'lervag/vimtex' | |
Plugin 'altercation/vim-colors-solarized' | |
Plugin 'tpope/vim-fugitive' | |
Plugin 'osyo-manga/vim-over' | |
Plugin 'LeafCage/yankround.vim' | |
Plugin 'terryma/vim-expand-region' | |
Plugin 'universal-ctags/ctags' | |
Plugin 'itchyny/lightline.vim' | |
Plugin 'iamcco/markdown-preview.vim' | |
Plugin 'previm/previm' | |
Plugin 'plasticboy/vim-markdown' | |
Plugin 'dhruvasagar/vim-table-mode' | |
Plugin 'xuhdev/vim-latex-live-preview' | |
Plugin 'cocopon/vaffle.vim' | |
Plugin 'fuenor/qfixhowm' | |
Plugin 'vim-pandoc/vim-pandoc' | |
Plugin 'vim-pandoc/vim-pandoc-syntax' | |
call vundle#end() | |
filetype plugin indent on | |
" setting | |
" Leader をSpaceキーにする | |
" https://postd.cc/how-to-boost-your-vim-productivity/ | |
let mapleader = "\<Space>" | |
"文字コードをUFT-8に設定 | |
set fenc=utf-8 | |
" バックアップファイルを作らない | |
set nobackup | |
" スワップファイルを作らない | |
set noswapfile | |
" 編集中のファイルが変更されたら自動で読み直す | |
set autoread | |
" バッファが編集中でもその他のファイルを開けるように | |
set hidden | |
" 入力中のコマンドをステータスに表示する | |
set showcmd | |
" 見た目系 | |
" 行番号を表示 | |
set number | |
" 現在の行を強調表示 | |
set cursorline | |
" 現在の行を強調表示(縦) | |
"set cursorcolumn | |
" 行末の1文字先までカーソルを移動できるように | |
set virtualedit=onemore | |
" インデントはスマートインデント | |
set smartindent | |
" ビープ音を可視化 | |
set visualbell | |
" 括弧入力時の対応する括弧を表示 | |
set showmatch | |
" ステータスラインを常に表示 | |
set laststatus=2 | |
" コマンドラインの補完 | |
set wildmode=list:longest | |
" 折り返し時に表示行単位での移動できるようにする | |
nnoremap j gj | |
nnoremap k gk | |
" シンタックスハイライトの有効化 | |
syntax enable | |
" Tab系 | |
" 不可視文字を可視化(タブが「▸-」と表示される) | |
set list listchars=tab:\▸\- | |
" Tab文字を半角スペースにする | |
set expandtab | |
" 行頭以外のTab文字の表示幅(スペースいくつ分) | |
set tabstop=2 | |
" 行頭でのTab文字の表示幅 | |
set shiftwidth=2 | |
" スマートタブ(行頭の前で <Tab> を押した時, 'shiftwidth' 分のスペースが挿入される) | |
set smarttab | |
" 検索系 | |
" 検索文字列が小文字の場合は大文字小文字を区別なく検索する | |
set ignorecase | |
" 検索文字列に大文字が含まれている場合は区別して検索する | |
set smartcase | |
" 検索文字列入力時に順次対象文字列にヒットさせる | |
set incsearch | |
" 検索時に最後まで行ったら最初に戻る | |
set wrapscan | |
" 検索語をハイライト表示 | |
set hlsearch | |
" ESC連打でハイライト解除 | |
nmap <silent><Esc><Esc> :nohlsearch<cr> | |
" バックスペースでインデントや改行を削除できるようにする | |
set backspace=indent,eol,start | |
" コマンドライン補完時に強化されたものを使う(参照 :help wildmenu) | |
set wildmenu | |
" テキスト挿入中の自動折り返しを日本語に対応させる | |
set formatoptions+=mM | |
" スペルチェックを有効にする(ただし日本語は除外する) | |
set spelllang+=cjk | |
set spell | |
" | |
"#####キーリマップ | |
nnoremap / /\v | |
"nnoremap <silent><C-s> :NERDTreeToggle<CR> | |
"map <leader>r :NERDTreeFind<cr> | |
map <silent><C-e> :Explore<cr> | |
nnoremap <silent><leader>. :bnext<CR> | |
nnoremap <silent><leader>, :bprev<CR> | |
nnoremap <silent><Leader>w :w<CR> | |
vmap v <Plug>(expand_region_expand) | |
vmap <C-v> <Plug>(expand_region_shrink) | |
inoremap <C-j> <Nop> | |
"#### previm | |
let g:previm_open_cmd = 'open -a "Google Chrome"' | |
"#### vim-markdown | |
let g:vim_markdown_conceal = 0 | |
"#### vim-table-mode | |
let g:table_mode_corner = '|' | |
"##### QFixHowm | |
let QFixHowm_Key = 'g' | |
let howm_dir = "~/Dropbox/howm/" | |
" ファイル拡張子をmkdにする | |
let howm_filename = '%Y/%m/%Y-%m-%d-%H%M%S.mkd' | |
" ファイルタイプをmarkdownにする | |
let QFixHowm_FileType = 'markdown' | |
" タイトル記号 | |
let QFixHowm_Title = '#' | |
"##### tex | |
"let g:vimtex_compiler_latexmk_engines = { '_' : '-pdfdvi' } | |
let g:vimtex_compiler_latexmk = { | |
\ 'background': 1, | |
\ 'build_dir': '', | |
\ 'continuous': 1, | |
\ 'options': [ | |
\ '-pdfdvi', | |
\ '-verbose', | |
\ '-file-line-error', | |
\ '-synctex=1', | |
\ '-interaction=nonstopmode', | |
\], | |
\} | |
let g:vimtex_enabled=1 | |
let g:vimtex_view_general_viewer | |
\ = '/Applications/Skim.app/Contents/SharedSupport/displayline' | |
let g:vimtex_view_general_options = '@line @pdf @tex' | |
"#### | |
" https://sites.google.com/site/fudist/Home/vim-nihongo-ban/tips/vim-key-emacs?tmpl=%2Fsystem%2Fapp%2Ftemplates%2Fprint%2F&showPrintDialog=1 | |
""カーソル一文字単位移動 | |
inoremap <silent> <C-b> <Left> | |
inoremap <silent> <C-f> <Right> | |
"単語単位移動(行末で止めたい場合) | |
"inoremap <silent> <C-f> <C-r>=MyMoveWord_i('w')<CR> | |
"inoremap <silent> <C-b> <C-r>=MyMoveWord_i('b')<CR> | |
"単語単位移動(行末で止まる必要がない場合) | |
"inoremap <silent> <C-b> <S-Left> | |
"inoremap <silent> <C-f> <S-Right> | |
"非補完時は行移動をj,kと同じ動作にして補完中は候補選択 | |
inoremap <silent> <expr> <C-p> pumvisible() ? "\<C-p>" : "<C-r>=MyExecExCommand('normal k')<CR>" | |
inoremap <silent> <expr> <C-n> pumvisible() ? "\<C-n>" : "<C-r>=MyExecExCommand('normal j')<CR>" | |
inoremap <silent> <expr> <Up> pumvisible() ? "\<C-p>" : "<C-r>=MyExecExCommand('normal k')<CR>" | |
inoremap <silent> <expr> <Down> pumvisible() ? "\<C-n>" : "<C-r>=MyExecExCommand('normal j')<CR>" | |
"行頭へ | |
inoremap <silent> <C-a> <C-r>=MyJumptoBol(' 。、.,/!?「」')<CR> | |
"行末へ | |
inoremap <silent> <C-e> <C-r>=MyJumptoEol(' 。、.,/!?「」')<CR> | |
"カーソル前の文字削除 | |
inoremap <silent> <BS> <C-g>u<BS> | |
inoremap <silent> <C-h> <C-g>u<C-h> | |
"カーソル後の文字削除 | |
inoremap <silent> <Del> <C-g>u<Del> | |
inoremap <silent> <C-d> <C-g>u<Del> | |
"カーソル位置から前の単語を削除 | |
"inoremap <silent> <C-w> <C-g>u<C-r>=MyExecExCommand('normal! db')<CR> | |
"カーソル位置から後の単語を削除 | |
"inoremap <silent> <C-t> <C-g>u<C-r>=MyDeleteWord()<CR> | |
"カーソル位置から行末まで削除 | |
inoremap <silent> <C-k> <C-o>D | |
"最後に挿入した文字列を挿入 | |
inoremap <silent> <C-z> <C-g>u<C-a> | |
"現在行をインデント | |
inoremap <silent> <Tab> <C-g>u<C-t> | |
inoremap <silent> <S-Tab> <C-g>u<C-d> | |
"undo | |
inoremap <silent> <C-u> <C-g>u<C-r>=MyExecExCommand('undo', 'onemore')<CR> | |
"2ストロークキー使用 | |
if 1 | |
"カーソル以降削除 | |
inoremap <silent> <C-k><C-k> <C-g>u<C-r>=MyExecExCommand('normal! D', 'onemore')<CR> | |
"redo | |
inoremap <silent> <C-k><C-r> <C-r>=MyExecExCommand('redo', 'onemore')<CR> | |
"行連結 | |
inoremap <silent> <C-k><C-j> <C-g>u<C-r>=MyExecExCommand('normal! J')<CR> | |
"新行挿入 | |
inoremap <silent> <C-k><C-n> <C-g>u<C-r>=MyExecExCommand("call cursor(line('.'), col('$'))")<CR><CR> | |
endif | |
"メタ(alt)キー使用 | |
if 0 | |
"カーソル以降削除 | |
inoremap <silent> <C-k> <C-g>u<C-r>=MyExecExCommand('normal! D', 'onemore')<CR> | |
"リドゥ | |
inoremap <silent> <M-r> <C-r>=MyExecExCommand('redo', 'onemore')<CR> | |
"行連結 | |
inoremap <silent> <M-j> <C-g>u<C-r>=MyExecExCommand('normal! J')<CR> | |
"新行挿入 | |
inoremap <silent> <M-n> <C-g>u<C-r>=MyExecExCommand("call cursor(line('.'), col('$'))")<CR><CR> | |
endif | |
"""""""""""""""""""""""""""""" | |
"sepが空でなければ、sepをセパレータとしてジャンプ。 | |
"見つからなければ見かけの行頭へ。 | |
"カーソル位置が見かけの行頭の場合は真の行頭へ。 | |
"""""""""""""""""""""""""""""" | |
function! MyJumptoBol(sep) | |
if col('.') == 1 | |
call cursor(line('.')-1, col('$')) | |
call cursor(line('.'), col('$')) | |
return '' | |
endif | |
if matchend(strpart(getline('.'), 0, col('.')), '[[:blank:]]\+') >= col('.')-1 | |
silent exec 'normal! 0' | |
return '' | |
endif | |
if a:sep != '' | |
call search('[^'.a:sep.']\+', 'bW', line(".")) | |
if col('.') == 1 | |
silent exec 'normal! ^' | |
endif | |
return '' | |
endif | |
exec 'normal! ^' | |
return '' | |
endfunction | |
"""""""""""""""""""""""""""""" | |
"sepが空でなければ、sepをセパレータとしてジャンプ。 | |
"見つからなければ行末へ。 | |
"""""""""""""""""""""""""""""" | |
function! MyJumptoEol(sep) | |
if col('.') == col('$') | |
silent exec 'normal! w' | |
return '' | |
endif | |
if a:sep != '' | |
let prevcol = col('.') | |
call search('['.a:sep.']\+[^'.a:sep.']', 'eW', line(".")) | |
if col('.') != prevcol | |
return '' | |
endif | |
endif | |
call cursor(line('.'), col('$')) | |
return '' | |
endfunction | |
"""""""""""""""""""""""""""""" | |
"行末でも停止する単語単位移動コマンド | |
"""""""""""""""""""""""""""""" | |
function! MyMoveWord_i(cmd) | |
let isEol = 0 | |
if col('$') == col('.') | |
let isEol = 1 | |
endif | |
let prevline = line('.') | |
silent exec 'normal! '.a:cmd | |
if line('.') == prevline | |
return '' | |
endif | |
if a:cmd == 'w' | |
if isEol == 0 | |
call cursor(prevline, 0) | |
call cursor(line('.'), col('$')) | |
endif | |
if line('.') - prevline > 1 | |
call cursor(prevline+1, 0) | |
call cursor(line('.'), col('$')) | |
endif | |
elseif a:cmd == 'b' | |
call cursor(line('.'), col('$')) | |
if prevline - line('.') > 1 | |
call cursor(prevline-1, 0) | |
call cursor(line('.'), col('$')) | |
endif | |
endif | |
return '' | |
endfunction | |
"""""""""""""""""""""""""""""" | |
"カーソル以降の単語削除 | |
"""""""""""""""""""""""""""""" | |
function! MyDeleteWord() | |
if col('.') == col('$') | |
return '' | |
endif | |
let save_cursor = getpos('.') | |
silent exec 'normal! wge' | |
if save_cursor[1] != line('.') || (save_cursor[2] > col('.')) | |
call setpos('.', save_cursor) | |
return MyExecExCommand('normal! dw', 'onemore') | |
endif | |
silent exec 'normal! v' | |
call setpos('.', save_cursor) | |
return MyExecExCommand('normal! d') | |
endfunction | |
"""""""""""""""""""""""""""""" | |
"IMEの状態とカーソル位置保存のため<C-r>を使用してコマンドを実行。 | |
"""""""""""""""""""""""""""""" | |
function! MyExecExCommand(cmd, ...) | |
let saved_ve = &virtualedit | |
let index = 1 | |
while index <= a:0 | |
if a:{index} == 'onemore' | |
silent setlocal virtualedit+=onemore | |
endif | |
let index = index + 1 | |
endwhile | |
silent exec a:cmd | |
if a:0 > 0 | |
silent exec 'setlocal virtualedit='.saved_ve | |
endif | |
return '' | |
endfunction | |
" https://qiita.com/syui/items/3a1af1301ee197b32a8a#yankroundvim | |
" yankround.vim {{{ | |
"" キーマップ | |
nmap p <Plug>(yankround-p) | |
nmap P <Plug>(yankround-P) | |
nmap <C-p> <Plug>(yankround-prev) | |
nmap <C-n> <Plug>(yankround-next) | |
"" 履歴取得数 | |
let g:yankround_max_history = 50 | |
""履歴一覧(kien/ctrlp.vim) | |
nnoremap <silent>g<C-p> :<C-u>CtrlPYankRound<CR> | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment