Skip to content

Instantly share code, notes, and snippets.

@kcrt
Last active December 20, 2015 11:09
Show Gist options
  • Save kcrt/6121681 to your computer and use it in GitHub Desktop.
Save kcrt/6121681 to your computer and use it in GitHub Desktop.
" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"
" .vimrc
" kcrt http://profile.kcrt.net
"
" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
scriptencoding utf-8
set nocompatible " 拡張機能を有効にする
" ----- 最初から入ってる奴 -----------------------
syntax on
filetype plugin indent on
augroup vimrcEx
autocmd!
" 開いたらとりあえず前のカーソルの位置へ
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" ===== システムに関する設定 =====================
if has("win32")
let $HOME="d:\\kt"
endif
" ===== ユーザーインターフェース関係 =============
" ----- 設定 -------------------------------------
set backspace=2 " <BS>の動作設定
set history=50 " :コマンドの履歴数
set showcmd " コマンド表示
set laststatus=2 " 最下部情報行の行数
set statusline=%h%w%f\ %m%#RO#%r%#StatusLine#%y%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%4v\ %l/%L\ (%p%%)
set hlsearch " 検索時ハイライト有効
" ----- マウス -----------------------------------
if stridx(&term, "screen") != -1
set mouse=a " マウス有効
set ttymouse=xterm2
endif
" ----- タブインターフェース(またはバッファ) -----
map Q gq
" C-Tabでタブが使えるときはタブを切り替え
" 使えない場合はバッファの切り替えを行う
if(exists(":tab"))
nmap <C-Tab> :tabn<CR>
nmap <C-S-Tab> :tabprev<CR>
else
nmap <C-Tab> :bn<CR>
nmap <C-S-Tab> :bp<CR>
endif
"C-→とC-←をC-Tab, C-S-Tabと同様の操作にする
nmap  <C-Tab>
nmap  <C-S-Tab>
" タブラインの表記
set tabline=%!MyTabLine() "後述
set showtabline=2 " 常にタブを表示
" ----- コマンド略記------------------------------
ca man help
" ----- 補完 -------------------------------------
set complete =.,w,k,b,u,t,i
set wildmode=list,full
if (exists('*pumvisible') && has("gui"))
inoremap <expr> <CR> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
inoremap <expr> <Esc> pumvisible() ? "\<C-E>":"\<Esc>"
endif
" C-Spaceに対してomniが使用可能なら使う、無理なら通常の<C-N>
" 一部の環境ではCtrl+Spaceが<Nul>として入力される
if (exists('&omnifunc'))
imap <C-Space> <C-X><C-O>
imap <Nul> <C-X><C-O>
iabbrev </ </<C-X><C-O>
else
imap <C-Space> <C-N>
imap <Nul> <C-N>
endif
" ----- キーの動作に関する設定 -------------------
set whichwrap=[,],>,<,b,s " 行末でLeft/Right 押しても次の行へ
" ----- その他のキー設定 -------------------------
map <F1> K
map K \K
inoremap jj <ESC>jj
nnoremap <UP> gk
nnoremap <DOWN> gj
inoremap <UP> gk
inoremap <DOWN> gj
nnoremap :w :w<CR>:echoe "File saved, but your input method manager is ON!"<CR>
" ===== 編集に関連する設定 =======================
" ----- 文字エンコードの設定 ---------------------
set fileencodings=utf-8,shift_jis,euc-jp
set fileencoding=utf-8 " デフォルトのファイルエンコーディング
set ambiwidth=double " 幅未定義MBSCの幅
" テスト用: abcdabcdαβγδ・○◎×本日は晴天なり
" ----- 親切設定 ---------------------------------
set showmatch " 対応する括弧を強調表示
set display=lastline " @@@表示
" テスト用: Formerly most Japanese houses were made of wood. You look pale. What is the matter with you? I've got a pain in my stomach. That's too bad. The riches are not always happier than the poor.
" ----- 検索 -------------------------------------
set incsearch " インクリメンタルサーチ
set ignorecase " 検索時大文字・小文字無効
set smartcase " 検索時大文字・小文字自動判別
" 見つかったアイテムを自動的に中央に
nmap n nzz
nmap N Nzz
" ----- タブとインデント -------------------------
set tabstop=4 " <Tab>に対応する空白数
set shiftwidth=4 " インデントに使われる空白数
set softtabstop=4 " タブとして使われる空白数
set autoindent " 自動インデント
set smartindent " スマートインデント
" ===== 動作設定 =================================
" ----- バックアップ -----------------------------
set backup " バックアップ有効
if has("win32")
set backupdir& backupdir=$HOME/Backup
else
set backupdir& backupdir=$HOME/.backup
endif
" crontab はbackup無効にする。
autocmd BufRead /tmp/crontab.* :set nobackup nowritebackup
" ----- クリップボード ---------------------------
nnoremap x "_x
imap <C-R>* <C-O>"*p
nmap "*yy V"*y
if has("win32unix") " cygwinの事です
nnoremap "*p :r!getclip<CR>
vnoremap "*y :!putclip<CR>u:echo 'copyed'<CR>
imap  <BS>
elseif has("unix")
if $TERM=~"screen.*"
nnoremap "*p i<C-O>:!screen -X paste .<CR>
vnoremap "*y :w! ~/tmp/vim-clipboard<CR>:!screen -X readbuf ~/tmp/vim-clipboard<CR>:echo 'copyed'<CR>
else
nnoremap "*p :r ~/tmp/vim-clipboard<CR>
vnoremap "*y :w! ~/tmp/vim-clipboard<CR>:echo 'copyed'<CR>
endif
endif
" ----- screen関係の設定 -------------------------
if &term =~ "screen.*"
augroup IsTerminal
autocmd!
autocmd VimLeave * silent! exe '!echo -n "k' . &shell . '\\"'
autocmd BufEnter * silent! exe '!echo -n "k' . "vim:%:t" . '\\"'
augroup END
endif
" ===== 印刷設定 =================================
" set printfont="ヒラギノ" -> gvimrc
" ===== ファイル関連設定 =========================
" ----- テンプレート -----------------------------
augroup LoadTemplate
autocmd!
let templatefiles = split(glob('~/etc/template/*'), '\n')
for filename in templatefiles
let f = matchlist(filename, '.*\.\(.*\)')
let ext = f[1]
execute 'autocmd BufNewFile *.' . ext . ' 0r ~/etc/template/template.' . ext
endfor
augroup END
" ----- ファイル別設定 ---------------------------
augroup filetypedetect
"autocmd! こいつだけは上書きできない
autocmd BufNewFile,BufRead *.txt :setf txt
autocmd BufNewFile,BufReadPre *.howm :set fileformats=dos,unix
autocmd BufNewFile,BufReadPost *.pl :set filetype=perl
autocmd BufNewFile,BufReadPost *.pm :set filetype=perl
autocmd BufNewFile,BufReadPost *.ctp :set filetype=php
autocmd BufNewFile,BufReadPost *.r :set filetype=r
" F5で実行
autocmd BufNewFile,BufRead *.pl :map <F5> :!perl %:p<CR>
autocmd BufNewFile,BufRead *.pm :map <F5> :!perl %:p<CR>
autocmd BufNewFile,BufRead *.php :map <F5> :!php %:p<CR>
autocmd BufNewFile,BufRead *.tex :map <F5> :call PreviewTeX()<CR>
autocmd BufNewFile,BufRead *.cpp :map <F5> :!g++ %:p<CR>
autocmd BufNewFile,BufRead *.sh :map <F5> :! %:p<CR>
autocmd BufNewFile,BufRead .vimrc :map <F5> :source %:p<CR>
" F7 で構文チェックとか
autocmd BufNewFile,BufRead *.pl :map <F7> :!perl -cw%:p<CR>
" 折りたたまれないように
autocmd FileType git :setlocal foldlevel=99
augroup END
let php_baselib = 1
let php_htmlInString = 1
let php_folding = 1
" ----- 暗号化 -----------------------------------
if version >= 703
set cryptmethod=blowfish
endif
" ----- バイナリファイル編集 ---------------------
" see :help xxd
augroup Binary
au!
autocmd BufReadPost * if &binary | exe ":%!xxd -g 1" | set ft=xxd | endif
autocmd BufWritePre * if &binary | exe ":%!xxd -r" | endif
autocmd BufWritePost * if &binary | exe ":%!xxd -g 1" | set nomod | endif
augroup END
" ===== プラグイン設定 ===========================
" ----- Vundle -----------------------------------
set rtp+=~/.vim/vundle.git/
call vundle#rc()
Bundle 'Shougo/neocomplcache'
Bundle 'Align'
Bundle 'tpope/vim-fugitive'
Bundle 'gitv'
Bundle 'sudo.vim'
Bundle 'basyura/jslint.vim'
Bundle 'gregsexton/MatchTag'
Bundle 'mattn/zencoding-vim'
Bundle 'scrooloose/syntastic'
Bundle 'thinca/vim-quickrun'
Bundle 'tpope/vim-surround'
Bundle 'teramako/jscomplete-vim'
Bundle 'w0ng/vim-hybrid'
" ----- neocomplcache ----------------------------
let g:neocomplcache_enable_at_startup = 1
let g:neocomplcache_auto_completion_start_length = 3
" ----- QuickRun and Syntastic -------------------
" use clang and C++11 for default, if available
if executable("clang++")
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = '--std=c++11 --stdlib=libc++'
let g:quickrun_config = {}
let g:quickrun_config['cpp/clang++11'] = {'cmdopt': '-O --std=c++11 --stdlib=libc++', 'type': 'cpp/clang++'}
let g:quickrun_config['cpp'] = {'type': 'cpp/clang++11'}
endif
" ----- その他のプラグイン -----------------------
runtime ftplugin/man.vim
let g:jscomplete_use = ['dom', 'moz', 'es6th']
autocmd FileType javascript :setl omnifunc=jscomplete#CompleteJS
" ===== 色設定 ===================================
set t_Co=16
if has("gui")
" gui
endif
colorscheme desert
colorscheme hybrid " あればこっちを優先(これだけだとCUIの色が変わらない)
" ----- 色の宣言(上書き) -------------------------
hi StatusLine guibg=#4242ff guifg=white gui=bold ctermfg=darkblue ctermbg=white cterm=reverse,bold
hi Title guibg=lightblue guifg=white ctermbg=lightblue ctermfg=white gui=bold
hi Comment ctermfg=darkgreen guifg=lightgreen
hi Statement guifg=lightyellow
hi Type ctermfg=blue guifg=lightcyan
hi Label ctermbg=darkyellow ctermfg=white guifg=#eeee55 guibg=#333300
hi Pmenu ctermbg=darkgray ctermfg=white guibg=darkgray guifg=white
hi PmenuSel ctermbg=lightblue ctermfg=white guibg=lightblue guifg=white
hi PmenuSbar ctermbg=darkgray ctermfg=lightgray guibg=darkgray guifg=lightgray
hi PmenuThumb ctermbg=darkgray ctermfg=lightgray guibg=darkgray guifg=lightgray
hi TabLine ctermbg=black ctermfg=gray gui=bold term=bold
hi TabLineFill ctermbg=darkgray ctermfg=black gui=underline
hi TabLineSel ctermbg=blue ctermfg=white
hi Search ctermbg=red ctermfg=black
hi LineNr guifg=#555555
hi DiffDelete ctermbg=DarkMagenta ctermfg=white
" ----- 色の宣言(オリジナル) ---------------------
hi Label ctermfg=black ctermbg=darkyellow
hi Label2 guifg=#e0b611 ctermfg=yellow
hi Label3 guifg=#b08d33 ctermfg=darkyellow
hi Bold gui=bold
hi Italic gui=italic
hi Striken guifg=#dddddd ctermfg=gray
hi HR guifg=gray ctermfg=darkgray
hi SuperHR guifg=lightgray guibg=darkcyan gui=italic ctermfg=lightgray ctermbg=blue
hi Citation guibg=#222200 guifg=lightyellow ctermbg=darkyellow ctermfg=black
hi TabCloseBox ctermbg=darkred ctermfg=white
hi RO ctermbg=red ctermfg=white guifg=white guibg=magenta
hi SpaceEnd ctermbg=red ctermfg=white guifg=white guibg=magenta
hi ZenkakuSpace ctermbg=darkgray guibg=#333333
" ----- 文法定義(見出し) -------------------------
au Syntax * syntax match Label display "^\* .*"
au Syntax * syntax match Label2 display "\t\* .*"
au Syntax * syntax match Label3 display "\t\t\* .*"
au Syntax * syntax match Label2 display "^[\t  ]*[・□■○●][^・].*"
au Syntax * syntax match Label display "^[・□■○●][^・].*"
au Syntax * syntax match Label2 display "^[\t  ]*\*\* .*"
au Syntax * syntax match Label3 display "^[\t  ]*\*\*\* .*"
au Syntax * syntax match Label display "^【.*】"
" au Syntax * syntax match HR display ".*-----.*"
au Syntax * syntax match SuperHR display ".*=====.*"
" ----- 文法定義(ハイライト) ---------------------
match Bold /\*\*.*\*\*/
match Italic /__.*__/
syntax region Citation start=".*>>>" end="<<<"
match ZenkakuSpace / /
" テスト用 **abc** __def__    a
" >>> This is citation <<<
" ===== 以下、関数 ===============================
" ----- タブライン -------------------------------
function! MyTabLine()
let s = ''
let tabname=''
for i in range(tabpagenr('$'))
let tabname=(i+1) . ':' . bufname(tabpagebuflist(i+1)[tabpagewinnr(i+1) -1])
let tabname=substitute(tabname, $HOME, "~", 1)
let tabname=substitute(tabname, $VIMRUNTIME, "(vim)", 1)
let s .= '%' . (i + 1) . 'T' "マウスクリック用
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#/ ' . tabname . ' %#TabCloseBox#%999X[X]%X%#TabLineSel# \'
else
let s .= '%#TabLine#/ ' . tabname . ' %' . (i+1) . 'X[X]%X \'
endif
endfor
let s .= '%#TabLineFill#%T%=Vi IMproved ver.'
let s .= version / 100 . '.' . strpart(version, strlen(version)-2, 2)
return s
endfunction
function! PreviewTeX()
cd %:h
exec "!platex --shell-escape-commands=extractbb '" . expand("%:p") . "'"
exec "silent !dvipdfmx '" . expand("%:p:r") . ".dvi'"
exec "silent !rm '" . expand("%:p:r") . ".dvi'"
exec "silent !rm '" . expand("%:p:r") . ".log'"
exec "silent !rm '" . expand("%:p:r") . ".aux'"
exec "silent !mv '" . expand("%:p:r") . ".pdf' ~/tmp/"
exec "silent !open \"" . expand("$HOME") . "/tmp/" . expand("%:r") . ".pdf\""
endfunction
function! CharCount() range
let l:count = a:firstline
let l:linestr = ""
let l:linecount = 0
let l:halfwidth = 0
let l:fullwidth = 0
while l:count <= a:lastline
let l:linestr = getline(l:count)
let l:linecount += 1
let l:strchars = strchars(l:linestr) " あ = a = 1
let l:strwidth = strwidth(l:linestr) " あ = 2, a = 1
let l:fullwidth += (l:strwidth - l:strchars)
let l:halfwidth += (l:strchars * 2 - l:strwidth)
let l:count += 1
" echo l:count . ": (" . l:fullwidth . ", " . l:halfwidth . ") " . l:linestr
endwhile
let l:msg = "** 文字数カウント **\n"
let l:msg .= " 行数: " . l:linecount . "\n"
let l:msg .= " 文字数: " . (l:halfwidth + l:fullwidth) . "\n"
let l:msg .= " 文字数(全角を2文字と換算): " . (l:halfwidth + l:fullwidth * 2) . "\n"
let l:msg .= " 文字数(全角を1文字と換算): " . printf("%g", l:halfwidth / 2.0 + l:fullwidth) . "\n"
let l:msg .= " 半角: " . l:halfwidth . "\n"
let l:msg .= " 全角: " . l:fullwidth . "\n"
echo l:msg
endfunction
command! -range=% CharCount :<line1>,<line2>call CharCount()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment