Vim + Zsh + Tmux 完美配合

Purpose


本文主要為了記錄個人的日常使用軟件配置, 以在切換設備時根據(jù)本文快速配置自己習慣的配置, 所以不涉及任何的操作教程, 以下所有配置主要針對在Ubuntu上操作

Vim


安裝 vundle

# 先從 github 中下載 vundle 放到.vim目錄中
git clone http://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  

# 接下來配置 vimrc 文件, 添加下列配置信息
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" Below here to add the vundle what I want

# 配置好 vimrc 文件后保存退出, 重新打開 vim, 并在 vim 中執(zhí)行 ex 命令
BundleInstall

# vundle 常用命令
BundleList             -列舉列表(也就是.vimrc)中配置的所有插件  
BundleInstall          -安裝列表中的全部插件  
BundleInstall!         -更新列表中的全部插件  
BundleSearch foo       -查找foo插件  
BundleSearch! foo      -刷新foo插件緩存  
BundleClean            -清除列表中沒有的插件  
BundleClean!           -清除列表中沒有的插件  

最終配置

" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd        " Show (partial) command in status line.
"set showmatch      " Show matching brackets.
"set ignorecase     " Do case insensitive matching
"set smartcase      " Do smart case matching
`代碼`"set incsearch      " Incremental search
"set autowrite      " Automatically save before commands like :next and :make
"set hidden     " Hide buffers when they are abandoned
"set mouse=a        " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

set fileencodings=utf-8
set termencoding=utf-8

" 解決和tmux的顏色沖突問題
colorscheme pablo

set rnu
set nu
set tabstop=4 
set softtabstop=4 
set shiftwidth=4 
set expandtab 
set autoindent 

inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {}<Esc>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=ClosePair('}')<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
inoremap <TAB> <c-r>=SkipPair()<CR>
nmap <F5> :!python3 %<CR>

nmap <F2> :!ici <C-R><C-W><CR>      " 翻譯當前光標下的單詞

" 自動補全括號
function ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endf

" 自動補全引號
function QuoteDelim(char)
    let line = getline('.')
    let col = col('.')
    if line[col - 2] == "\\"
        return a:char
    elseif line[col - 1] == a:char
        return "\<Right>"
    else
        return a:char.a:char."\<Esc>i"
    endif
endf

" 按 Tab 跳出括號和引號
function SkipPair()  
    if getline('.')[col('.') - 1] == ')' || getline('.')[col('.') - 1] == ']' || getline('.')[col('.') - 1] == '"' || getline('.')[col('.') - 1] == "'"
        return "\<ESC>la"  
    else  
        return "\t"  
    endif  
endf

filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" Below here to add the vundle what I want

" Emmet html標簽快速生成
Plugin 'mattn/emmet-vim'
let g:user_emmet_mode = 'i'
let g:user_emmet_expandabbr_key = '<C-b>'
let g:user_emmet_next_key = '<C-d>'
let g:user_emmet_prev_key = '<C-t>'
let g:user_emmet_install_global = 1

" autocmd Filetype html,css,php,tpl,python,javascript,ruby EmmetInstall
let g:user_emmet_settings = {
            \ 'php' : {
            \ 'extends' : 'html',
            \ 'filters' : 'c',
            \ },
            \ 'xml' : {
            \ 'extends' : 'html',
            \ },
            \ 'haml' : {
            \ 'extends' : 'html',
            \ },
            \}

" NERDTree目錄樹插件
Plugin 'scrooloose/nerdtree'
nmap <F4> :NERDTree  <CR>
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=20
let g:NERDTreeShowLineNumbers=1

" NERDCommenter快速注釋插件
Plugin 'scrooloose/nerdcommenter'

" 變量函數(shù)樹
" Plugin 'vim-scripts/taglist.vim'

" 快速添加符號
Plugin 'tpope/vim-surround'
" 使surround可重復
Plugin 'tpope/vim-repeat'

" 多行光標
Plugin 'terryma/vim-multiple-cursors'

" JS
Plugin 'chemzqm/vim-jsx-improve'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'pangloss/vim-javascript'

" Rails
Plugin 'tpope/vim-rails'

" 代碼對齊
Plugin 'godlygeek/tabular'

" YouCompleteMe補全
Plugin 'Valloric/YouCompleteMe'

" YouCompleteMe補全配置
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_global_ycm_extra_conf'
" 修改ycm按鍵
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
" let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
" 配置成像一樣IDE
set completeopt=longest,menu
" 退出insert模式后自動隱藏補全提示框
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" 回車鍵選擇補全項
inoremap <expr> <CR>  pumvisible() ? "\<C-y>\<C-o>:pclose\<CR>\<C-o>l" : "\<CR>"
" 禁用補全
nnoremap <leader>y :let g:ycm_auto_trigger=1<CR>
" 注釋和字符串中的文字也會被收入補全
let g:ycm_collect_identifiers_from_comments_and_strings = 1

" 重命名文件
Plugin 'danro/rename.vim'

" 語法檢查
" Plugin 'vim-syntastic/syntastic'

" Ctrlp 文件模糊查找
Plugin 'ctrlpvim/ctrlp.vim'

Zsh


安裝 zsh

sudo apt-get install zsh

將 zsh 設置成默認的 shell

chsh -s /bin/zsh

配置 oh-my-zsh

# 通過 curl 安裝
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

# 通過 wget 安裝
wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

# 手動安裝
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh        # 克隆 oh-my-zsh 項目文件

# 備份自己的配置
cp ~/.zshrc ~/.zshrc.bk

# 將 oh-my-zsh 的模板配置拷貝出來
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Tmux


安裝 tmux

sudo apt-get install tmux

配置tmux

為了配合 vim 使用, 配置成類似于 IDE 的下方或右方顯示終端輸出結果, 在 Home 目錄下添加布局配置文件

右方布局 ~/.tmux/horizontal_split_layout

selectp -t 0                               # 選中第0個窗格
splitw -h -p 20 -c "#{pane_current_path}"  # 垂直分屏

下方布局 ~/.tmux/horizontal_split_layout

selectp -t 0    # 選中第0個窗格
splitw -v -p 15 -c "#{pane_current_path}" # 將其分成左右兩個

然后在 tmux 配置文件中引用布局并綁定對應按鍵, 并添加上自己習慣的按鍵操作配置, 最終 tmux 配置如下

# 加載布局文件
bind q source-file ~/.tmux/horizontal_split_layout
bind z source-file ~/.tmux/vertical_split_layout

# 重新加載配置文件
bind C-r source-file ~/.tmux.conf \; display "Refleshed Configure!"

# 設置成vim模式
setw -g mode-keys vi

# 將面板切換設置成hjkl
bind-key k select-pane -U # up
bind-key j select-pane -D # down
bind-key h select-pane -L # left
bind-key l select-pane -R # right

# 設置鼠標滾動
# set-window-option -g mode-mouse on # (setw其實是set-window-option的別名)

# 將觸發(fā)鍵改成C-a
set -g prefix C-a
unbind C-b

# 將復制模式設置成vim的復制模式
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"

# 設置終端顏色
# set -g default-terminal "screen-256color"
# set -g default-terminal "linux"
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌炮捧,老刑警劉巖秦爆,帶你破解...
    沈念sama閱讀 216,744評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件砂心,死亡現(xiàn)場離奇詭異璧亚,居然都是意外死亡,警方通過查閱死者的電腦和手機能扒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,505評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來辫狼,“玉大人初斑,你說我怎么就攤上這事∨虼Γ” “怎么了见秤?”我有些...
    開封第一講書人閱讀 163,105評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長真椿。 經(jīng)常有香客問我鹃答,道長,這世上最難降的妖魔是什么突硝? 我笑而不...
    開封第一講書人閱讀 58,242評論 1 292
  • 正文 為了忘掉前任测摔,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘锋八。我一直安慰自己浙于,他們只是感情好,可當我...
    茶點故事閱讀 67,269評論 6 389
  • 文/花漫 我一把揭開白布挟纱。 她就那樣靜靜地躺著羞酗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪樊销。 梳的紋絲不亂的頭發(fā)上整慎,一...
    開封第一講書人閱讀 51,215評論 1 299
  • 那天,我揣著相機與錄音围苫,去河邊找鬼裤园。 笑死,一個胖子當著我的面吹牛剂府,可吹牛的內容都是我干的拧揽。 我是一名探鬼主播,決...
    沈念sama閱讀 40,096評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼腺占,長吁一口氣:“原來是場噩夢啊……” “哼淤袜!你這毒婦竟也來了?” 一聲冷哼從身側響起衰伯,我...
    開封第一講書人閱讀 38,939評論 0 274
  • 序言:老撾萬榮一對情侶失蹤铡羡,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后意鲸,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體膏潮,經(jīng)...
    沈念sama閱讀 45,354評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡抱怔,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,573評論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片崇众。...
    茶點故事閱讀 39,745評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡榄审,死狀恐怖巾遭,靈堂內的尸體忽然破棺而出若河,到底是詐尸還是另有隱情,我是刑警寧澤募强,帶...
    沈念sama閱讀 35,448評論 5 344
  • 正文 年R本政府宣布株灸,位于F島的核電站,受9級特大地震影響钻注,放射性物質發(fā)生泄漏蚂且。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,048評論 3 327
  • 文/蒙蒙 一幅恋、第九天 我趴在偏房一處隱蔽的房頂上張望杏死。 院中可真熱鬧,春花似錦、人聲如沸淑翼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,683評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽玄括。三九已至冯丙,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間遭京,已是汗流浹背胃惜。 一陣腳步聲響...
    開封第一講書人閱讀 32,838評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留哪雕,地道東北人船殉。 一個月前我還...
    沈念sama閱讀 47,776評論 2 369
  • 正文 我出身青樓,卻偏偏與公主長得像斯嚎,于是被迫代替她去往敵國和親利虫。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,652評論 2 354

推薦閱讀更多精彩內容