由于本人使用的是mac,所以一些配置可能與linux不同
安裝Vim
如果是linux
yum update -y
yum install vim -y
如果是mac
brew install vim
安裝Vundle
我們采用vundle安裝插件,這樣比較方便,如果~/.vim/bundle目錄沒有,自行創建即可
我們把vundle放到.vim/bundle/下面
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置~/.vimrc
如下是我自己的配置,復制粘貼即可,如果沒有該文件,也是自行創建即可
set nocompatible " be iMproved
" 搜索逐字符高亮
set hlsearch
set path+=**
set wildmenu
" leader 鍵
let mapleader = ','
"配置backspace鍵工作方式
set backspace=indent,eol,start
"搜索時,關鍵字高亮
set hls
"設置在Vim中可以使用鼠標 防止在Linux終端下無法拷貝
set mouse=a
" 復制粘貼到系統剪貼板
map <C-C> "+y<CR>
map <C-V> "+p<CR>
" 快速擴大分屏
map <C-M> :res +2<CR>
map <C-N> :vertical res +2<CR>
" 窗口縮放
"set modifiable
"設置ctags的快捷鍵為 Ctrl-F12
map <F10> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"顯示行號
set number
"設置在編輯過程中右下角顯示光標的行列信息
set ruler
"當一行文字很長時取消換行
"set nowrap
"在狀態欄顯示正在輸入的命令
set showcmd
"設置歷史記錄條數
set history=1000
"設置取消備份 禁止臨時文件生成
set nobackup
set noswapfile
"突出現實當前行列
set cursorline
"set cursorcolumn
"設置匹配模式 類似當輸入一個左括號時會匹配相應的那個右括號
set showmatch
"設置C/C++方式自動對齊
set autoindent
set cindent
"開啟語法高亮功能
syntax enable
syntax on
"設置搜索時忽略大小寫
set ignorecase
"設置Tab寬度
set tabstop=2
"設置自動對齊空格數
set shiftwidth=2
"設置按退格鍵時可以一次刪除4個空格
set softtabstop=4
set smarttab
"將Tab鍵自動轉換成空格 真正需要Tab鍵時使用[Ctrl + V + Tab]
set expandtab
"設置編碼方式
set encoding=utf-8
""自動判斷編碼時 依次嘗試一下編碼
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
"檢測文件類型
filetype on
"針對不同的文件采用不同的縮進方式
filetype indent on
"允許插件
filetype plugin on
"啟動智能補全
filetype plugin indent on
filetype off " required! /** 從這行開始,vimrc配置 **/
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'tpope/vim-rails.git'
Bundle 'L9'
"NerdTree
Bundle 'scrooloose/nerdtree'
let NERDTreeWinPos='left'
let NERDTreeShowBookmarks=1
let NERDTreeWinSize=31
let NERDTreeChDirMode=1
map <C-Y> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" nerdtree-git-plugin
Bundle 'Xuyuanp/nerdtree-git-plugin'
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "?",
\ "Staged" : "?",
\ "Untracked" : "?",
\ "Renamed" : "?",
\ "Unmerged" : "═",
\ "Deleted" : "?",
\ "Dirty" : "?",
\ "Clean" : "??",
\ "Unknown" : "?"
\ }
" TagBar use <F3>
Bundle 'majutsushi/tagbar'
let g:tagbar_ctags_bin='ctags' "ctags程序的路徑
let g:tagbar_width=35 "窗口寬度的設置
"let g:tagbar_left=1 "居左
let g:tagbar_right=1 "居左
let g:tagbar_type_ruby = {
\ 'kinds' : [
\ 'm:modules',
\ 'c:classes',
\ 'd:describes',
\ 'C:contexts',
\ 'f:methods',
\ 'F:singleton methods'
\ ]
\ }
map <C-I> :Tagbar<CR>
" 增強狀態欄
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'git://github.com/edkolev/tmuxline.vim.git'
set laststatus=2
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#whitespace#enabled=0
let g:airline_powerline_fonts = 1
"let g:airline_theme='ayu_mirage'
let g:airline_theme='dark'
map <C-H> :bp<CR>
map <C-L> :bn<CR>
map <C-B> :ls<CR>
Bundle 'scrooloose/nerdcommenter'
Bundle 'kien/ctrlp.vim.git'
Bundle 'dkprice/vim-easygrep.git'
Bundle 'git://github.com/tpope/vim-endwise.git'
"ctrlp
"<Leader>p搜索當前目錄下文件
let g:ctrlp_map = '<Leader>p'
let g:ctrlp_cmd = 'CtrlP'
"<Leader>f搜索MRU文件
nmap <Leader>f :CtrlPMRUFiles<CR>
"<Leader>b顯示緩沖區文件,并可通過序號進行跳轉
nmap <Leader>b :CtrlPBuffer<CR>
"設置搜索時忽略的文件
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|rvm)$',
\ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|pyc)$',
\ }
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_bottom = 1
"修改QuickFix窗口顯示的最大條目數
let g:ctrlp_max_height = 15
let g:ctrlp_match_window_reversed = 1
"設置MRU最大條目數為20
let g:ctrlp_mruf_max = 20
let g:ctrlp_follow_symlinks = 1
"默認使用全路徑搜索,置1后按文件名搜索,準確率會有所提高,可以用<C-d>進行切換
let g:ctrlp_by_filename = 0
"默認不使用正則表達式,置1改為默認使用正則表達式,可以用<C-r>進行切換
let g:ctrlp_regexp = 0
"自定義搜索列表的提示符
let g:ctrlp_line_prefix = '? '
let g:EasyGrepMode = 2 " All:0, Open Buffers:1, TrackExt:2,
let g:EasyGrepCommand = 0 " Use vimgrep:0, grepprg:1
let g:EasyGrepRecursive = 1 " Recursive searching
let g:EasyGrepIgnoreCase = 1 " not ignorecase:0
let g:EasyGrepFilesToExclude = "tags"
let g:EasyGrepFilesToExclude = "*.bak"
let g:EasyGrepFilesToExclude = "*~"
let g:EasyGrepFilesToExclude = "cscope.*"
let g:EasyGrepFilesToExclude = "*.a"
let g:EasyGrepFilesToExclude = "*.o"
let g:EasyGrepFilesToExclude = "*.pyc"
let g:EasyGrepFilesToExclude = "*.log"
" 縮進線條
Plugin 'Yggdroot/indentLine'
"let g:indentLine_showFirstIndentLevel = 1
"let g:indentLine_setColors = 0
Plugin 'SuperTab'
let g:SuperTabRetainCompletionType=2
" 主題插件
Plugin 'git://github.com/tomasr/molokai.git'
"molokai 主題 monokai的進化版
set t_Co=256
colorscheme molokai
let g:molokai_original = 1
let g:rehash256 = 1
Plugin 'Chiel92/vim-autoformat'
noremap <C-F> :Autoformat<CR>
" rspec插件
Plugin 'thoughtbot/vim-rspec'
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
let g:rspec_runner = "os_x_iterm2"
call vundle#end()
filetype plugin indent on " required! /** vimrc文件配置結束 **/
安裝插件
vim # 隨便一個地方打開vim
:PluginInstall # 安裝插件
插件安裝
配色文件放入~/.vim/colors(這里采用molokai)
配色文件需要放在.vim/colors下面
cp -rf ~/.vim/bundle/molokai/colors ~/.vim/
當前效果
配色方案也可以選擇自己喜歡的下載,github上很多
這是一張老圖,實際結果有出入
安裝PowerLineFonts字體
因為我們用的狀態欄插件是帶有箭頭符號的,但是需要安裝powerline字體才能顯示出來
直接去github下載下來安裝
https://github.com/powerline/fonts
(順便安利一下)因為我在vim裝了molokai主題,為了顏色統一,我也在terminal安裝了molokai主題,如果有興趣,可以去裝一個terminal的主題配色
安裝完之后,在terminal設置中,啟用我們安裝的字體和主題
terminal設置
重新打開vim,目前的效果
箭頭可以顯示
terminal
這里的terminal不僅采用了molokai配色,還使用了ZSH,如果切換到ZSH,可以看看這里Mac下采用zsh代替bash
以上就是terminal+vim的設置了
tmux 設置
安裝
brew install tmux
- 很多時候,我們需要在terminal中實現分屏
- tmux 允許隨時隨地斷開或重新接入會話(Session)
關于tmux更多的使用,可以去網上科普一下,這里只給出如何配置
tmux的配置就是一個 ~/.tmux.conf
文件,如果沒有需要自行創建
# 解除默認前綴
unbind C-b
# 設置自定義前綴
set -g prefix C-a
# 采用vim的操作方式
setw -g mode-keys vi
# 窗口序號從1開始計數
set -g base-index 1
# 開啟鼠標模式
set-option -g mouse on
# 通過前綴+KJHL快速切換pane
#up
bind-key k select-pane -U
#down
bind-key j select-pane -D
#left
bind-key h select-pane -L
#right
bind-key l select-pane -R
# panes 分割線顏色
set -g pane-border-bg colour236
set -g pane-border-fg colour236
set -g pane-active-border-bg colour232
set -g pane-active-border-fg colour232
以上是我目前使用的配置,同樣為了與vim的顏色統一,在vim的插件中,我采用了tmuxline.vim
這樣一個插件,它可以讓tmux
的狀態欄跟vim主題顏色一致,因為在上面我們已經裝了這個插件,所以不用再裝了
這里是vim插件影響了tmux,而不是一個tmux插件
tmux狀態欄效果
WechatIMG155.jpeg
配置中涉及的部分快捷鍵(部分快捷鍵在配置中未開啟,如果需要可以取消注釋)只隨便列出部分,更多的請從網上查資料學習
本人一直使用Mac,對Windows鍵盤不熟悉,以Mac上的快捷鍵組合列出(應該和windows差不多,大家可以對照以下)
# 左側目錄樹
ctrl + y # 在目錄樹窗口按大寫R,可以刷新目錄樹
# 右側函數樹
ctrl + i
# Buffer左右切換
ctrl + h # 向左移動
ctrl + l # 向右移動
# ctags生成
F10
# 自動補全,插件中沒有使用專門的補全插件,全是用的ctags
ctrl + p 或 tab # insert 狀態下 【由于裝了superTab,也可以直接tab鍵補全】
# 文件查找
ctrl + p # normal 狀態下 【當前目錄全局】
ctrl + f # 【從最近搜索的文件中查找】
ctrl + b # 從當前buffer中查找
# 模糊搜索
:Grep xxxx # normal 狀態下,我們leader鍵已經改為了“,”【逗號】
或者光標移到一個需要搜索的單詞上,按 ,vv
# 替換
:Replace xxxx yyyy # normal 狀態下
# 跳轉到函數定義處
光標移到需要跳轉的單詞上,按下 ctrl + ] # 需要先生成 ctags 文件
回到跳轉前位置,按下 ctrl + t
# 關閉當前buffer
:bd
# 復制到系統剪貼板
ctrl + c
# 從系統剪貼板粘貼
ctrl + v
# 垂直分屏
ctrl + w + v
# 水平分屏
ctrl + w + s
# 關閉分屏
ctrl + w + c
# 水平快速擴大分屏
ctrl + n
# 垂直快速擴大分屏
ctrl + m
# easymotion的使用,我們leader鍵已經改為了“,”【逗號】
,,s + 關鍵字
# 更多詳細配置大家可以自行閱讀配置文件,或者根據自己需要更改配置