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

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が無いと死んじゃう

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

コメント

このブログの人気の投稿

Let's note CF-SZ6にGoogle Play入りChromeOSを入れて、超軽量Chromebookを手に入れた

Let's note CF-SZ6にGoogle Play入りChromeOSをインストールする 先日、 魔が差して 、 Let's note CF-SZ6の中古 をポチってしまった。なんとなく ChromeOS に触りたくなり、中古のやっすいPCに入れたらええんちゃうんという心の声に逆らえなくなった。 で、一旦ChromeOS Flexを入れて使ってみたんだけれど、やっぱりGoogle Playのアプリが入れられないのはNG。 自分が欲しかったのは、Google Playが使えるChromeOSなんやという事で、 ネットのインストール記事 を探して、入れることにした。 ほぼ、そこの記事通りにインストールしているが、自分なりのアレンジも加えているので、参考にする人は参考にしていただきたい。 手順は下記の通り 軽量Linuxをダウンロードする 対応しているChromeOSのバージョンを調べ、ダウンロードする Brunchをダウンロードする Rufusをダウンロードする USBメモリーに軽量Linuxをインストールし、ChromeOSをコピペする USBメモリーから、実際に軽量Linuxを起動して、インストールコマンドを実行する 軽量Linuxをダウンロードする インストール作業用として、軽量LinuxをUSBメモリーに構築する。 Linux Mint がオススメという事なので、こいつをダウンロードする。 ダウンロードページ にアクセスし、Xfce Editionをダウンロード。 ダウンロードが完了すると、 linuxmint-21.3-xfce-64bit.iso みたいなファイルが出来上がっている。 対応しているChromeOSのバージョンを調べ、ダウンロードする 自分が購入した Let's note CF-SZ6 は、Core i5-7200Uとの事なので、7世代目のCPUとなる。 この7世代目のCPUに対応しているのは、board: rammusのバージョンになる。 https://cros.tech/ にアクセスし、 rammus を検索すると、対応するChrome OSのバージョンが出てくるので、これをダウンロードする。 自分は、 stable バージョンの 126 をダウンロードした。 ダウン...

Windows版gVimをアンインストールした日

Windows 版 gVim をアンインストールした話 以前に、 Windows11 on WSL2 + wezterm + Neovim = 最強開発環境 という痛々しい記事を書いたのだが、その続きの記事と言っても過言ではない。 この記事は Vim 駅伝 の 3 月 1 日の記事である。 前回はぺりーさんの netrw を使うために という記事だった。 次回は kuuote さんの Vim 側の組み込みプラグインを無効化するハック という記事である。 gVim との付き合い 思い返してみると、gVim との付き合いは大分長くなった。エディタとしては 自分の人生の中で最も長く付き合ってきたエディタ と言える。Vim のインターフェースとして gVim を何度も使ってきた。自分の手持ちのマシンは Windows なので、必然的に gVim を選択肢として選ぶ必要があった。 gVim の良さは何か。それは、Windows とのシームレスな関係であり、Windows OS の機能をそのまま使いたい場合に有用である。かつての自分にとってこの部分は非常に重要であった。具体的には、印刷機能と画面半透明化機能であり、これが無いとやってられないという認識であった。 しかし、時代が進み、自分の技術力の向上や考え方の変化、さらに Vim 周りのプラグインの更新が進むと gVim で運用していく事がだんだんと億劫になっていったというのが事実である。故に、 WSL2 上で動く Neovim の快適さに心が打ち震えた のである。 技術力の向上に伴う考え方の変化 かつての自分は 何でも gVim で処理したいな と考えていた。メールを見たり天気を見たり、Twitter を見たりするのに、gVim を活用していた。かつての Emacs 使いの guru のような立ち位置を目指していたというのがある。2000 年代初頭にインターネットに多少なりとも触れていた人ならば、「それ Pla」という古の単語を思い浮かべるかもしれない。この概念を持ち出すのはあまりにも古すぎるが、結局言いたいのは、 1 つの手法で全部をこなす という考え方だ。ネットを見るのにわざわざブラウザに切り替えるのはもったいないという今となっては情熱に似た何かを当時は多くの人が持っていた。 しかし、自分自身の技術力...

翼の騎士正体考察

翼の騎士正体考察 最新刊の宣伝 先日、 最新18巻が発売された 。七ツ星 魔人 ヴァンデル も残るは、ノア、ベルトーゼ、ロディーナと3体まで減り物語も佳境に入ったと言える。今巻は、新生ビィト戦士団の結成と魔人博士ノアとの邂逅までが描かれているのだが、いやあ、そう来たかぁという落ちで、何も情報無しで読むとめっちゃビックリすると思う。 最新刊読んでいない人は今すぐ購入して読もう。 翼の騎士について 翼の騎士の初登場は(恐らく)7巻P94。シルエットのみの登場。本格的な登場は9巻のP31以降。 本格登場から、ゼノン戦士団の才牙を十分以上に使いこなしていて、正体は一体誰なのだろうと考えさせられるキャラだ。 翼の騎士は ゼノン戦士団を良く知っている ゼノン戦士団の才牙を使いこなせる 武器としてミニガンを持っている(9巻P82) 武器として長剣(?)を持っている(12巻P115) 長剣と天力を使って弓矢のように放つことが出来る?(12巻P126) クルスと同時に存在してるページがある(=クルスではない)(11巻P123) 才牙は持っていない 時間制限がある(12巻P138) 時間になったり、一定上のダメージを受けると光になって消える(12巻P140) ビィトは素顔を知っている(16巻P61) グランシスタ王と顔見知り(18巻P63) といった要素が挙げられているが、決定打は今のところ無い。 とは言え、ここまで出揃った要素について考えると、幾つかの候補が挙げられる 翼の騎士の正体候補 上記の要素から、翼の騎士の正体は基本的に ゼノン戦士団 の誰かである事は確実だろう。 その場合、候補は三人になる。 ゼノン アルサイド ブルーザム 候補1 ゼノン ベルトーゼとの戦いで光となって消えてしまった ゼノン が翼の騎士の正体と考える読者は多いだろう。 王道でひねり無く行くならば、ゼノンで良い気がする。 ゼノンほどの能力があれば、ゼノン戦士団の才牙を使いこなせるというのも納得だし、光となって消えるのも、回想シーンからある程度納得の行く材料として挙げられる。 しかしながら、ゼノン(=実の兄)との再開なのに、思った以上にビィトが喜んでいないというのが個人的には引っかかっている。三条陸氏は何もひねらずに伏線回収するよりも、 一捻り入れ...