ソフトウェア > Cygwin

Linux系のコマンドやツールが使えると何かと便利なので、Cygwin(64bit)を導入しました。
その時の備忘録

インストール

  • http://www.cygwin.com/からsetup-x86_64.exeをダウンロード
  • サーバー・インストールディレクトリを指定後、必要なものを選んでインストール(下記適当に自分がインストールしたもの
    • Archiveのzip,uzipなど
    • Base,Devel全部
    • EditorsのEmacs,Vim,nanoなど
    • InterpreterのPython,Perlなど(Vimでneocompleteを使うので、luaも追加)
    • Netのopenssh,openssl,wgetなど
    • Utilsのscreenなど
    • Webのw3mなど

各種設定

Cygwin Terminal(mintty)の設定

自分の場合の設定(~/.mintty)を下記に示します。
BoldAsFont=no
Font=MS ゴシック
Locale=ja_JP
Charset=SJIS
FontHeight=10
Columns=100
Rows=34
Transparency=medium
Term=xterm
RightClickAction=paste
OpaqueWhenFocused=no
PgUpDnScroll=yes
CtrlShiftShortcuts=yes
BellFlash=yes
BellTaskbar=no

minttyのロケール・文字コードの設定

  • Cygwinを起動後、タイトルバーの左端のアイコンを右クリック、
  • 「Options...」をクリック
  • メニューで「Text」を選択
  • 「Locale」で「C」を選択<<2015/03現在、ロケールを「C」にしないとVim内のeskkで変換ができないため「ja_JP」にはしない>>
  • 「Character_Set」で「UTF-8」を選択

文字コードをUTF-8にする(上記minttyのロケール・文字コードを設定し、minttyからしかCygwinを使用しない場合はこの設定は不要)

$ echo "export LANG=ja_JP.utf8" >>  ~/.bashrc
$ source ~/.bashrc

apt-cygのインストール

いちいちsetup-x86_64.exeを起動して追加ソフトのインストールは面倒なのでapt-getみたいにコマンドでインストールできるようにする。
参照元:http://code.google.com/p/apt-cyg/
$ svn --force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/
$ chmod +x /bin/apt-cyg
apt-cyg実行時、setup.iniが無いとエラーが出たため、その対策↓
http://qiita.com/DQNEO/items/f49d5a534eee6c3352a8

コンテキストメニューで任意のディレクトリをCygwin Terminalで開けるようにする

参照元:http://stackoverflow.com/questions/9637601/open-cygwin-at-a-specific-folder
Cygwinをコンテキストメニューから開くのは、ChereをCygwinにインストールする方法がベターなようですが、
64bit版のCygwinではChereが使えないので、コンテキストメニューの「送る」(SendTo)にショートカットを追加することで対応しました。
Windowsのエクスプローラから、フォルダを右クリック->送る->CygwinTerminalHereでその場所をカレントディレクトリとしたCygwinを開く
  • C:\Users\ユーザ名\AppData\Roaming\Microsoft\Windows\SendTo を開く(Windows8の場合)
  • 右クリック->ショートカットの作成
  • 下記を入力
C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico  C:\cygwin64\bin\bash.exe  -l -c "cd \"$(cygpath -u \"$0\")\" ; exec bash"
  • 名前を「CygwinTerminalHere」など適当に指定してOK

コンテキストメニューで任意のファイルをCygwin内のVimで開けるようにする

Windows版のGvimでもできるが、Cygwin内のVimとWindows版のGvim2つを使うのは
管理が面倒そうなので、Gvim同様にコンテキストメニューからCygwin内にVimを開けるようにして
CygwinのVimで作業するよう統一した。
Windowsのエクスプローラから、フォルダを右クリック->送る->Vim(Cygwin)で、
ファイルのある場所をカレントディレクトリとし、指定したフィアルをCygwin内のVimで開く
  • C:\Users\ユーザ名\AppData\Roaming\Microsoft\Windows\SendTo を開く(Windows8の場合)
  • 右クリック->ショートカットの作成
  • 下記を入力(シェルスクリプト初心者なので間違ってるかも)
C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico  C:\cygwin64\bin\bash.exe  -l -c "cd \"$(dirname \"$(cygpath -u \"$0\")\")\" ; vim \"$(cygpath -u \"$0\")\""
  • 名前を「Vim(Cygwin)」など適当に指定してOK

Vimの設定

neobundleのインストール

プラグインの管理を簡単にするため導入
$ mkdir ~/.vim
$ cd ~/.vim
$ mkdir bundle
$ cd bundle
$ git clone git://github.com/Shougo/neobundle.vim

.vimrcの作成

~/.vimrcを作成して、下記のような内容にした。
参考:http://vimwiki.net/?vimrc%2F9
neobundleで幾つかプラグインをインストールするよう記述したため、
初回起動時に、:NeoBundleInstallを実行すること
+ .vimrcの内容
" URL: http://vim.wikia.com/wiki/Example_vimrc
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
" Description: A minimal, but feature rich, example .vimrc. If you are a
"              newbie, basing your first .vimrc on this file is a good choice.
"              If you're a more advanced user, building your own .vimrc based
"              on this file is still a good idea.
 
"------------------------------------------------------------
" Features {{{1
"
" These options and commands enable some very useful features in Vim, that
" no user should have to live without.
 
" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
" Vi互換モードをオフ(Vimの拡張機能を有効)
set nocompatible
 
" Attempt to determine the type of a file based on its name and possibly its
" contents.  Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
" ファイル名と内容によってファイルタイプを判別し、ファイルタイププラグインを有効にする
filetype indent plugin on
 
" Enable syntax highlighting
" 色づけをオン
syntax on
 
 
"------------------------------------------------------------
" Must have options {{{1
"
" These are highly recommended options.
" 強く推奨するオプション
 
" One of the most important options to activate. Allows you to switch from an
" unsaved buffer without saving it first. Also allows you to keep an undo
" history for multiple files. Vim will complain if you try to quit without
" saving, and swap files will keep you safe if your computer crashes.
" バッファを保存しなくても他のバッファを表示できるようにする
set hidden
 
" Better command-line completion
" コマンドライン補完を便利に
set wildmenu
 
" Show partial commands in the last line of the screen
" タイプ途中のコマンドを画面最下行に表示
set showcmd
 
" Highlight searches (use <C-L> to temporarily turn off highlighting; see the
" mapping of <C-L> below)
" 検索語を強調表示(<C-L>を押すと現在の強調表示を解除する)
set hlsearch
 
" Modelines have historically been a source of security vulnerabilities.  As
" such, it may be a good idea to disable them and use the securemodelines
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
" 歴史的にモードラインはセキュリティ上の脆弱性になっていたので、
" オフにして代わりに上記のsecuremodelinesスクリプトを使うとよい。
" set nomodeline
 
 
"------------------------------------------------------------
" Usability options {{{1
"
" These are options that users frequently set in their .vimrc. Some of them
" change Vim's behaviour in ways which deviate from the true Vi way, but
" which are considered to add usability. Which, if any, of these options to
" use is very much a personal preference, but they are harmless.
 
" Use case insensitive search, except when using capital letters
" 検索時に大文字・小文字を区別しない。ただし、検索後に大文字小文字が
" 混在しているときは区別する
set ignorecase
set smartcase
 
" Allow backspacing over autoindent, line breaks and start of insert action
" オートインデント、改行、インサートモード開始直後にバックスペースキーで
" 削除できるようにする。
set backspace=indent,eol,start
 
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
" オートインデント
set autoindent
 
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
" 移動コマンドを使ったとき、行頭に移動しない
set nostartofline
 
" Display the cursor position on the last line of the screen or in the status
" line of a window
" 画面最下行にルーラーを表示する
set ruler
 
" Always display the status line, even if only one window is displayed
" ステータスラインを常に表示する
set laststatus=2
 
" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
" バッファが変更されているとき、コマンドをエラーにするのでなく、保存する
" かどうか確認を求める
set confirm
 
" Use visual bell instead of beeping when doing something wrong
" ビープの代わりにビジュアルベル(画面フラッシュ)を使う
set visualbell
 
" And reset the terminal code for the visual bell.  If visualbell is set, and
" this line is also included, vim will neither flash nor beep.  If visualbell
" is unset, this does nothing.
" そしてビジュアルベルも無効化する
set t_vb=
 
" Enable use of the mouse for all modes
" 全モードでマウスを有効化
set mouse=a
 
" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
" コマンドラインの高さを2行に
set cmdheight=2
 
" Display line numbers on the left
" 行番号を表示
set number
 
" Quickly time out on keycodes, but never time out on mappings
" キーコードはすぐにタイムアウト。マッピングはタイムアウトしない
set notimeout ttimeout ttimeoutlen=200
 
" Use <F11> to toggle between 'paste' and 'nopaste'
" <F11>キーで'paste'と'nopaste'を切り替える
set pastetoggle=<F11>
 
 
"------------------------------------------------------------
" Indentation options {{{1
" インデント関連のオプション {{{1
"
" Indentation settings according to personal preference.
 
" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
" タブ文字の代わりにスペース2個を使う場合の設定。
" この場合、'tabstop'はデフォルトの8から変えない。
set shiftwidth=2
set softtabstop=2
set expandtab
 
" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
" インデントにハードタブを使う場合の設定。
" タブ文字を2文字分の幅で表示する。
"set shiftwidth=2
"set tabstop=2
 
 
"------------------------------------------------------------
" Mappings {{{1
" マッピング
"
" Useful mappings
 
" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
" Yの動作をDやCと同じにする
map Y y$
 
" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
" <C-L>で検索後の強調表示を解除する
nnoremap <C-L> :nohl<CR><C-L>
 
"------------------------------------------------------------
"" デフォルトのエンコードをUTF-8に設定
"if has('gui_running') && !has('unix')
"  set encoding=utf-8
"endif
"".vimrc(_vimrc)が cp932の場合
"scriptencoding cp932
 
"------------------------------------------------------------
" 日本語環境用エンコード処理
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'
  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'
  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
  if &encoding ==# 'utf-8'
    let s:fileencodings_default = &fileencodings
    if has('mac')
      let &fileencodings = s:enc_jis .','. s:enc_euc
      let &fileencodings = &fileencodings .','. s:fileencodings_default
    else
      let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
      let &fileencodings = &fileencodings .','. s:fileencodings_default
    endif
    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
 
"------------------------------------------------------------
" neobundleの設定
 
" vim起動時のみruntimepathにneobundle.vimを追加
if has('vim_starting')
  set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
 
" neobundle.vimの初期化
call neobundle#rc(expand('~/.vim/bundle'))
 
" neobundle.vimを更新するための設定
NeoBundleFetch 'Shougo/neobundle.vim'
 
" 読み込むプラグインを記述
" NeoBundle 'プラグイン名'
NeoBundle 'git://github.com/scrooloose/syntastic.git'
" if_luaが使用可能であればneocompleteを読み込む
if has('lua')
  NeoBundle 'git://github.com/Shougo/neocomplete' , {
        \ 'autoload': {
        \   'insert': 1,
        \ }}
else
  NeoBundle 'git://github.com/Shougo/neocomplcache' , {'lazy': 1,
        \ 'autoload': {
        \   'insert': 1,
        \ }}
endif
" 読み込んだプラグインも含め、ファイルタイプの検出、
" ファイルタイプ別プラグイン/インデントを有効化する
filetype plugin indent on
 
"------------------------------------------------------------
" Syntasticの設定
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list=1
 
"------------------------------------------------------------
" NeoCompleteの設定
" Note: This option must set it in .vimrc(_vimrc).
" NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
 
" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell_hist',
    \ 'scheme' : $HOME.'/.gosh_completions'
    \ }
 
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
 
" Plugin key-mappings.
inoremap <expr><C-g>     neocomplete#undo_completion()
inoremap <expr><C-l>     neocomplete#complete_common_string()
 
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return neocomplete#smart_close_popup() . "\<CR>"
  " For no inserting <CR> key.
  "return pumvisible() ? neocomplete#close_popup() : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><C-y>  neocomplete#close_popup()
inoremap <expr><C-e>  neocomplete#cancel_popup()
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? neocomplete#close_popup() : "\<Space>"
 
" For cursor moving in insert mode(Not recommended)
"inoremap <expr><Left>  neocomplete#close_popup() . "\<Left>"
"inoremap <expr><Right> neocomplete#close_popup() . "\<Right>"
"inoremap <expr><Up>    neocomplete#close_popup() . "\<Up>"
"inoremap <expr><Down>  neocomplete#close_popup() . "\<Down>"
" Or set this.
"let g:neocomplete#enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplete#enable_insert_char_pre = 1
 
" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1
 
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB>  pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
 
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
 
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif
if !exists('g:neocomplete#force_omni_input_patterns')
  let g:neocomplete#force_omni_input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php =
"\ '[^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?'
"let g:neocomplete#sources#omni#input_patterns.c =
"\ '[^.[:digit:] *\t]\%(\.\|->\)\%(\h\w*\)\?'
"let g:neocomplete#sources#omni#input_patterns.cpp =
"\ '[^.[:digit:] *\t]\%(\.\|->\)\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?'
 
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl =
\ '[^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?'
 
" For smart TAB completion.
"inoremap <expr><TAB>  pumvisible() ? "\<C-n>" :
"        \ <SID>check_back_space() ? "\<TAB>" :
"        \ neocomplete#start_manual_complete()
"  function! s:check_back_space() "{{{
"    let col = col('.') - 1
"    return !col || getline('.')[col - 1]  =~ '\s'
"  endfunction"}}} 

syntasticによるverilogの構文チェックを有効にする

syntasticは様々な言語の構文チェックをしてくれる便利なVimのプラグイン
最近Verilog HDLを書いているが、IDEのエディタは使いづらいため、Vimでコーディングしている。
しかし、IDEで構文チェックをする前のコーディング時に初歩的なバグを潰したいため、
Verilogでもsyntasticによる構文チェックを有効にした。
  • verilatorのビルド・インストール
Verilogの構文チェックにverilatorが必要なため、インストールする。
公式サイトのインストール手順そのままで大丈夫かも(未確認)
http://www.veripool.org/projects/verilator/wiki/Installing
実際行ったインストール手順のは、verilator-***.tgzの中のREADMEを参考にした
SystemCはCygwinで未対応らしいのでインストール手順から省いた
$ apt-cyg install make autoconf g++ flex bison
$ cpan install Verilog::Language
$ export SYSTEMPERL=/usr/lib/perl5/site_perl/5.14/x86_64-cygwin-threads/SystemC/
$ export SYSTEMPERL_INCLUDE=~/.cpan/build/SystemPerl-1.341-zUi4IV/src/
$ export VERILATOR_ROOT=
$ cd
$ wget http://www.veripool.org/ftp/verilator-3.853.tgz
$ tar xvzf verilator-3.853.tgz
$ cd verilator-3.853
$ make
$ make test
$ make install
インストールが完了すると、syntasticでVerilog編集時の構文チェックが機能するはず
ちなみに簡単な使い方
  • :SyntasticCheck で構文チェック実行
  • :Errors で構文ミスの一覧を表示
このページで公開しているvimrcのsyntasticの設定だと、
ソースを開いた時にも構文チェックをするようになってるはず。
最終更新:2015年03月02日 23:57