Feed

Kojo Sugita's watching list

  • [1879] autocomplpop.vim

    Comment キーワード等を自動的に補完.便利すぎます.
  • [1984] fuzzyfinder.vim

    Comment ファイルやバッファのインクリメンタルサーチ.適当なキーに割り当てて使ってます.
  • [39] matchit.zip

    Comment %の拡張.HTMLとかTeXを書くときにあると便利です.
  • [741] movewin.vim

    Comment ウィンドウをキーボードから移動.なんとなく使っています.
  • [69] project.tar.gz

    Comment プロジェクトの作成.taglist.vimとの相性が悪いのが気になるところです.
  • [2350] rootwater.vim

    Comment カラースキーマ.自作ですがメインで使っているのでウォッチしておきます.
  • [1318] snippetsEmu

    Comment コードスニペット.自分好みに改良できるのも楽しいです.
  • [1697] surround.vim

    Comment タグやダブルクォートの追加,修正,削除.
  • [273] taglist.vim

    Comment ソース内の関数やメソッドを一覧で表示.ソースを追うときに,これがあるのと無いのでは全然違う気がします.
  • [2027] taskpaper.vim

    Comment Todo管理.
  • [1218] The NERD Commenter

    Comment ファイルタイプに応じたコメントアウト.便利に使っています.
  • [1234] YankRing.vim

    Comment ヤンクの履歴を順番に参照.記憶力が弱いので助かっています.

Profile

Vimをビムと呼んでいたら, 知人から
「ブイアイエムだよ」と言われました.
どっちでもいいと思うんだけどなあ(´・ω・`)

blog
http://drytail.seesaa.net/

HP
http://ctips.web.fc2.com/

.vimrc

" Maintainer: Kojo Sugita<kojo.sugita@gmail.com>
" Latest Revision: 2008-11-20

" {{{ Common setting
"/* --- フォント, 背景色設定 --- */
"背景色
colorscheme rootwater

"フォント設定
if has("unix")
" set guifont=IPAMonaGothic\ 12
" set guifontwide=IPAMonaGothic\ 12
set guifont=Bitstream\ Vera\ Sans\ Mono\ 12
set guifontwide=Bitstream\ Vera\ Sans\ Mono\ 12
set printfont=IPAMonaGothic\ 12
autocmd GUIEnter * winpos 200 100
autocmd GUIEnter * winsize 80 50

elseif has("gui_win32")
" set guifont=HGゴシックM:h11
" set guifontwide=HGゴシックM:h11
set guifont=sazanami_gothic:h10
set guifontwide=sazanami_gothic:h10
set printfont=MS_Gothic:h11:cSHIFTJIS
autocmd GUIEnter * winpos 200 100
autocmd GUIEnter * winsize 100 50
endif

"/* --- 表示 --- */
syntax on "シンタックス有効
set number "行番号を表示
set laststatus=2 "ステータスラインを表示
set showcmd "入力中のコマンドをステータスに表示する
set ruler "現在のカーソル位置を表示
set wrap! = nowrap "折り返ししない
set foldmethod=marker "折りたたみを有効にする

"/* --- 検索設定 --- */
set hlsearch "検索結果文字列のハイライトを有効にする
set ignorecase "大文字小文字を区別なく検索する
set smartcase "検索文字列に大文字が含まれている場合は区別して検索する
set incsearch "インクリメンタルサーチ

"選択範囲内から検索できるようにする
vnoremap <silent> / :<C-U>call RangeSearch('/')<CR>:if strlen(g:srchstr) > 0\|exec '/'.g:srchstr\|endif<CR>
vnoremap <silent> ? :<C-U>call RangeSearch('?')<CR>:if strlen(g:srchstr) > 0\|exec '?'.g:srchstr\|endif<CR>

"/* --- "括弧の設定 --- */
set showmatch "括弧の対応表示

"括弧が入力されたときに自動的に閉じ括弧を入力する
inoremap [ []<LEFT>
inoremap ( ()<LEFT>
inoremap { {}<LEFT>

"/* --- インデント, Tab文字, EOFなどの設定 --- */
set autoindent "自動インデント
set smartindent "自動インデント
set shiftwidth=4 "autoindent時に挿入されるタブの幅
set tabstop=4 "タブ幅の設定
set list "Tab文字や、EOFを表示

"tab文字や、EOLを変更
set lcs=tab:..,eol:<,extends:\

"全角スペース, 行末半角スペースの色変え
if has("syntax")
syntax on
function! ActivateInvisibleIndicator()
"全角スペースを表示
syntax match InvisibleJISX0208Space " " display containedin=ALL
highlight InvisibleJISX0208Space term=underline ctermbg=Blue guibg=#6666ff
"行末の半角スペースを表示
syntax match InvisibleTrailedSpace "[ \t]\+$" display containedin=ALL
highlight InvisibleTrailedSpace term=underline ctermbg=red guibg=#ff6666
endf
augroup invisible
autocmd! invisible
autocmd BufNew,BufRead * call ActivateInvisibleIndicator()
augroup ENDendif
endif

"Smarter Table Editing
map <S-Tab> :call NextField(' \{2,}',2,' ',0)<CR>
imap <S-Tab> <C-O>:call NextField(' \{2,}',2,' ',0)<CR>

"/* --- ヤンクの設定 --- */
"選択した範囲に行番号をつけてレジスタ * にヤンク
vnoremap \y :call YankWithLineNumber()<CR>

"無名レジスタに入るデータを、*レジスタにも入れる。
set clipboard+=unnamed

"/* --- 文字コード --- */
" 文字コードの自動認識(http://www.kawaz.jp/pukiwiki/?vim#g59923b3から頂戴)
if &encoding !=# 'utf-8'
set encoding=japan
set fileencoding=japan
endif
if has('iconv')
let s:enc_euc = 'euc-jp'
let s:enc_jis = 'iso-2022-jp'
" iconvがeucJP-msに対応しているかをチェック
if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'eucjp-ms'
let s:enc_jis = 'iso-2022-jp-3'
" iconvがJISX0213に対応しているかをチェック
elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'euc-jisx0213'
let s:enc_jis = 'iso-2022-jp-3'
endif
" fileencodingsを構築
if &encoding ==# 'utf-8'
let s:fileencodings_default = &fileencodings
let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
let &fileencodings = &fileencodings .','. s:fileencodings_default
unlet s:fileencodings_default
else
let &fileencodings = &fileencodings .','. s:enc_jis
set fileencodings+=utf-8,ucs-2le,ucs-2
if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
set fileencodings+=cp932
set fileencodings-=euc-jp
set fileencodings-=euc-jisx0213
set fileencodings-=eucjp-ms
let &encoding = s:enc_euc
let &fileencoding = s:enc_euc
else
let &fileencodings = &fileencodings .','. s:enc_euc
endif
endif
" 定数を処分
unlet s:enc_euc
unlet s:enc_jis
endif
" 日本語を含まない場合は fileencoding に encoding を使うようにする
if has('autocmd')
function! AU_ReCheck_FENC()
if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
let &fileencoding=&encoding
endif
endfunction
autocmd BufReadPost * call AU_ReCheck_FENC()
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
set ambiwidth=double
endif

"日本語設定
if has('multi_byte_ime') || has('xim')
" 日本語入力ON時のカーソルの色を設定
highlight CursorIM guibg=Red guifg=NONE
endif

"/* --- その他編集 --- */
"表示行単位で移動
noremap j gj
noremap k gk
vnoremap j gj
vnoremap k gk

" インサートモードでバックスペースを押したときの対策
"noremap ^? 
"noremap! ^? 
"noremap 
"noremap! 

"前後移動をEmacsのようなキーバインドにする
inoremap <C-f> <Right>
inoremap  <Right>
inoremap <C-b> <Left>
inoremap  <Left>

"/* --- その他 --- */
filetype plugin on "ファイルタイププラグインを有効にする
set vb t_vb= "ビープ音をならさない
set guioptions=F "GUIオプション
set nobackup "バックアップしない
set autoread "編集されたら読み直す
set wildchar=<Tab> "Tabで補完できるようにする
set nocompatible "VI互換をオフ

"completeを初期化
au FileType * set complete=.,w,b,u,t,i

"<Leader>を\にする
let mapleader = '\'

"連続する空白行を圧縮する
nnoremap <silent> <C-x><C-o> :call DeleteBlankLines()<CR>

".vimrcの再読み込み
if has("unix")
noremap <C-F12> :source ~/.vimrc<CR>
elseif has("gui_win32")
noremap <C-F12> :source $VIM/_gvimrc<CR>
endif

" }}}
" {{{ Programing language
au BufNewFile,BufRead *.bat,*.cmd call DosBatchSettings()
au BufNewFile,BufRead *.vb,*vbs call VBScriptSettings()
au BufNewFile,BufRead *.c,*.h,*.cpp,*.java,*.js,*.pl,*.cgi call CCommonSettings()
au BufNewFile,BufRead *.c,*.h call CSettings()
au BufNewFile,BufRead *.cpp call CppSettings()
au BufNewFile,BufRead *.java call JavaSettings()
au BufNewFile,BufRead *.js call JavaScriptSettings()
au BufNewFile,BufRead *.rb call RubySettings()
au BufNewFile,BufRead *.py call PythonSettings()
au BufNewFile,BufRead *.html,*.htm,*.xhtml,*.xml,*.xsl,*.xslt,*.xul call TagCommonSettings()
au BufNewFile,BufRead *.html,*.htm,*.xhtml call HTMLSettings()
au BufNewFile,BufRead *.css call CssSettings()
au BufNewFile,BufRead *.xml call XmlSettings()
au BufNewFile,BufRead *.xul call XulSettings()
au BufNewFile,BufRead *.php call PHPSettings()
au BufNewFile,BufRead *.pl,*.cgi call PerlSettings()
au BufNewFile,BufRead *.tex call LaTeXSettings()
au BufNewFile,BufRead *.s,*.src call AssemblySettings()
au BufNewFile,BufRead *.scm call SchemeSettings()
au BufNewFile,BufRead *.txt call TextSettings()

" {{{ Windows batch file
function! DosBatchSettings()
"Windowsバッチファイルの辞書ファイルをセット
set dictionary=$VIMRUNTIME/dict/dosbatch.dict

"実行
noremap <F5> <Esc>:! %<Enter>

endfunction
" }}}
" {{{ VBScript
function! VBScriptSettings()
"VBScriptの辞書ファイルをセット
set dictionary=$VIMRUNTIME/dict/vbscript.dict,$VIMRUNTIME/dict/wsh.dict

"Enterが押されたときに自動補完する
inoremap <expr> <CR> AutoEndForVBScript()

"実行
noremap <F5> <Esc>:! %<Enter>

endfunction
" }}}
" {{{ C,C++,Java,JavaScript commonness
function! CCommonSettings()

set cindent

"キーマップを変更
inoremap <expr> ; GetSemicolonForC()
inoremap <expr> { GetBraceForC()
inoremap <expr> " GetDoubleQuotes()
inoremap <expr> ' GetSingleQuotesForC()
inoremap <expr> <Space> GetSpace()
inoremap , ,<Space>

"関数を範囲選択(VimWikiより)
nnoremap vf ][v[[?^?s*$<CR>

"ブロック選択(VimWikiより)
nnoremap vb /{<CR>%v%0

endfunction

"
" }}}
" {{{ C
function! CSettings()
"cの辞書ファイルをセット
if has("unix")
set dictionary=$HOME/.vim/dict/c.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/c.dict
endif
"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=ccomplete#Complete
endif

" inoremap <expr> :st GetStructForC("struct")
" inoremap <expr> :em GetStructForC("enum")

" inoremap <expr> :fv GetFunctionForC_2select("void")
" inoremap <expr> :fc GetFunctionForC_4select("char")
" inoremap <expr> :fs GetFunctionForC_4select("short")
" inoremap <expr> :fi GetFunctionForC_4select("int")
" inoremap <expr> :fl GetFunctionForC_4select("long")
" inoremap <expr> :ff GetFunctionForC_2select("float")
" inoremap <expr> :fd GetFunctionForC_2select("double")

"gccコンパイラ設定
nmap <F5> :call MakeC_gcc()<cr>

"bccコンパイラ設定
nmap <F6> :call MakeC_bcc()<cr>

endfunction
" }}}
" {{{ C++
function! CppSettings()
"C++言語のキーワードをハイライト
:let java_allow_cpp_keywords=1
endfunction
" }}}
" {{{ Java
function! JavaSettings()
"javaの辞書ファイルをセット
if has("unix")
set dictionary=$HOME/.vim/dict/j2se14.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/j2se14.dict
endif

"ハイライト
:let java_highlight_all=1 "Java言語の標準のクラス名をハイライト
:let java_highlight_debug=1 "デバッグ文のハイライト
:let java_space_errors=1 "余分な空白に対してハイライト
:let java_highlight_functions=1 "メソッド宣言文をハイライト

"コンパイラ設定(Java)
compiler javac

"コンパイル
nmap <F5> :call MakeJava()<CR>

"javacomplete
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=javacomplete#Complete
set completefunc=javacomplete#CompleteParamsInfo
endif

endfunction
" }}}
" {{{ JavaScript
function! JavaScriptSettings()
"JavaScriptの辞書ファイルをセット
if has("unix")
set dictionary=$HOME/.vim/dict/javascript.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/javascript.dict
endif

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=javascriptcomplete#CompleteJS
endif

endfunction
" }}}
" {{{ Ruby
function! RubySettings()
"Rubyのときは、タブ幅を2に設定 & タブ文字の代わりに同じ幅の空白文字を入れる
set nowrap tabstop=2 tw=0 sw=2 expandtab

"コンパイラ設定(RUBY)
compiler ruby

nmap <F5> :call DebugRuby()<cr>

"<F6>でバッファのRubyスクリプトを実行し、結果をプレビュー表示
vmap <silent> <F6> :call Ruby_eval_vsplit()<CR>
nmap <silent> <F6> mzggVG<F6>`z
map <silent> <S-F6> :pc<CR>

"<C-F10>でRubyスクリプトを保存後コマンドプロンプトから実行
nmap <silent> <C-F6> :w<CR>:!ruby %<CR>
endfunction
" }}}
" {{{ HTML,XHTML,XML,XUL commonness
function! TagCommonSettings()

"タブ幅を2に設定
set nowrap tabstop=2 tw=0 sw=2

inoremap <expr> " GetDoubleQuotes()
inoremap <buffer> < <><LEFT>

endfunction
" }}}
" {{{ HTML
function! HTMLSettings()

"マークアップ記号を補完する
inoremap <buffer> \" &quot;
inoremap <buffer> \& &amp;
inoremap <buffer> \< &lt;
inoremap <buffer> \> &gt;
inoremap <buffer> \<Space> &nbsp;

"<F5>でHtmlを表示する
nmap <F5> :! %<CR>

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=htmlcomplete#CompleteTags
endif

endfunction
" }}}
" {{{ Cascading Style Sheets
function! CssSettings()

"タブ幅を2に設定
set nowrap tabstop=2 tw=0 sw=2

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=csscomplete#CompleteCSS
endif

"キーマップ変更
inoremap ; ;<CR>
inoremap : :
inoremap { {<CR>}<Esc>0bo

endfunction
" }}}
" {{{ XML
function! XmlSettings()

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=xmlcomplete#CompleteTags
endif
endfunction
" }}}
" {{{ XUL
function! XulSettings()
set filetype=xul

"XULの辞書ファイルをセット
if has("unix")
set dictionary=$HOME/.vim/dict/xul.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/xul.dict
endif

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=xmlcomplete#CompleteTags
endif
endfunction
" }}}
" {{{ Perl
function! PerlSettings()

"Perlの辞書ファイルをセット
if has("unix")
set dictionary=$HOME/.vim/dict/perl.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/perl.dict
endif

"キーマップを変更
nmap <F5> :! perl %<CR>

endfunction

" }}}
" {{{ Python
function! PythonSettings()
"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=pythoncomplete#Complete
endif
endfunction
" }}}
" {{{ PHP
function! PHPSettings()
"辞書ファイルの設定
if has("unix")
set dictionary=$HOME/.vim/dict/PHP.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/PHP.dict
endif

"オムニ補完
if has("autocmd") && exists("+omnifunc")
"<C-x><C-o>
set omnifunc=phpcomplete#CompletePHP
endif

endfunction
" }}}
" {{{ LaTeX
function! LaTeXSettings()

"四則演算
inoremap <buffer> \* \times
inoremap <buffer> \/ \div
inoremap <buffer> \= \equiv
inoremap <buffer> \!= \neq

"その他演算子
inoremap <buffer> \<= \leq
inoremap <buffer> \>= \geq
inoremap <buffer> \<< \ll
inoremap <buffer> \>> \gg
inoremap <buffer> \+- \pm
inoremap <buffer> \-+ \mp

inoremap $ $$<LEFT>

"LaTeXのときは、タブ幅を2に設定 & タブ文字の代わりに同じ幅の空白文字を入れる
set nowrap tabstop=2 tw=0 sw=2 expandtab

"辞書ファイルの設定
if has("unix")
set dictionary=$HOME/.vim/dict/tex.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/tex.dict
endif

"LaTeXをコンパイル
nmap <C-F5> :! platex %<CR>

"PDF変換
nmap <C-F6> :! dvipdfmx %<<CR>

"句読点を.や,に変換する
nmap <F12> :call ConvertPunctuation()<CR>

"/* -- VIM-LaTeX用設定 -- */
set shellslash

" grepを持っている場合
set grepprg=grep\ -nH\ $*

" OPTIONAL: This enables automatic indentation as you type.
filetype indent on

" dviファイル生成コマンド
let g:Tex_CompileRule_dvi = 'platex --interaction=nonstopmode $*'

" dviファイルビューワー
let g:Tex_ViewRule_dvi = 'dviout'

" pdf生成
let g:Tex_FormatDependency_pdf = 'dvi,pdf'
let g:Tex_CompileRule_pdf = 'dvipdfmx $*.dvi'
let g:Tex_ViewRule_pdf = 'C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe'

" jbitex設定
let g:Tex_BibtexFlavor = 'jbibtex -kanji=sjis'

endfunction
" }}}
" {{{ Assembly
function! AssemblySettings()

"タブ幅を8に設定
set nowrap tabstop=8 tw=0 sw=8

endfunction
" }}}
" {{{ Scheme
function! SchemeSettings()

"タブ幅を2に設定
" set nowrap tabstop=2 tw=0 sw=2

"辞書ファイルの設定
if has("unix")
set dictionary=$HOME/.vim/dict/R5RS.dict
elseif has("gui_win32")
set dictionary=$VIMRUNTIME/dict/R5RS.dict
endif

"インデントの設定(ボクノス様http://d.hatena.ne.jp/tanakaBox/20070609/1181382818より頂戴)
set nocindent
set lisp
set lispwords=define

inoremap <expr> <Space> GetSpace()

endfunction
" }}}
" {{{ Text
function! TextSettings()
set nocindent
"タブ幅を2, タブ文字の変わりにスペース
set nowrap tabstop=2 tw=0 sw=2 expandtab
endfunction
" }}}
" }}}
" {{{ Plugins
"
"NERD_comments
let NERDSpaceDelims = 1
let NERDShutUp = 1

"fuzzyfinder
nnoremap <silent> <C-x><C-b> :FuzzyFinderBuffer<CR>
nnoremap <silent> <C-x><C-f> :FuzzyFinderFile<CR>
nnoremap <silent> <C-x><C-d> :FuzzyFinderDir<CR>

"matchit
:source $VIMRUNTIME/macros/matchit.vim

" }}}
" {{{ Functions
"/* ----------------------------------------------------------------------
" brief: 選択した範囲に行番号をつけてレジスタ * にヤンクする
" param: -
" #http://vimwiki.net/?tips%2F91より頂戴
"---------------------------------------------------------------------- */
function! YankWithLineNumber() range
let a = ""
let i = a:firstline
while i <= a:lastline
let a = a . i . " " . getline(i) . "\n"
let i = i + 1
endwhile
call setreg('*', a, "l")
endfunction

"/* ----------------------------------------------------------------------
" brief: Emacs の delete-blank-lines 相当の関数
" param: -
" #http://vimwiki.net/?tips%2F88より頂戴
"---------------------------------------------------------------------- */
function! DeleteBlankLines()
if search('\S','bW')
let b = line('.') + 1
else
let b = 1
endif
if search('^\s*\n.*\S', 'eW')
let e = line('.') - 1
else
let e = line('$')
endif
if b == e
exe b . "d"
else
exe (b+1) . "," . e . "d"
exe b
endif
endfunction

"/* ----------------------------------------------------------------------
" brief: Smarter Table Editing
" param: fieldsep フィールドのセパレータ(正規表現)
" minlensep フィールドのセパレータの最小の長さ
" padstr 次のフィールドまでの間隔を埋める文字
" offset 次のフィールドの先頭から何文字目にジャンプするかのオフセット
" #http://vimwiki.net/?tips%2F46より頂戴
"---------------------------------------------------------------------- */
function! NextField(fieldsep,minlensep,padstr,offset)
let curposn = col(".")
let linenum = line(".")
let prevline = getline(linenum-1)
let curline = getline(linenum)
let nextposn = matchend(prevline,a:fieldsep,curposn-a:minlensep)+1
let padding = ""

if nextposn > strlen(prevline) || linenum == 1 || nextposn == 0
echo "last field or no fields on line above"
return
endif

echo ""

if nextposn > strlen(curline)
if &modifiable == 0
return
endif
let i = strlen(curline)
while i < nextposn - 1
let i = i + 1
let padding = padding . a:padstr
endwhile
call setline(linenum,substitute(curline,"$",padding,""))
endif
call cursor(linenum,nextposn+a:offset)
return
endfunction

"/* ----------------------------------------------------------------------
" brief: 選択範囲内から検索
" param: 検索キー
" #http://vimwiki.net/?tips%2F45より頂戴
"---------------------------------------------------------------------- */
function! RangeSearch(direction)
call inputsave()
let g:srchstr = input(a:direction)
call inputrestore()
if strlen(g:srchstr) > 0
let g:srchstr = g:srchstr.
\ '\%>'.(line("'<")-1).'l'.
\ '\%<'.(line("'>")+1).'l'
else
let g:srchstr = ''
endif
endfunction

"/* ----------------------------------------------------------------------
" brief: C言語系(C,C++,Java,JavaScript)のセミコロン設定(呼出し側)
" セミコロンが押されたときに一緒に改行するようにする。
" param: -
" return: ; or ;+改行
"---------------------------------------------------------------------- */
function! GetSemicolonForC()
";+改行 or ;
return AutoSemicolonEnterForC()
endfunction

"/* ----------------------------------------------------------------------
" brief: C言語系(C,C++,Java,JavaScript)のセミコロン設定
" セミコロンが押されたときに一緒に改行するようにする。
" param: -
" return: ; or ;+改行
"---------------------------------------------------------------------- */
function! AutoSemicolonEnterForC()
let line = strpart(getline('.'), 0, col('.') - 1)

if line =~ '^\t*for \=('
"for文を記述中
return "; "

else
let words = [
\ "cString",
\ "cCppString",
\ "cCharacter",
\ "cComment",
\ "cCommentStart",
\ "cCommentL",
\ "javaString",
\ "javaCharacter",
\ "javaComment",
\ "javaLineComment",
\ "javaScriptStringD",
\ "javaScriptStringS",
\ "javaScriptComment",
\ "javaScriptLineComment"
\ ]
"let s = synIDattr(synID(line("."),col(".")-1,0),"name")
let s = synIDattr(synID(line("."),col("."),0),"name")
for word in words
if s == word
return ";"
endif
endfor

return ";\<CR>"

endif
endfunction

"/* ----------------------------------------------------------------------
" brief: {が入力されたときに改行+閉じ括弧を補完する
" param: -
" return: {} or { + 改行 + }
"---------------------------------------------------------------------- */
function! GetBraceForC()
let line = strpart(getline('.'), 0, col('.') - 1)
if line =~ ') \=$'
return "{\n}\<Esc>0bo"
else
return "{}\<Left>"
endif
endfunction

"/* ----------------------------------------------------------------------
" brief: 括弧内でスペースが押された場合に、( ←ココにカーソル )状態にする
" param: -
" return: <Space> or <Space><Space><Left>
"---------------------------------------------------------------------- */
function! GetSpace()
let nextChar = strpart(getline('.'), col('.') - 1, 1)
let prevChar = strpart(getline('.'), col('.') - 2, 1)

if nextChar == ")"
if prevChar == "("
return "\<Space>\<Space>\<Left>"
endif
endif

return "\<Space>"

endfunction

"/* ----------------------------------------------------------------------
" brief: 文字列中にある検索ワードがマッチした件数を返す
" param: 行, 検索文字列
" return: マッチした件数
"---------------------------------------------------------------------- */
function! GetMatchCount(line,serchWord)
let l:i = 0
let l:str = a:line
let l:index = match(a:line, a:serchWord)
while l:index != -1
let l:str = strpart(l:str,index + 1)
let l:index = match(l:str, a:serchWord)
let l:i = i + 1
endwhile
return l:i

endfunction

"/* ----------------------------------------------------------------------
" brief: 開きダブルクォートが入力されたときに閉じダブルクォートを挿入する
" param: -
" return: " or ""
"---------------------------------------------------------------------- */
function! GetDoubleQuotes()
if IsExistCorrespondDoubleQuote(getline('.'))
return "\"\"\<LEFT>"
else
return '"'
endif
endfunction

"/* ----------------------------------------------------------------------
" brief: 開きシングルクォートが入力されたときに閉じシングルクォートを挿入する
" param: -
" return: ' or ''
"---------------------------------------------------------------------- */
function! GetSingleQuotesForC()
if IsExistCorrespondSingleQuote(getline('.'))
return "''\<LEFT>"
else
return "'"
endif

endfunction

"/* ----------------------------------------------------------------------
" brief: ダブルクォーテーションの存在チェック
" param: 行
" return: 1 or 0
"---------------------------------------------------------------------- */
function! IsExistCorrespondDoubleQuote(line)
let l:matchCount = GetMatchCount(a:line,'"') - GetMatchCount(a:line,'\\"')
if ( l:matchCount % 2 ) == 0
return 1
else
return 0
endif

endfunction

"/* ----------------------------------------------------------------------
" brief: シングルクォートの存在チェック
" param: 行
" return: 1 or 0
"---------------------------------------------------------------------- */
function! IsExistCorrespondSingleQuote(line)
let l:matchCount = GetMatchCount(a:line,"'")
if ( l:matchCount % 2 ) == 0
return 1
else
return 0
endif

endfunction

"/* ----------------------------------------------------------------------
" brief: VBScriptのEnd XXXを自動的に補完する
" param: -
" return: 改行 or End XXX
"---------------------------------------------------------------------- */
function! AutoEndForVBScript()
let line = strpart(getline('.'), 0, col('.') - 1)

if strlen(line) != strlen(getline('.'))
return "\<CR>"
endif

"ポップアップメニューが表示されているか?
if pumvisible()
return "\<CR>"
endif

"Function, If, Select-Case, While, Do-While, Do-Until, Do-Loop, For
let serchWords = [
\ '^\t*Sub.*)$',
\ '^\t*Function.*)$',
\ '^\t*If ',
\ '^\t*Select Case ',
\ '^\t*While ',
\ '^\t*Do While ',
\ '^\t*Do Until ',
\ '^\t*Do \=$',
\ '^\t*For '
\ ]
"End
let endsStatements = [
\ "End Sub",
\ "End Function",
\ "End If",
\ "End Select",
\ "Wend",
\ "Loop",
\ "Loop",
\ "Loop",
\ "Next"
\]
let i = 0
for regexp in serchWords
if line =~ regexp
return "\<CR>" . endsStatements[i] . "\<UP>\<Esc>o"
endif
let i = i + 1
endfor

return "\<CR>"

endfunction

"/* ----------------------------------------------------------------------
" brief: gccコンパイラ設定
" param: -
" return: -
"---------------------------------------------------------------------- */
function! MakeC_gcc()
:w
:compiler gcc
:set makeprg=gcc
" :make -Wall -g %
:make -Wall --std=c99 %
:cw
endfunction

"/* ----------------------------------------------------------------------
" brief: bccコンパイラ設定
" param: -
" return: -
"---------------------------------------------------------------------- */
function! MakeC_bcc()
:compiler bcc
:set makeprg=bcc32
:make %
:cw
endfunction

"/* ----------------------------------------------------------------------
" brief: Javaコンパイラ設定
" param: -
" return: -
"---------------------------------------------------------------------- */
function! MakeJava()
:make %
:cw
endfunction

"デバッグ
function! DebugRuby()
:make -Ks %
:cw
endfunction

"/* ----------------------------------------------------------------------
" preview interpreter's output(Tip #1244)
"---------------------------------------------------------------------- */
function! Ruby_eval_vsplit() range
if &filetype == "ruby"
let src = tempname()
let dst = "Ruby Output"
" put current buffer's content in a temp file
silent execute ": " . a:firstline . "," . a:lastline . "w " . src
" open the preview window
silent execute ":pedit! " . dst
" change to preview window
wincmd P
" set options
setlocal buftype=nofile
setlocal noswapfile
setlocal syntax=none
setlocal bufhidden=delete
" replace current buffer with ruby's output
silent execute ":%! ruby " . src . " 2>&1 "
" change back to the source buffer
wincmd p
endif
endfunction

"/* ----------------------------------------------------------------------
" brief: 句読点を.や,に変換する
" param: -
" return: -
"---------------------------------------------------------------------- */
function! ConvertPunctuation()

let choice = inputlist(
\ ['run?',
\ ' 1. Yes',
\ ' 2. Cancel']
\ )
if choice == 1
:%s/。/./g
:%s/、/,/g
endif

endfunction
" }}}