Bear Su's Blog

My Vim 設定

紀錄一下我的 vim 設定,還在學習中,所以會不定期更新。


安裝 Vundle


install dependency in ubuntu

sudo apt-get install git curl

Install Vundle

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Vundle:Vim Plugin 自動下載、安裝、更新與管理工具(Vim Bundle)


Configure Vim


編輯 ~/.vimrc

set nocompatible              " be iMproved, required
set noswapfile
set encoding=utf-8

filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'

Plugin 'scrooloose/nerdtree'
Plugin 'vim-ruby/vim-ruby'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-dispatch'
Plugin 'thoughtbot/vim-rspec'
Plugin 'vim-scripts/tComment'
Plugin 'ap/vim-css-color'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
Plugin 'honza/vim-snippets'
Plugin 'ntpeters/vim-better-whitespace'

filetype plugin indent on     " required

" RSpec.vim mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>

" common setting
syntax on
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set number
set cindent
set autoindent

" 在所有 window 顯示狀態列
set laststatus=2

" 提示游標所在的行
set cursorline
" set cursorcolumn

" 高光搜尋
set hlsearch

" default show hidden files
let NERDTreeShowHidden=1
" use F3 toggle
noremap <F3> <ESC>:NERDTreeToggle<CR>
" user F5 to run rake
noremap <F5> <ESC>:!rake<CR>

" auto remove unwant space:w
autocmd BufWritePre * StripWhitespace

Plugin list

nerdtree

檔案導覽,文件

vim-ruby

Ruby 支援,文件

vim-rails

Rails 支援,文件

vim-bundler

Bundler 指令支援,文件

vim-dispatch

非同步建置與測試,文件

vim-rspec

Rspec 支援,文件

tComment

提供註解的熱鍵,文件

vim-css-color

可以在 vim 中看到色碼的顏色

vim-addon-mw-utils

For vim-snipmate

vim-tlib_vim

For vim-snipmate

vim-snipmate

提供一些常用的程式碼片段,按 tab 補齊,讓寫 code 稍微快一點,文件

vim-snippets

支援更多程式語言的程式碼片段

vim-better-whitespace

顯示行尾多餘空白,並提供移除功能


Install Plugins

Run command in terminal:

vim +PluginInstall +qall

Or run command in vim

:PluginInstall

FAQ


Q: Occur error when edit git commit in MAC OSX

A: run git config --global core.editor /usr/bin/vim to fix.

Fixing “There was a problem with the editor ‘vi’” for Git on Mac OS X Snow Leopard


參考



如果覺得這篇文章對您有所幫助,歡迎贊助我一杯咖啡 ☕️

祝您有美好的一天 ❤️