Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Thursday, August 29, 2013

Vim: Converting tabs into spaces

`set expandtab` option automatically converts tabs into spaces. However, the command does not affect the tabs existed before the option is set.

To convert such tabs into spaces, issue :retab

Ref:
Converting tabs to spaces
http://vim.wikia.com/wiki/Converting_tabs_to_spaces

Friday, May 31, 2013

Solarized, Uniform Color Scheme

I've switched my vim's color scheme from oceandeep to solarized. Oceandeep is an eye-friendy dark color scheme great for people who prefer not to be distracted by highlighted text. However, it makes you feel a bit awkward when you launch vim from a console because it supports only gvim. I got hungry for "uniformity", and solarized came in.

Solarized - Precision colors for machines and people
http://ethanschoonover.com/solarized

Solarized is a color scheme maintained by Ethan Schoonover provides uniformity to your environment; it supports not only editors (not limited to vim!) but also other system development tools like terminal emulators and IDEs.

I've changed color schemes for vim and iTerm2, and they look coordinated. Awesome.

Monday, August 27, 2012

Color scheme for vim (not for gvim)

I was always wondering why some color scheme does work on gvim (MacVim) but not on vim launched from terminal. That's the reason.

Using GUI color settings in a terminal
http://vim.wikia.com/wiki/Using_GUI_color_settings_in_a_terminal

Sunday, August 19, 2012

Vim: set path to working directory

Add the following to .vim


" Add the current file's directory to the path if not already present.
BufRead *
  \ let s:tempPath=escape(escape(expand("%:p:h"), ' '), '\ ') |
  \ exec "set path+=".s:tempPath

Ref: Set working directory to the current file

With previous make and javac binding, you can compile and execute Java code from vim with
  :mak
  :!java FILENAME

Saturday, August 18, 2012

Vim: Binding :make and javac

Add the following to your .vimrc

filetype on
autocmd FileType java set makeprg=javac\ %

You can make .java files with :make command.
To view errors, try ":cope", ":ccl", ":cc", ":cn", ":cp", etc.

Thursday, August 16, 2012

Tuesday, March 20, 2012

Change of .vimrc

Change log:
1) Added tab settings for html
2) Enabled filetype plugins
3) Enabled matchit

  1 "
  2 " This file (.vimrc) is modified on 2012/3/19
  3 "
  4
  5 " General
  6 set number " to display lines
  7 set title " display filename on the title bar
  8 set ignorecase " search not casesensitively
  9 set showmatch " hilight a pair of parenthesis and braces
 10 set matchtime=2 " limit the showmatch's hilight time, ms
 11 set wildmenu " compliment vim's commandline instructions
 12 set tabstop=4
 13 set shiftwidth=4
 14 set softtabstop=4
 15 set autoindent " Enable autoindent
 16 set ruler  " Ruler on
 17 set incsearch
 18 set hlsearch
 19 set backup
 20 set backupdir=~/.tmp_vim
 21 set dir=~/.tmp_vim
 22
 23 " Plugins
 24 filetype on           " Enable filetype detection
 25 filetype indent on    " Enable filetype-specific indenting
 26 filetype plugin on    " Enable filetype-specific plugins
 27 runtime macros/matchit.vim
 28
 29 " Ruby
 30 autocmd FileType ruby,eruby compiler ruby
 31 autocmd FileType ruby,eruby set tabstop=2
 32 autocmd FileType ruby,eruby set shiftwidth=2
 33 autocmd FileType ruby,eruby set softtabstop=2
 34 autocmd FileType ruby,eruby set expandtab
 35
 36 " HTML
 37 autocmd FileType html set tabstop=2
 38 autocmd FileType html set shiftwidth=2
 39 autocmd FileType html set softtabstop=2
 40
 41
 42 " For GUI
 43 if has("gui_running")
 44   colorscheme oceandeep
 45   set clipboard+=unnamed  " Yanks to clipboard
 46 endif
 47

Wednesday, January 18, 2012

Key bind for Vim

In an insert mode,
  "C - [", "C - {" are bound to ESC
  "C - h" is bound to BS
  "C - m" is bound to Enter

.vimrc の見直し

今回の変更で set clipboard+=unnamed のオプションを追加

"
" This file (.vimrc) is modified on 2012/1/18
"
set number " to display lines
set title " display filename on the title bar
set ignorecase " search not casesensitively
set showmatch " hilight a pair of parenthesis and braces
set matchtime=2 " limit the showmatch's hilight time, ms
set wildmenu " compliment vim's commandline instructions
set softtabstop=4
set expandtab
set autoindent " Enable autoindent
set ruler  " Ruler on
if has("gui_running")
  colorscheme oceandeep
  set clipboard+=unnamed  " Yanks to clipboard
  autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
  autocmd FileType ruby,eruby set tabstop=2
  autocmd FileType ruby,eruby set shiftwidth=2
  autocmd FileType ruby,eruby set softtabstop=2
endif

Tuesday, February 17, 2009

MacVim: Cocoaベースの Vim

恥ずかしながら Cocoa ベースの Vim が存在することに今頃きづきました。
いままでは Vim for Mac OS X を...。まぁ、機能には大差ないわけですが。

MacVim
http://code.google.com/p/macvim/

インストール手順は下記のとおり
  1. 最新の安定版をダウンロード
  2. 解凍後
  3. MacVim.app アプリケーションディレクトリにコピー

mvim という、シェルから MacVim を起動するスクリプトが付属していたので
/usr/local/bin に置きました。

既存の Vim の置き換えは、
sudo mv /usr/bin/vim /usr/bin/vim-6.2
sudo ln -s /usr/local/bin/mvim /usr/bin/vim
にてOK。これで view も vimdiff も通るようになります。

MacVim の設定ファイル名は vim と同様、
全体設定
GUI: /Applications/MacVim.app/Contents/Resources/vim/gvimrc
CLI: /Applications/MacVim.app/Contents/Resources/vim/vimrc

ユーザー個別設定
GUI: ~/.gvimrc
CLI: ~/.vimrc
となります。

mvim のスクリプト、どのような名前で呼び出されたかによって GUI と CLI 、どちらのモードで
起動するかを制御しているようです。勉強になりました。

mvimより抜粋
# Next, peek at the name used to invoke this script, and set options
# accordingly.

name="`basename "$0"`"
gui=
opts=

# GUI mode, implies forking
case "$name" in m*|g*|rg*) gui=true ;; esac

# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac

# vimdiff and view
case "$name" in
*vimdiff)
opts="$opts -dO"
;;
*view)
opts="$opts -R"
;;
esac

Thursday, July 17, 2008

vimでインデントなしで貼り付けるには

:set paste!
というオプションを指定。
逆にインデントされるようにするには
:set paste

Tuesday, March 4, 2008

VIMのよさげなカラースキーム

Vimデフォルトのカラースキームがしっくりこず、自分の好みを探してみました。
ピピッときたのは Oceandeep 、この配色が気に入って今ではWindowsの時もVim。

Oceandeepを設定する際は、colorscheme oceandeep を .gimrc に記述する。

.vimrcに
colorscheme oceandeep
という記述を加えて vim を起動しても
文字色は odeandeep の指定どおり、背景色がターミナルの色のまま
という状態になる。
この設定での gvim の動作はWindowsとMacOS Xで異なっていて
Windows: oceandeep のカラースキームどおり
MacOS X: 文字色は odeandeep の指定どおり、背景色がターミナルの色のまま
となる。
MacOSでは、gvim上から
:colorscheme oceandeep
とやれば意図した動作になるのにもかかわらず .vimrc の記述内容は完全に反映されないという
不可解に見える動作をする。

.vimrc から .gvimrc へ
colorscheme oceandeep
の記述を移すと意図した通りの動作に。
oceandeep がgvimのみ対応するカラースキームだったために今回の事象が起こった、のかな?

現在 .vimrc には
colorscheme vividchalk
という記述を入れています。
黒いターミナル背景色との相性がステキ。

参考: VIM for Ruby on Rails development
http://anilwadghule.com/blog/2007/07/09/vim-for-ruby-on-rails-development/

Saturday, March 1, 2008

MacBook+Vim7.0でvim-rubyのインデント

vimのプラグイン、vim-ruby の設定ファイルにあるモードラインの設定が有効にならない件について。

/Applications/Vim.app/Contents/Resources/vim/vimfiles/ftplugin/ruby.vim のインデントの設定を
モードラインではなく、set を使用してパラメータ指定するよう変更。
これで ruby のファイルを編集している時のみインデント、エキスパンドタブが反映されるようになりました。
モードラインのことが分からなくて何時間も悩んだのに...。

変更前
230 " vim: expandtab sw=2 sts=2 ts=2 ff=unix:
変更後
230 set expandtab
231 set sw=2
232 set sts=2
233 set ts=2
234 set ff=unix
# 数字は行番号

残る疑問は
  • どうしてモードラインが有効にならないのか
  • 改行コードの設定はこのままでよいのか
改行コードについて検索してみると、下記の記述を発見。
http://www.ac.cyberhome.ne.jp/~yakahaira/vimdoc/usr_23.html

よくわからないから、とりあえずこのままで。

Thursday, February 28, 2008

Vim7.0をMacBookにインストール

RubyのスクリプトをVimを使って楽に書くため、Vim7.0とRuby用のプラグインをMacBookに入れる。
パッケージインストールの動きがよくわからず、なんだかんだで時間がかかった。

Vim7.0 インストール手順 及び ソース
http://macvim.org/OSX/index.php
# www.vim.orgからMacOSにインストールする方法をたどって行くとたどり着くところ
書いてある通りにインストール

vim7.0をパッケージインストールしただけでは /usr/bin/vim の内容を書き換えてくれなかったので
/usr/bin/vimからインストールしたバイナリに向けてシンボリックリンクを作成。
sudo mv /usr/bin/vim /usr/bin/vim6.2
sudo chown root:wheel /Applications/Vim.app/Contents/MacOS/Vim
sudo ln -s /Applications/Vim.app/Contents/MacOS/Vim /usr/bin/vim

これで view, vimdiff 等も問題なくvim7.0にて開くようになる。

MacOS版vim7.0同梱のコマンドライン上からgvimを起動するスクリプトを /usr/bin にコピー
cd ~/Desktop/vim70/ " 展開したソースはユーザーのデスクトップ上に保存してあった
chmod 755 gvim
sudo chown root:wheel gvim
sudo mv gvim /usr/bin
同じく同梱のgvimを複数インスタンス起動出来る、というappをダッシュボードにコピー

Ruby用のプラグインインストール

sudo gem install vim-ruby
sudo /usr/local/bin/vim-ruby-install.rb

Possible Vim installation directories:
1) /Users/kaede/.vim
2) /Applications/Vim.app/Contents/Resources/vim/vimfiles

Please select one (or anything else to specify another directory): 2

.vimrcの追記部分
" Followings are my original configurations
set number " to display lines
set title " display filename on the title bar
set ignorecase " search not casesensitively
set showmatch " hilight a pair of parenthesis and braces
set matchtime=2 " limit the showmatch's hilight time, ms
set wildmenu " compliment vim's commandline instructions
set backupdir=/Applications/Vim.app/tmp_working " designame backup directory
let &directory=&backupdir " designame tmp file directory
source $VIMRUNTIME/macros/matchit.vim " enable matchit plugin
/Applications/Vim.app/tmp_working は新しく作ったディレクトリ
source $VIMRUNTIME/macros/matchit.vim はMacOS X 用のvim7.0同梱のmatchitプラグインの設定

参考: Ruby用のプラグインインストール
http://sssdiary.at.webry.info/200611/article_7.html


あれこれさわっても
/Applications/Vim.app/Contents/Resources/vim/vimfiles/ftplugin/ruby.vim
の最後にあるモードラインが有効にできない。
" vim: expandtab sw=2 sts=2 ts=2 ff=unix:
とあるからrubyと認識されたファイルならタブが2文字に変わる、と理解しているが...。

~/.vimrc には set modeline という記述を足してみたり、参考のURLの真似をしてみたけれど、はて。