Windowsインストール(6)

Vim

Gvimではなく、Vimを使っています。

インストール
  1. ダウンロード
    1. "Runtime files"(vim72rt.zip)をダウンロード、展開
    2. "Win32 console executable"(vim72w32.zip)をダウンロード、展開
  2. すべて同じ"C:\vim"ディレクトリに混ぜ入れ
  3. "C:\vim\vim32\install.bat"をクリックして起動
  4. 質問に対して"d[Enter]"を入力
  5. PATHに"C:\vim\vim72"を追加
  6. "C:\vim\_vimrc"を編集
" Command --
syntax on
filetype on
set showcmd
set laststatus=2
set statusline=%<%f\ %h%r%w%=\ %M\ %l,%v\ %{'['.(&ft!=''?&ft:'any').','.(&fenc!=''?&fenc:&enc).','.&ff.']'}[%n]

" Edit --
set autoindent
set backspace=indent,eol,start
set cinwords=if,unless,else,elsif,while,do,for,switch
set errorbells
set incsearch
set list
set listchars=tab:>\ ,trail:-
set scrolljump=20
set tabstop=4
set whichwrap=b,s,h,l,<,>,[,]

nmap <silent> <F4> <C-W><C-W>
nmap <silent> <C-Up> <C-W>j<C-W>_
nmap <silent> <C-Down> <C-W>k<C-W>_
nmap <silent> <C-Right> 4<C-W>+
nmap <silent> <C-Left> 4<C-W>-

" File --
set autoread
set autowrite
set browsedir=buffer
set fileencodings=utf-8,euc-jp,cp932
set fileformats=unix

nmap <silent> <F2> :Sexplore<CR>

" Encoding --
set encoding=utf-8
set termencoding=utf-8

" Make --
augroup make
  autocmd! make
  autocmd FileType java :compiler javac
  autocmd FileType perl :compiler perl
  autocmd FileType php :compiler php
  autocmd FileType python :compiler ptyhon
  autocmd FileType ruby :compiler ruby
augroup END

" thanks: http://blog.blueblack.net/item_150
nmap <silent> <F10> :w<CR>:make %<CR>:cw<CR>:cfirst<CR>zz
nmap <silent> <S-F10> :ccl<CR>

" Execute --
" thanks: http://blog.blueblack.net/item_150
function LL_execute(runtime, first, last)
  let src = tempname()
  let dst = tempname()
  execute ": " . a:first . "," . a:last . "w " . src
  execute ":silent ! " . a:runtime . " " . src . " > " . dst . " 2>&1 "
  execute ":pedit! " . dst
endfunction

let s:interpreter = {
  \"perl":       [function("LL_execute"), "perl"  ],
  \"php":        [function("LL_execute"), "php"   ],
  \"python":     [function("LL_execute"), "python"],
  \"ruby":       [function("LL_execute"), "ruby"  ]
\}

function! Cmd_execute() range
  if empty(&filetype)
    return
  endif
  let cmd = get(s:interpreter, &filetype)
  if empty(cmd)
    return
  endif
  call call(cmd[0], [cmd[1], a:firstline, a:lastline])
endfunction
vmap <silent> <F9> :call Cmd_execute()<CR>
nmap <silent> <F9> mzggVG<F9>`z
nmap <silent> <S-F9> :pclose<CR>

" Full Width Space --
" thanks: http://d.hatena.ne.jp/potappo2/20061107/1162862536
function! JpSpace_highlight()
  syntax clear
  syntax match JpSpace " " display containedin=ALL
  highlight JpSpace term=underline ctermbg=1
endfunction
augroup invisible
  autocmd! invisible
  autocmd BufNew,BufNewFile,BufRead * call JpSpace_highlight()
augroup END

" Remove trailing spaces --
function! Remove_trailing_spaces()
  normal mz
  silent %s/\s*$//
  normal `z
endfunction
augroup trailing
  autocmd! trailing
  autocmd BufWritePre * call Remove_trailing_spaces()
augroup END

" Last edit line --
function! Last_edit_line()
  if line("'\"") > 0 && line("'\"") <= line("$")
    normal g'"
  endif
endfunction
augroup lasteditline
  autocmd! lasteditline
  autocmd BufReadPost * call Last_edit_line()
augroup END

" Tlist --
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1

" for Windows --
map <silent> <S-Up> <C-Up>
map <silent> <S-Down> <C-Down>
map <silent> <S-Right> <C-Right>
map <silent> <S-Left> <C-Left>
set encoding=cp932
set termencoding=cp932
set fileencodings=utf-8,cp932,euc-jp,utf-16
set fileformats=dos,unix

" for Unix --
"map <silent> <Esc>[24~ <S-F2>
"map <silent> <Esc>[33~ <S-F9>
"map <silent> <Esc>[34~ <S-F10>
"map <silent> <Esc>[A <C-Up>
"map <silent> <Esc>[B <C-Down>
"map <silent> <Esc>[C <C-Right>
"map <silent> <Esc>[D <C-Left>
  1. "C:\vim\.vimrc"にリネーム
> rename "C:\vim\_vimrc" "C:\vim\.vimrc"
スタートメニューの調整
  1. [スタート]をクリック、[プログラム]"Vim7.2"の"vim"を右クリック
  2. [プロパティ]をクリック
  3. 画面の色タブに切り替え
  4. "画面の文字"にチェックを入れて、色を白に設定
  5. レイアウトタブに切り替え
  6. "画面バッファサイズ"の高さを2000ぐらいに設定
  7. "ウィンドウのサイズ"の高さを42ぐらいに設定
  8. [OK]
  9. 同様に"Vim Diff","Vim Read-only"も設定
ハードリンク
> mkdir "%USERPROFILE%\My Documents\etc\vim"
> fsutil hardlink create "%USERPROFILE%\My Documents\etc\vim\.vimrc" "C:\vim\.vimrc"
> fsutil hardlink create "C:\vim\vim72\vi.exe" "C:\vim\vim72\vim.exe"
プラグインtaglist.vim
  1. taglistをダウンロード、展開
  2. 中身を"C:\vim\vimfiles"へコピー
  3. ctagsをダウンロード、展開
  4. 中身を"C:\usr\bin"へコピー

初期化

> cd "C:\vim\vimfiles\doc"
> vim
:helptags .

起動

:Tlist
プラグインmru.vim
  1. "mru.vim"をそのまま"C:\vim\vimfiles\plugin"へコピー

起動

:MRU

Msysでvimが動かない?

Msys上でVimが動いたと思ったのですが、動かない(CPUを使い切ったままハングアップする)ので、対処にMsys専用のvimを導入します。

7-Zip

LZMA対応の圧縮展開ソフト。

  1. ダウンロードして、インストール

Msys Vim

ダウンロードへ直接リンクです。

  1. ダウンロードしたのち、7-Zipで展開
  2. "vim-7.2-1-msys-1.0.11-bin"以下を"C:\msys\1.0"にコピー
  3. "C:\msys\1.0\vim"にリネーム
  4. "$HOME/.profile"("C:\msys\1.0\home\ユーザ名\.profile")に以下を追加
export PATH="/vim/bin:$PATH"
設定

"$HOME/.profile"("C:\msys\1.0\home\ユーザ名\.profile")に追加します。

export PATH="/vim/bin:$PATH"
export VIMRUNTIME="/vim/share/vim/vim72"
alias vi=vim

"$HOME/.vimrc"("C:\msys\1.0\home\ユーザ名\.vimrc")を作ります。

set runtimepath+=/c/vim/vimfiles/
source /c/vim/.vimrc

※fencの設定が無いかもしれません(元々考えられてないかも)。