スキップしてメイン コンテンツに移動

vim+zsh+Cygwin環境を構築したので、メモ

Cygwinで遊びたいっ

Cygwinで遊びたい季節ですよね(どういう前ふりなの……?)
いますぐコマンドプロンプトを捨てて、Cygwinを使うべき10+の理由 - ブックマクロ開発に
上記エントリに影響されて、早速Cygwin環境を構築したのでその覚書を。
構築環境はWindows7 Professional 64bit版です。

ダウンロード先

Cygwin本家
本文中のsetup.exeをクリックするとダウンロードが始まります。
とりあえず、Dドライブ直下にインストールしました。
これは自分の環境に合わせて適当にしましょう。

インストールするファイル類

最小構成インストールでも問題ありませんが、以下のソフトを入れておくと捗ります。

  1. vim
  2. zsh
  3. git
  4. gcc4
  5. wget
  6. bzip2
  7. perl
  8. ruby
  9. python
  10. php
日常作業をする分にはこれだけあれば十分では無いでしょうかね。

apt-cygのインストール

wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
chmod +x apt-cyg
mv apt-cyg /bin/apt-cyg

このエントリではapt-cygの出番が殆ど無いけれども、これがあれば毎度毎度setup.exeを起動しなくて良くなるので、非常に大事。

minttyの設定

右クリックからOptionsを選択すしましょう
LooksのTransparencyはMed.かHigh.がお勧めです。個人的にはHigh.が好き。
対応していればGlassもいいかもしれません。
CursorはデフォルトではLineになっていますが、僕はBlockが好きなので、それにしました。
Textは後でも変えられるのでそのままに。
Localeは、ja_JP、Charcter setはUTF-8にしました。
後は特に変更した箇所はありません。
一つ前のエントリに書いたように、minttyの起動オプションを適当に設定しましょう。最大化素敵。

細かい設定等

.screenrcはこんな感じ。 escapeがC-aでもC-zでもC-tでも無く、C-kな僕は異端派。

#UTF-8を使う
defutf8 on
defencoding utf8
encoding utf-8 utf-8

#escape
escape ^Kk

startup_message off
autodetach on
vbell off

caption always "%-w%10L>%{=b bw}%n %t%{-}%+w%-0="
hardstatus alwayslastline "%H%=%Y/%m/%d %02c"
shelltitle "$ |shell"
shell $SHELL

zshrcはこんな感じ

# 文字コードの設定
export LANG=ja_JP.UTF-8


# ヒストリの設定
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000

autoload -Uz compinit
compinit
autoload colors
colors
alias ls='ls -pla'

# like vim
bindkey -v


# history search
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end
bindkey "^N" history-beginning-search-forward-end

# aut cd
setopt auto_cd
setopt auto_pushd

#環境変数
export CYGWIN=tty

.minttyrcはこんな感じ。
フォントはMigu 2Mにしてますが、ここはお好みで。これをそのままコピペするとうぎゃーってなっても責任取れませんw

BoldAsFont=no
FontHeight=14
Columns=80
Rows=20
Locale=ja_JP
Charset=UTF-8
Transparency=medium
CursorType=block
Font=Migu 2M
BoldAsColour=no
RightClickAction=paste
CursorColour=0,255,0
IMECursorColour=255,0,0
Term=xterm-256color
FontHeight=14
Columns=80
Rows=20
Locale=ja_JP
Charset=UTF-8
Transparency=medium
CursorType=block
Font=Migu 2M
BoldAsColour=no
RightClickAction=paste
CursorColour=0,255,0
IMECursorColour=255,0,0
Term=xterm-256color

.vimrcはこんな感じ

""
" For Cygwin Version _vimrc
" Since 2011.11.24

""""""""""""""""""""""""""""""
"内部エンコーディングの設定
""""""""""""""""""""""""""""""
"if has('gui_running') && !has('unix')
  set encoding=utf-8
"endif
"scriptencoding cp932

"filetype off
filetype on
filetype indent on
syntax enable


"行番号表示
set number

"バックアップは邪魔臭いので要らない
set nobackup

"クリップボードへコピー
set clipboard=unnamed

"for vundler

set nocompatible               " be iMproved
filetype plugin indent off     " required!

if has('vim_starting')
 set runtimepath+=~/.vim/bundle/neobundle.vim/
 call neobundle#rc(expand('~/.vim/bundle/'))
endif

NeoBundle 'Shougo/neocomplcache'
NeoBundle 'Shougo/vimshell'
NeoBundle 'Shougo/unite.vim'
NeoBundle 'Shougo/git-vim'
NeoBundle 'Shougo/vimproc'
NeoBundle 'Shougo/vimfiler'
NeoBundle 'tpope/vim-surround'
NeoBundle 'thinca/vim-quickrun'
NeoBundle 'mattn/zencoding-vim'
NeoBundle 'mattn/webapi-vim'
NeoBundle 'kana/vim-smartchr'
NeoBundle 'koron/chalice'

filetype plugin indent on     " required!


"For vimfiler
let g:vimfiler_as_default_explorer = 1


"Zen Coding用
let g:user_zen_settings = {
\'lang': "ja"
\}


"for smart char
"inoremap <expr> = smartchr#one_of(' = ', ' == ', ' === ', '=')

" 演算子の間に空白を入れる
"inoremap <buffer><expr> < search('^#include\%#', 'bcn')? ' <': smartchr#one_of(' < ', ' << ', '<')
"inoremap <buffer><expr> > search('^#include <.*\%#', 'bcn')? '>': smartchr#one_of(' > ', ' >> ', '>')
"inoremap <buffer><expr> + smartchr#one_of(' + ', '++', '+')
"inoremap <buffer><expr> - smartchr#one_of(' - ', '--', '-')
"inoremap <buffer><expr> / smartchr#one_of(' / ', '// ', '/')
" *はポインタで使うので、空白はいれない
"inoremap <buffer><expr> & smartchr#one_of(' & ', ' && ', '&')
"inoremap <buffer><expr> % smartchr#one_of(' % ', '%')
"inoremap <buffer><expr> <Bar> smartchr#one_of(' <Bar> ', ' <Bar><Bar> ', '<Bar>')
"inoremap <buffer><expr> , smartchr#one_of(', ', ',')
" 3項演算子の場合は、後ろのみ空白を入れる
"inoremap <buffer><expr> ? smartchr#one_of('? ', '?')
"inoremap <buffer><expr> : smartchr#one_of(': ', '::', ':')

" =の場合、単純な代入や比較演算子として入力する場合は前後にスペースをいれる。
" 複合演算代入としての入力の場合は、直前のスペースを削除して=を入力
inoremap <expr> = search('\(&\<Bar><Bar>\<Bar>+\<Bar>-\<Bar>/\<Bar>>\<Bar><\) \%#', 'bcn')? '<bs>= '
    \ : search('\(*\<Bar>!\)\%#', 'bcn') ? '= '
    \ : smartchr#one_of(' = ', ' == ', '=')

"neocomplcache用
let g:neocomplcache_enable_at_startup = 1 


"" reloadable vimrc
nnoremap <silent> ,r :<C-u>source $MYVIMRC<CR>

"" for unite
" 編集モードで開始する
let g:unite_enable_start_insert=0
"バッファ一覧
nnoremap <silent> ,ub :<C-u>Unite buffer<CR>
"ファイル一覧
nnoremap <silent> ,uf :<C-u>UniteWithBufferDir -buffer-name=files file<CR>
"レジスタ一覧
nnoremap <silent> ,ur :<C-u>Unite -buffer-name=register register<CR>
"最近使用したファイル一覧
nnoremap <silent> ,um :<C-u>Unite file_mru<CR>
"常用セット
nnoremap <silent> ,uu :<C-u>Unite buffer file_mru<CR>
"全部乗せ
nnoremap <silent> ,ua :<C-u>UniteWithBufferDir -buffer-name=files buffer file_mru bookmark file<CR>

"ウインドウを横に分割して開く
au FileType unite nnoremap <silent> <buffer> <expr> <C-j> unite#do_action('split')
au FileType unite inoremap <silent> <buffer> <expr> <C-j> unite#do_action('split')
"ウインドウを縦に分割して開く
au FileType unite nnoremap <silent> <buffer> <expr> <C-l> unite#do_action('split')
au FileType unite inoremap <silent> <buffer> <expr> <C-l> unite#do_action('split')
"ESCキーを2回押すと終了する
"au FileType unite nnoremap <silent> <ESC><ESC> q
"au FileType unite inoremap <silent> <ESC><ESC> q
"新しいウインドウで開く
au FileType unite nnoremap <silent> <buffer> <expr> <C-t> unite#do_action('tabopen')
au FileType unite inoremap <silent> <buffer> <expr> <C-t> unite#do_action('tabopen')


"バッファ系
au BufNewFile,BufRead * set tabstop=4 shiftwidth=4
au BufNewFile,BufRead *.rhtml set tabstop=2 shiftwidth=2
au BufNewFile,BufRead *.rb set tabstop=2 shiftwidth=2
au BufNewFile,BufRead *.yml set tabstop=2 shiftwidth=2
au BufNewFile,BufRead *.js set tabstop=4 shiftwidth=4
au BufNewFile,BufRead *.css set tabstop=2 shiftwidth=2
au BufNewFile,BufRead *.html set tabstop=2 shiftwidth=2

" for python
autocmd FileType python setl autoindent
autocmd FileType python setl smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python setl tabstop=8 expandtab shiftwidth=4 softtabstop=4

" replce
nnoremap <silent> cy ce<C-r>0<Esc>:let@/=@1<CR>:noh<CR>
vnoremap <silent> cy c<C-r>0<Esc>:let@/=@1<CR>:noh<CR>
nnoremap <silent> ciy ciw<C-r>0<Esc>:let@/=@1<CR>:noh<CR>

" F5 command history
" F6 search history
nnoremap <F5> <Esc>q:  
nnoremap <F6> <Esc>q/

" ignore q: q/ 
nnoremap q: <Nop>
nnoremap q/ <Nop>
nnoremap q? <Nop> 

"ゴミ削除
function! RTrim()
let s:cursor = getpos(".")
%s/\s\+$//e
call setpos(".", s:cursor)
endfunction

autocmd BufWritePre *.php,*.rb,*.js,*.bat,*.py call RTrim()
autocmd QuickfixCmdPost vimgrep cwin

" コメントアウト用
" http://vim-users.jp/2011/03/hack205/をそのままコピペ
" Comment or uncomment lines from mark a to mark b.
function! CommentMark(docomment, a, b)
  if !exists('b:comment')
    let b:comment = CommentStr() . ' '
  endif
  if a:docomment
    exe "normal! '" . a:a . "_\<C-V>'" . a:b . 'I' . b:comment
  else
    exe "'".a:a.",'".a:b . 's/^\(\s*\)' . escape(b:comment,'/') . '/\1/e'
  endif
endfunction

" Comment lines in marks set by g@ operator.
function! DoCommentOp(type)
  call CommentMark(1, '[', ']')
endfunction

" Uncomment lines in marks set by g@ operator.
function! UnCommentOp(type)
  call CommentMark(0, '[', ']')
endfunction

" Return string used to comment line for current filetype.
function! CommentStr()
  if &ft == 'cpp' || &ft == 'java' || &ft == 'javascript'
    return '//'
  elseif &ft == 'vim'
    return '"'
  elseif &ft == 'python' || &ft == 'perl' || &ft == 'sh' || &ft == 'R' || &ft == 'ruby'
    return '#'
  elseif &ft == 'lisp'
    return ';'
  endif
  return ''
endfunction

nnoremap <Leader>c <Esc>:set opfunc=DoCommentOp<CR>g@
nnoremap <Leader>C <Esc>:set opfunc=UnCommentOp<CR>g@
vnoremap <Leader>c <Esc>:call CommentMark(1,'<','>')<CR>
vnoremap <Leader>C <Esc>:call CommentMark(0,'<','>')<CR>


"カレント変更
command! -nargs=? -complete=dir -bang CD  call s:ChangeCurrentDir('<args>', '<bang>') 
function! s:ChangeCurrentDir(directory, bang)
    if a:directory == ''
        lcd %:p:h
    else
        execute 'lcd' . a:directory
    endif

    if a:bang == ''
        pwd
    endif
endfunction

" Change current directory.
nnoremap <silent> <Space>cd :<C-u>CD<CR>

"URL encode and decode
command! -nargs=0 -range URLEncode :<line1>,<line2>call <SID>URLEncode()
command! -nargs=0 -range URLDecode :<line1>,<line2>call <SID>URLDecode()

"from chalice.vim
function! s:URLEncode()
 let l:line = getline('.')
 let l:encoded = AL_urlencode(l:line)
 call setline('.', l:encoded)
endfunction

"from chalice.vim
function! s:URLDecode()
 let l:line = getline('.')
 let l:encoded = AL_urldecode(l:line)
 call setline('.', l:encoded)
endfunction

" colors
colorscheme desert
hi CursorIM  guifg=black  guibg=red  gui=NONE  ctermfg=black  ctermbg=white  cterm=reverse

圧倒的なVim力の差……。
メイン環境なので仕方がありませんね。
ちなみにvimは厳密な手順で設定する必要があります。

$ mkdir -p ~/.vim/bundle
$ git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim

上記の魔法のコマンドを実行してから、vimを起動。
:NeoBundleInstall を実行。

$ cd ~/.vim/bundle/vimproc
$ make -f make_cygwin.mak

と実行して、cygwin用のvimproc.dllをコンパイル。
そうしてようやくunite.vimが使えるようになります。
unite.vimはホント素晴らしい。

感想

  1. minttyが思った以上に綺麗。
  2. apt-cygで全て捗る
  3. zencoding.vimは便利
  4. UTF-8いいねぇ。
  5. VimFilerに感動。
  6. vimprocに感動。
  7. githubが無いと死んじゃう

以上です。何かの参考にしていただければ幸いです

コメント

このブログの人気の投稿

EFIブートローダを移動した話

EFIブートローダを移動した HX90に環境を整え終わってから、アホな事をしたので、その記録を残す。 SSD: Cドライブ SSD: Dドライブ(データストレージ用) + ESP※ SSD: Eドライブ(データストレージ用) ※ESP(EFI System Partition) インストールした時、こんな構成だった。 ESPがDドライブにあるのが気持ち悪かったので、これを削除した。 そしたら、BIOS画面が出るだけになり、Windowsが起動しなくなった。 移動手順 この時の自分はMBRをふっ飛ばした時と同じ現象だと思ったので、MBRというキーワードで検索したが、今はEFIブートローダーと呼んでいるらしい。 【Win10】任意のディスクにEFIブートローダをインストールする 色々検索した結果この記事が参考になった。 Diskpartを使って、パーティションを新たに分割し、bcdbootを実行して、無事に事なきを得た。 パーティションの分割はこんな感じ Diskpart Select volume 0 shrink desired = 200 Select disk 0 Create partition EFI size=200 Format quick fs=fat32 label="ESP" Assign letter=P exit EFIブートローダーのインストールはこんな感じ bcdboot C:\Windows /s P: /f UEFI ちなみに、自分の環境だけの問題なのだが、コマンドラインで、「\」を入力するのができなかった。我が家のキーボードはHHKBだけなので、日本語配列を無理やり適用されると、バックスラッシュが入力できないという不具合が生じる。 結局、コマンドプロンプトからマウスで範囲選択してコピーして貼り付けるという荒業でクリアした。 普通の人は、何も考えずに、\を入力すれば良い。 最終的に SSD: Cドライブ + ESP※ SSD: Dドライブ(データストレージ用) SSD: Eドライブ(データストレージ用) ※ESP(EFI System Partition) という構成に切り替えることができた。

PlemolJP導入

PlemolJP を導入した 思い立つことがあり、 PlemolJP をインストールする事にした。 自分は、PowerLine を使っているので、PlemolJP Nerd Fonts 版である、PlemolJP_NF をダウンロードしてインストールした PlemolJP の releases から、PlemolJP_NF_vx.x.x.zip をダウンロードする。 zip を展開し、PlemolJPConsoleNF-Regular.ttf をインストールする set guifont=PlemolJP_Console_NF:h18 を gvimrc に書く(フォントサイズはお好きに) ちなみに、これは Windows 限定の設定なので、Mac や Linux などで導入する際には、別の方法をオススメする。 余談 gvimrc に指定するフォント名が微妙にわかりづらい。 普段は、 set guioptions-=m してメニューバーは出していないが、今回は :set guioptions+=m を実行して、編集 → フォント設定からフォントを選び、フォント名に入力されている文字列をコピペして、スペース部分をアンダースコアで置き換えた。 この辺のルールとかに詳しい人にぜひとも教えて欲しい所。 導入した感想 今までの Powerline フォントはいまいちなのが多かったが、PlemolJP の表示は非常に良い。 今後はこちらをメインで使って行きたい。 あと、僕はヱビス派です。