tanakaBoxの日記

2008-01-122年目の.vimrc

ども。Vim歴2年目に突入したtanakaです。

また.vimrc張っときます。

roc

" etc {{{
" Scratch & SetSyn {{{
" memo : -> command! -nargs=0 -bar Scrach ...
" See : h command-bar
command! -nargs=1 SS Scratch | call SetSyn("<args>")
"}}}

" Inc file name {{{
" use my inc command
command! -nargs=1 Inc exe "e " . Readirect("!inc " . "<args>")[0] | exe "normal <c-l>"
function! Readirect(cmd)
  let tmp = expand("$TMP/tmp") . Rand(100000000)
  silent exe a:cmd . " > " . tmp
  let r = readfile(tmp)
  silent exe "!rm " . tmp
  return r
endfunc
" }}}

" rand {{{
function! Rand(n)
  exe 'ruby VIM::command("return #{rand(' . a:n . ')}")'
endfunc
" }}}

" Calc {{{
command! -nargs=+ Calc :ruby print <args>
ruby include Math
" }}}

" save window position and window size {{{
let s:save_size = '~/.vim/savesize.vim'
au GUIEnter * if filereadable(expand(s:save_size)) | execute 'source ' . s:save_size | endif
function! SaveSizes()
  let x0 = getwinposx()
  let y0 = getwinposy()
  let x1 = &columns
  let y1 = &lines
  execute 'redir! > ' . s:save_size
  echo 'if exists(":winpos") == 2'
  echo "\t:winpos" x0 y0
  echo "endif"
  echo "set columns=" . x1
  echo "set lines=" . y1
  redir END
endfunction
au VimLeave * if has("gui_running") | silent call SaveSizes() | endif
" }}}

" #!で始まるファイルを保存時に実行権限を付与する {{{
au BufWritePost * :call AddExecmod()
function! AddExecmod()
  let line = getline(1)
  if strpart(line, 0, 2) == "#!"
    call system("chmod +x ". expand("%"))
  endif
endfunction
" }}}

" auto ctags {{{
au FileWritePost,BufWritePost *.c :call AddCtags()
function! AddCtags()
  call system("ctags -a ". expand("%"))
endfunction
" }}}

" Brouser {{{
" url : http://www.vim.org/tips/tip.php?tip_id=306
" test : javascript:alert()
function! Browser ()
  let line0 = getline (".")
  let line = matchstr (line0, "http[^ ]*")
  if line == ""
    let line = matchstr (line0, "ftp[^ ]*")
  endif
  if line == ""
    let line = matchstr (line0, "file[^ ]*")
  endif
  "let line = escape (line, "#?&;|%")
  ":if line==""
  "  let line = "\"" . (expand("%:p")) . "\""
  ":endif
  call system("firefox "  . "\"" . line . "\"")
endfunction
"  http://hoge.com/
nmap <Leader>w :call Browser ()<CR>
" }}}
" auto QuickFix {{{
" url : http://vimwiki.net/?tips%2F66
" move MakeEasy
" }}}

" ruby {{{
"preview interpreter's output(Tip #1244)
function! Ruby_eval_vsplit() range
    if &filetype == "ruby"
        let src = tempname()
        let dst = "RubyOutput"
        " 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
        " change back to the source buffer
        wincmd p
    endif
endfunction
"<F10>でバッファのRubyスクリプトを実行し、結果をプレビュー表示
vmap <silent> <F10> :call Ruby_eval_vsplit()<CR>
nmap <silent> <F10> mzggVG<F10>`z
map  <silent> <S-F10> :pc<CR>
" }}}

au BufWritePost memo.txt helptags .
" }}}

" jp {{{
" 文字コードの自動認識
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



" :IminsertOff/On
" command! -nargs=0 IminsertOff inoremap <buffer> <silent> <ESC> <ESC>:set iminsert=0<CR>
" command! -nargs=0 IminsertOn iunmap <buffer> <ESC>

" runtime macros/editexisting.vim
" }}}


" key bindings {{{

noremap ,, ,

" help : key-notation
set backspace=indent,eol,start
set winaltkeys=no
set timeoutlen=100000

" 関数を範囲選択
vmap \f <ESC>][mz[[V'z

" noremap <silent> <leader> :set timeoutlen=3000<CR>
" inoremap <silent> <ESC> <ESC>:set timeoutlen=10<CR>

noremap <Del> "_

noremap <Leader>te :tabe<cr>
noremap <Leader>tc :tabc<cr>
noremap <Leader>tn :tabn<cr>
noremap <Leader>tp :tabp<cr>
noremap <C-Tab>    :bn<cr>
noremap <C-S-Tab>  :bp<cr>
noremap <Leader><tab> :bn<cr>

map <silent> <F4> :w<CR>:call ReloadFirefox()<CR>
map <silent> <F5> :w<CR>:make<CR>
map <silent> <F6> :w<CR>:make debug<CR>

au! User Rails map <buffer> <silent> <F5> :w<CR>:call ReloadFirefox()<CR>

" noremap o o<ESC>
" noremap O O<ESC>
" smart insert改 http://d.hatena.ne.jp/spiritloose/20061113/1163401194
if has('gui_running')
  nmap ( /(<CR>:noh<CR>
  nmap ) /)<CR>:noh<CR>
  nmap <M-9> ysa()a
  nmap <M-0> ds)
  inoremap <M-{> {}<Left>
  inoremap <M-[> []<Left>
  inoremap <M-(> ()<Left>
  inoremap <M-"> ""<Left>
  inoremap <M-'> ''<Left>
  inoremap <M-<> <><Left>
  "vnoremap { "zdi{<C-R>z}<ESC>
  "vnoremap [ "zdi[<C-R>z]<ESC>
  "vnoremap ( "zdi(<C-R>z)<ESC>
  "vnoremap " "zdi"<C-R>z"<ESC>
  "vnoremap ' "zdi'<C-R>z'<ESC>
  nnoremap <M-;> A;<ESC>
  inoremap <M-;> <ESC>A;<ESC>

  inoremap <M-}> <ESC>A<Space>{}<Left><CR><ESC>O
  nnoremap <M-}> A<Space>{}<Left><CR><ESC>O
  aug CloseBlock
    au!
    au FileType ruby,eruby imap <M-}> <ESC>oend<ESC>O
    au FileType ruby,eruby nmap <M-}> oend<ESC>O
    au FileType ruby,eruby imap <M-#> #{}<Left>
  aug END

  noremap <M-s> :%S//g<Left><Left>

  inoremap <M-p> <C-p>
  inoremap <M-n> <C-n>
  inoremap <M-l> <C-X><C-L>
  inoremap <M-o> <C-X><C-O>
  inoremap <M-k> <C-X><C-K>
  inoremap <M-u> <C-X><C-U>
endif

" for screen
function! ScreenSpiritOpen(cmd)
  call system("screen -X eval split  focus 'screen " . a:cmd ."' focus")
endfunction

function! ScreenEval(str)
  let s = substitute(a:str, "[\n]*$", "\n\n", "") " 最後が改行 * 2で終わるようにする。
  call writefile(split(s, "\n"), "/tmp/vim-screen", "b")
  if has('gui_running')
    call system("screen -X eval 'readreg p /tmp/vim-screen' 'paste p'")
  else
    call system("screen -X eval focus 'readreg p /tmp/vim-screen' 'paste p' focus")
  endif
endfunction

nmap ,e :call ScreenEval(getline('.'))<CR>
vmap ,e "zy:call ScreenEval(@z)<CR>
command! -nargs=1 Screen call ScreenSpiritOpen("<args>")

" smooth-smooth scroll
map <C-U> <C-Y>2<C-Y>2<C-Y>2<C-Y>2<C-Y><C-Y>
map <C-D> <C-E>2<C-E>2<C-E>2<C-E>2<C-E><C-E>

" emacs like? kyes

if has('gui_running')
  cnoremap <M-a> <C-A>
  cnoremap <M-b> <C-B>
  cnoremap <M-d> <C-D>
  cnoremap <M-e> <C-E>
  cnoremap <M-f> <C-F>
  cnoremap <M-n> <C-N>
  cnoremap <M-p> <C-P>
  cnoremap <M-b> <S-Left>
  cnoremap <M-f> <S-Right>
endif

cnoremap <C-A>		<Home>
cnoremap <C-B>		<Left>
cnoremap <C-D>		<Del>
cnoremap <C-E>		<End>
cnoremap <C-F>		<Right>
cnoremap <C-N>		<Down>
cnoremap <C-P>		<Up>
" }}}

au VimEnter * Scratch | set ft=vim | exe "normal i\" = Scratch ===========================================\n\n" | b 1

あれ?うまく貼れてなかった。

PeggyPeggy 2011/07/11 02:24 I’m so glad that the internet allwos free info like this!

ciyqmseciyqmse 2011/07/11 17:37 pEQ3wP <a href="http://lfttxogwufhn.com/">lfttxogwufhn</a>

klpowkesocxklpowkesocx 2011/07/11 22:21 EsWWKi , [url=http://gvvjrdilmeoz.com/]gvvjrdilmeoz[/url], [link=http://uebwfkzyjsda.com/]uebwfkzyjsda[/link], http://pwlwenmlhpvg.com/

wxoldrgpqgjwxoldrgpqgj 2011/07/13 17:56 3SKDJk <a href="http://guzkcheiqasl.com/">guzkcheiqasl</a>

pzqhmlpgcpzqhmlpgc 2011/07/14 00:00 b56gA3 , [url=http://iazlbdcsdfod.com/]iazlbdcsdfod[/url], [link=http://ccybbkaschjc.com/]ccybbkaschjc[/link], http://jvuutyaohjxt.com/

JenaJena 2013/03/03 03:15 I use VIM, but I'm more familiar with the inofamus; (. )( .) command. It should come as a default upgrade with the ubuntu software package. Check your c:/boobs directory. It allows all the HTML you can throw at it.

qjsipwmvqjsipwmv 2013/03/06 09:58 gUyku7 <a href=\"http://cdarplvwgrfx.com/\">cdarplvwgrfx</a>

mrvgenmrvgen 2013/03/08 05:56 TnKMDO , [url=http://ttbnkcrsxtil.com/]ttbnkcrsxtil[/url], [link=http://olkbynsfxovu.com/]olkbynsfxovu[/link], http://bzfpctwrtzbg.com/

ゲスト



トラックバック - http://vim.g.hatena.ne.jp/tanakaBox/20080112