vimに入門してみる
小指の疲労感が深刻なレベルに達しているのでvimを練習しておくことにした。
vimperatorを弄っていたのでコマンド群にそれほど抵抗なく入門できたと思う。
基本的にMacVimです。
macvim - Project Hosting on Google Code
すごく適当なモードの理解
ノーマルモード(esc) - インサートモード(i)
|
ビジュアルモード(v)
各モードからノーマルモードに移るには
ノーマルモードで:打ってから適当にコマンド飛ばせる
コマンドがEmacsのelispなんかと違って非常にわかりやすい
キーバインド
| i | インサートモードへ |
| v | ビジュアルモードへ |
| : | コマンドラインでへ |
| hjkl | 左下上右 |
| yy | 行コピー |
| p | 張りつけ |
| dd | 行削除 |
ファイル操作
| :w | 保存 |
| :e filename | 開く |
!をつけると強制力を持たせることができる。:w!など
画面操作
| 縦分割 | |
| 横分割 | |
| 分割解除 | |
| バッファ移動 |
いまいちヴィジュアルモードの存在意義がわかってない
Emacsからの移行
とりあえず慣れるまでEmacsからの移行用に以下のキーバインドを追加した。
vimの設定ファイルは ~/.vimrc
map <C-x><C-f> :e<Space> map <C-x><C-s> :w!<CR> map <C-g> <esc> map <C-x>2 <C-w>s map <C-x>3 <C-w>v map <C-x>1 <C-w>o
なんのためにvim使ってんだ、って話ですが
vimrc
適当に切り貼りしたvimrc
まだ全然調べてないので暫定版
~/.vimrc
====================
"vi compatible mode off
set nocompatible
"share clipboard with other applications
set clipboard=unnamed
"number ruler
set number
"define backup dir
set backupdir=$HOME/vimbackup
set directory=$HOME/vimbackup
" ignore case in search
set ignorecase
" consider case if the search pattern contains uppercase
set smartcase
" incsearch
set noincsearch
" tab = 4space
set tabstop=4
" tab is tab. doesnot expand to space.
set noexpandtab
" allow autoindent
set autoindent
" backspace can delete linefeed, tab, space
set backspace=2
" hilight another brace if the cursor was on it
set showmatch
" add extra features to command-line
set wildmenu
" show whitespace chars as following
set lcs=tab:>-,eol:$,trail:_,extends:\
" doesnt allow textwrap
set nowrap
" show status line
set laststatus=2
" commandline height
set cmdheight=1
" show commandline
set showcmd
" show filename on titlebar
set title
" hilight cursor line
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
set cursorline
" hilight searched chars
set hlsearch
" make me go to next line
set whichwrap=b,s,h,l,<,>,[,]
" statusline
set statusline=%<%f\ %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%l,%c%V%8P
"number of screen lines to show around the cursor
set scrolloff=2
" minimal number of columns to keep left and right of the cursor
set sidescrolloff=3
" first directory is where the buffer exists
set browsedir=buffer
" hide toolbars
set guioptions-=T
" use console dialog instead of popup dialogs for simple choice
set guioptions+=c
" show japanese charactors (this works only if this file was saved as Sfhit-jis)
highlight ZenkakuSpace cterm=underline ctermfg=lightblue guibg=#555555
au BufNewFile,BufRead * match ZenkakuSpace / //
" delete buffer but splitted window remains there
command! Kwbd let kwbd_bn= bufnr("%")|enew|exe "bdel ".kwbd_bn|unlet kwbd_bn
command! FKwbd let kwbd_bn= bufnr("%")|enew|exe "bdel! ".kwbd_bn|unlet kwbd_bn
"change hjkl behavior for line wrap
noremap j gj
noremap k gk
noremap gj j
noremap gk k
" tab change
map <F2> <ESC>:previous<CR>
map <F3> <ESC>:bnext<CR>
map <F4> <ESC>:bwipe<CR>
map <F9> <ESC>:Kwbd<CR>
map <S-F9> <ESC>:FKwbd<CR>
set visualbell
"user map
"from Emacs
nmap <C-x><C-f> :e<Space>
map <C-x><C-s> :w!<CR>
map <C-g> <esc>
map <C-x>2 <C-w>s
map <C-x>3 <C-w>v
map <C-x>1 <C-w>o