操做
文件打開與多文件
:e f:\demo.py |
打開一個文件 |
:tabnew f:\demo.py |
打開一個標籤 |
:bn |
下一個文件 |
:bp |
上一個文件 |
:b3 |
切換至第 3 個文件 |
:b3.py |
切換至 3.py 文件 |
:ls |
列出打開的文件,帶序號 |
:bd! |
關閉當前文件不關閉 gvim 窗口 |
:close |
關閉窗口 |
光標移動
10 + enter |
向下移動 10 行 |
^ | 0 |
移至當前行的開頭位置 |
$ |
移至當前行的結尾位置 |
w |
將光標移到下一個單詞的開頭(W 包含標點符號) |
b |
將光標移到上一個單詞的開頭(B 包含標點符號) |
( |
將光標移到當前或上一句子的開頭 |
) |
將光標移到下一句子的開頭 |
{ |
將光標移到上一段落的開頭 |
} |
將光標移到下一段落的開頭 |
ctrl + f |
下一頁 |
ctrl + b |
上一頁 |
插入模式
i |
光標前插入 |
I |
行首插入 |
a |
光標後插入 |
A |
行尾插入 |
R |
光標前替換 |
o |
下方新開一行 |
O |
上放新開一行 |
撤銷與重作
u |
退回前一個動做 |
ctrl + r |
重複前一個動做 |
:e! |
還原上次保存的狀態 |
刪除與剪切
x |
向後刪除一個字符 |
X |
向前刪除一個字符 |
dd |
剪切光標所在的那一行 |
d$ |
刪除當前行光標後的內容 |
ndd |
剪切光標所在的向下n行(n爲數字) |
D |
剪切光標所在行的內容(不刪除行) |
d1G |
剪切光標所在行到第一行的全部數據,包含當行。 |
dG |
剪切光標所在行到末行的全部數據,包含當行。 |
查找與替換
在正常模式下按 / 便可進入查找模式php
/demo |
查找 demo,按 n 下一個,按 N 上一個 |
g |
全局替換 |
i |
大小寫不敏感 |
I |
大小寫敏感 |
gc |
確認 |
:s/1/2/g |
當前行 1 替換成 2,g 爲全部出現都會被替換 |
:%s/1/2/g |
全文 1 替換成 2,g 爲全部出現都會被替換, |
:'<,'>s/1/2/g |
選區 1 替換成 2,g 爲全部出現都會被替換 |
:.,+2s/1/2/g |
當前行至 +2 行1 替換成 2,g 爲全部出現都會被替換 |
可視化模式
v |
字符可視化模式 |
V |
行可視化模式 |
ctrl + q |
塊可視化模式 |
複製粘貼
yy |
複製當前行 |
2yy |
複製兩行 |
y2w |
複製兩個單詞 |
p |
光標後粘貼 |
P |
光標前粘貼 |
shift + inset |
粘貼剪切板內容 |
註釋與取消註釋
一、命令行模式下光標固定在第一列 Ctrl + q 進入可視化塊模式html
二、上下移動光標選擇要註釋的行java
三、大寫 i 進入插入模式而後輸入註釋符 #python
四、按兩次 esc 就註釋成功了linux
五、取消註釋一樣操做前兩步驟,選中後按 d 刪除ios
多行縮進
shift + v 進入可視化模式上下選擇須要縮進或取消縮進的行 shift + < 或者 shift + > 便可c++
分割窗口
:vs |
縱向分隔 |
:sp |
橫向分隔 |
ctrl + w + w |
切換窗口 |
:qa |
關閉全部窗口 |
保存文件與退出
:w |
保存當前文件並留在編輯器中 |
:w! |
若文本爲只讀模式,強制保存 |
:q |
退出當前文件,僅在沒有未保存更改的狀況下。 |
:q! |
退出當前文件,忽略任何未保存的修改 |
:wq |
保存並退出當前文件 |
ZZ |
保存並退出當前文件 |
配置詳解
在 vim 根目錄 _vimrc 中設定git
set fileencoding=utf-8 |
當前文件設置爲 utf-8 編碼 |
set nu |
行號開關 |
set wrap! |
關閉詞折行 |
colorscheme monokai |
代碼高亮 |
syntax on |
語法自動 |
set nocompatible |
能夠回退多步 |
set guioptions-=m |
隱藏菜單欄 |
set guioptions-=T |
隱藏工具欄 |
set guioptions-=r |
隱藏右側滾動條 |
set ai |
自動縮進 |
set sts=4 |
縮進 4 個空格 |
set shiftwidth=4 |
縮進 4 個空格 |
set expandtab |
用恰當的空格來填充這個 tab |
set guifont |
查詢當前字體 |
set gfn=Microsoft_YaHei_Mono:h11:cGB2312 |
設置字體 |
set ruler set rulerformat=%20(%2*%<%f%= %m%r %3l %c %p%%%) |
在狀態行上顯示光標所在位置的行號和列號 |
set cmdheight=2 |
末行命令行高度 |
set backspace=2 |
使用回格鍵(backspace) |
set ignorecase |
在搜索的時候忽略大小寫 |
set laststatus=2 |
老是顯示狀態行 |
autocmd GUIEnter * simalt ~x |
窗口最大化 |
set lines=37 columns=120 |
窗口自定義大小 |
map <F11> <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR> |
全屏 |
tab 縮進爲 4個空格
set ts=4
set expandtab
set autoindent
一鍵執行腳本
! |
執行命令 |
% |
當前打開文件含後綴名的絕對路徑 |
%< |
當前打開文件絕對路徑中不含後綴的文件名 |
func CompileRun()
exec "w"
if &filetype == "python"
exec " !python % "
elseif &filetype == "c"
exec " !gcc % -o %< "
exec " !%< "
elseif &filetype == "cpp"
exec " !g++ % -o %< "
exec " !%< "
elseif &filetype == "java"
exec " !javac % "
exec " !java % "
elseif &filetype == "html"
exec " !% "
elseif &filetype == "go"
exec " !go run % "
endif
endfunc
map <F9> :call CompileRun()<CR>
字典補全
set dictionary=$vim\dict.txt |
設置字典路徑 |
English
read write easy
python
c
配置文件
vim_vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 糾結
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 顯示相關
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set shortmess=atI " 啓動的時候不顯示那個援助烏干達兒童的提示
"winpos 5 5 " 設定窗口位置
"set lines=40 columns=155 " 設定窗口大小
"set nu " 顯示行號
set go= " 不要圖形按鈕
"color asmanian2 " 設置背景主題
set guifont=Courier_New:h10:cANSI " 設置字體
"syntax on " 語法高亮
autocmd InsertLeave * se nocul " 用淺色高亮當前行
autocmd InsertEnter * se cul " 用淺色高亮當前行
"set ruler " 顯示標尺
set showcmd " 輸入的命令顯示出來,看的清楚些
"set cmdheight=1 " 命令行(在狀態行下)的高度,設置爲1
"set whichwrap+=<,>,h,l " 容許backspace和光標鍵跨越行邊界(不建議)
"set scrolloff=3 " 光標移動到buffer的頂部和底部時保持3行距離
set novisualbell " 不要閃爍(不明白)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "狀態行顯示的內容
set laststatus=1 " 啓動顯示狀態行(1),老是顯示狀態行(2)
set foldenable " 容許摺疊
set foldmethod=manual " 手動摺疊
"set background=dark "背景使用黑色
set nocompatible "去掉討厭的有關vi一致性模式,避免之前版本的一些bug和侷限
" 顯示中文幫助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
" 設置配色方案
"colorscheme murphy
"字體
"if (has("gui_running"))
" set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
"endif
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件標題""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自動插入文件頭
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定義函數SetTitle,自動插入文件頭
func SetTitle()
"若是文件類型爲.sh文件
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ma6174")
call append(line(".")+2, "\# mail: ma6174@163.com")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: ma6174")
call append(line(".")+2, " > Mail: ma6174@163.com ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
"新建文件後,自動定位到文件末尾
autocmd BufNewFile * normal G
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"鍵盤命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>
" 映射全選+複製 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
map <F12> gg=G
" 選中狀態下 Ctrl+c 複製
vmap <C-c> "+y
"去空行
nnoremap <F2> :g/^\s*$/d<CR>
"比較文件
nnoremap <C-F2> :vert diffsplit
"新建標籤
map <M-F2> :tabnew<CR>
"列出當前目錄文件
map <F3> :tabnew .<CR>
"打開樹狀文件目錄
map <C-F3> \be
"C,C++ 按F9編譯運行
map <F9> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "! ./%<"
elseif &filetype == 'python'
exec " !python3 % "
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
elseif &filetype == 'sh'
:!./%
endif
endfunc
"C,C++的調試
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""實用設置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 設置當文件被改動時自動載入
set autoread
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"代碼補全
set completeopt=preview,menu
"容許插件
filetype plugin on
"共享剪貼板
set clipboard+=unnamed
"從不備份
set nobackup
"make 運行
:set makeprg=g++\ -Wall\ \ %
"自動保存
set autowrite
set ruler " 打開狀態欄標尺
set cursorline " 突出顯示當前行
set magic " 設置魔術
set guioptions-=T " 隱藏工具欄
set guioptions-=m " 隱藏菜單欄
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
" 設置在狀態行顯示的信息
set foldcolumn=0
set foldmethod=indent
set foldlevel=3
set foldenable " 開始摺疊
" 不要使用vi的鍵盤模式,而是vim本身的
set nocompatible
" 語法高亮
set syntax=on
" 去掉輸入錯誤的提示聲音
set noeb
" 在處理未保存或只讀文件的時候,彈出確認
set confirm
" 自動縮進
set autoindent
set cindent
" Tab鍵的寬度
set tabstop=4
" 統一縮進爲4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替製表符
set noexpandtab
" 在行和段開始處使用製表符
set smarttab
" 顯示行號
set number
" 歷史記錄數
set history=1000
"禁止生成臨時文件
set nobackup
set noswapfile
"搜索忽略大小寫
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
"行內替換
set gdefault
"編碼設置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"語言設置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 個人狀態行顯示的內容(包括文件類型和解碼)
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
" 老是顯示狀態行
set laststatus=2
" 命令行(在狀態行下)的高度,默認爲1,這裏是2
set cmdheight=2
" 偵測文件類型
filetype on
" 載入文件類型插件
filetype plugin on
" 爲特定文件類型載入相關縮進文件
filetype indent on
" 保存全局變量
set viminfo+=!
" 帶有以下符號的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-
" 字符間插入的像素行數目
set linespace=0
" 加強模式中的命令行自動完成操做
set wildmenu
" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2
" 容許backspace和光標鍵跨越行邊界
set whichwrap+=<,>,h,l
" 能夠在buffer的任何地方使用鼠標(相似office中在工做區雙擊鼠標定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 經過使用: commands命令,告訴咱們文件的哪一行被改變過
set report=0
" 在被分割的窗口間顯示空白,便於閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮顯示匹配的括號
set showmatch
" 匹配括號高亮的時間(單位是十分之一秒)
set matchtime=1
" 光標移動到buffer的頂部和底部時保持3行距離
set scrolloff=3
" 爲C程序提供自動縮進
set smartindent
" 高亮顯示普通txt文件(須要txt.vim腳本)
au BufRead,BufNewFile * setfiletype txt
"自動補全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
filetype plugin indent on
"打開文件類型檢測, 加了這句才能夠用智能補全
set completeopt=longest,menu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的設定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = "name" " 按照名稱排序
let Tlist_Use_Right_Window = 1 " 在右側顯示窗口
let Tlist_Compart_Format = 1 " 壓縮方式
let Tlist_Exist_OnlyWindow = 1 " 若是隻有一個buffer,kill窗口也kill掉buffer
let Tlist_File_Fold_Auto_Close = 0 " 不要關閉其餘文件的tags
let Tlist_Enable_Fold_Column = 0 " 不要顯示摺疊樹
autocmd FileType java set tags+=D:\tools\java\tags
"autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags
"let Tlist_Show_One_File=1 "不一樣時顯示多個文件的tag,只顯示當前文件的
"設置tags
set tags=tags
"set autochdir
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"其餘東東
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"默認打開Taglist
let Tlist_Auto_Open=1
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Show_One_File = 1 "不一樣時顯示多個文件的tag,只顯示當前文件的
let Tlist_Exit_OnlyWindow = 1 "若是taglist窗口是最後一個窗口,則退出vim
let Tlist_Use_Right_Window = 1 "在右側窗口中顯示taglist窗口
" minibufexpl插件的通常設置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 糾結
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" tab 縮進爲 4 個空格
set ts=4
set expandtab
set autoindent
gvim_vimrc
" =============================================================================
" << 判斷操做系統是 Windows 仍是 Linux 和判斷是終端仍是 Gvim >>
" =============================================================================
" -----------------------------------------------------------------------------
" < 判斷操做系統是不是 Windows 仍是 Linux >
" -----------------------------------------------------------------------------
let g:iswindows = 0
let g:islinux = 0
if(has("win32") || has("win64") || has("win95") || has("win16"))
let g:iswindows = 1
else
let g:islinux = 1
endif
" -----------------------------------------------------------------------------
" < 判斷是終端仍是 Gvim >
" -----------------------------------------------------------------------------
if has("gui_running")
let g:isGUI = 1
else
let g:isGUI = 0
endif
" =============================================================================
" << 如下爲軟件默認配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
" < Windows Gvim 默認配置> 作了一點修改
" -----------------------------------------------------------------------------
if (g:iswindows && g:isGUI)
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
endif
" -----------------------------------------------------------------------------
" < Linux Gvim/Vim 默認配置> 作了一點修改
" -----------------------------------------------------------------------------
if g:islinux
set hlsearch "高亮搜索
set incsearch "在輸入要搜索的文字時,實時匹配
" 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
if g:isGUI
" Source a global configuration file if available
if filereadable("/etc/vim/gvimrc.local")
source /etc/vim/gvimrc.local
endif
else
" 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
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
set mouse=a " 在任何模式下啓用鼠標
set t_Co=256 " 在終端啓用256色
set backspace=2 " 設置退格鍵可用
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
endif
endif
" =============================================================================
" << 如下爲用戶自定義配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
" < Vundle 插件管理工具配置 >
" -----------------------------------------------------------------------------
" 用於更方便的管理vim插件,具體用法參考 :h vundle 幫助
" Vundle工具安裝方法爲在終端輸入以下命令
" git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
" 若是想在 windows 安裝就必需先安裝 "git for window",可查閱網上資料
set nocompatible "禁用 Vi 兼容模式
filetype off "禁用文件類型偵測
if g:islinux
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
else
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc('$VIM/vimfiles/bundle/')
endif
" 使用Vundle來管理插件,這個必需要有。
Bundle 'gmarik/vundle'
" 如下爲要安裝或更新的插件,不一樣倉庫都有(具體書寫規範請參考幫助)
Bundle 'a.vim'
Bundle 'Align'
Bundle 'jiangmiao/auto-pairs'
Bundle 'bufexplorer.zip'
Bundle 'ccvext.vim'
Bundle 'cSyntaxAfter'
Bundle 'ctrlpvim/ctrlp.vim'
Bundle 'mattn/emmet-vim'
Bundle 'Yggdroot/indentLine'
Bundle 'vim-javacompleteex'
Bundle 'Mark--Karkat'
Bundle 'Shougo/neocomplcache.vim'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
Bundle 'OmniCppComplete'
Bundle 'Lokaltog/vim-powerline'
Bundle 'repeat.vim'
Bundle 'msanders/snipmate.vim'
Bundle 'wesleyche/SrcExpl'
Bundle 'std_c.zip'
Bundle 'tpope/vim-surround'
Bundle 'scrooloose/syntastic'
Bundle 'majutsushi/tagbar'
Bundle 'taglist.vim'
Bundle 'TxtBrowser'
Bundle 'ZoomWin'
" -----------------------------------------------------------------------------
" < 編碼配置 >
" -----------------------------------------------------------------------------
" 注:使用utf-8格式後,軟件與程序源碼、文件路徑不能有中文,不然報錯
set encoding=utf-8 "設置gvim內部編碼,默認不更改
" set fileencoding=utf-8 "設置當前文件編碼,能夠更改,如:gbk(同cp936)
set fileencoding=gbk "設置當前文件編碼,能夠更改,如:gbk(同cp936)
set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1 "設置支持打開的文件的編碼
" 文件格式,默認 ffs=dos,unix
set fileformat=unix "設置新(當前)文件的<EOL>格式,能夠更改,如:dos(windows系統經常使用)
set fileformats=unix,dos,mac "給出文件的<EOL>格式類型
if (g:iswindows && g:isGUI)
"解決菜單亂碼
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解決consle輸出亂碼
language messages zh_CN.utf-8
endif
" -----------------------------------------------------------------------------
" < 編寫文件時的配置 >
" -----------------------------------------------------------------------------
filetype on "啓用文件類型偵測
filetype plugin on "針對不一樣的文件類型加載對應的插件
filetype plugin indent on "啓用縮進
set smartindent "啓用智能對齊方式
set expandtab "將Tab鍵轉換爲空格
set tabstop=4 "設置Tab鍵的寬度,能夠更改,如:寬度爲2
set shiftwidth=4 "換行時自動縮進寬度,可更改(寬度同tabstop)
set smarttab "指定按一次backspace就刪除shiftwidth寬度
set foldenable "啓用摺疊
set foldmethod=indent "indent 摺疊方式
" set foldmethod=marker "marker 摺疊方式
" 常規模式下用空格鍵來開關光標行所在摺疊(注:zR 展開全部摺疊,zM 關閉全部摺疊)
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 當文件在外部被修改,自動更新該文件
set autoread
" 常規模式下輸入 cS 清除行尾空格
nmap cS :%s/\s\+$//g<CR>:noh<CR>
" 常規模式下輸入 cM 清除行尾 ^M 符號
nmap cM :%s/\r$//g<CR>:noh<CR>
set ignorecase "搜索模式裏忽略大小寫
set smartcase "若是搜索模式包含大寫字符,不使用 'ignorecase' 選項,只有在輸入搜索模式而且打開 'ignorecase' 選項時纔會使用
" set noincsearch "在輸入要搜索的文字時,取消實時匹配
" Ctrl + K 插入模式下光標向上移動
imap <c-k> <Up>
" Ctrl + J 插入模式下光標向下移動
imap <c-j> <Down>
" Ctrl + H 插入模式下光標向左移動
imap <c-h> <Left>
" Ctrl + L 插入模式下光標向右移動
imap <c-l> <Right>
" 啓用每行超過80列的字符提示(字體變藍並加下劃線),不啓用就註釋掉
au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)
" -----------------------------------------------------------------------------
" < 界面配置 >
" -----------------------------------------------------------------------------
set number "顯示行號
set laststatus=2 "啓用狀態欄信息
set cmdheight=2 "設置命令行的高度爲2,默認爲1
set cursorline "突出顯示當前行
" set guifont=YaHei_Consolas_Hybrid:h10 "設置字體:字號(字體名稱空格用下劃線代替)
set nowrap "設置不自動換行
set shortmess=atI "去掉歡迎界面
" 設置 gVim 窗口初始位置及大小
if g:isGUI
" au GUIEnter * simalt ~x "窗口啓動時自動最大化
winpos 100 10 "指定窗口出現的位置,座標原點在屏幕左上角
set lines=38 columns=120 "指定窗口大小,lines爲高度,columns爲寬度
endif
" 設置代碼配色方案
if g:isGUI
colorscheme Tomorrow-Night-Eighties "Gvim配色方案
else
colorscheme Tomorrow-Night-Eighties "終端配色方案
endif
" 顯示/隱藏菜單欄、工具欄、滾動條,可用 Ctrl + F11 切換
if g:isGUI
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=L
nmap <silent> <c-F11> :if &guioptions =~# 'm' <Bar>
\set guioptions-=m <Bar>
\set guioptions-=T <Bar>
\set guioptions-=r <Bar>
\set guioptions-=L <Bar>
\else <Bar>
\set guioptions+=m <Bar>
\set guioptions+=T <Bar>
\set guioptions+=r <Bar>
\set guioptions+=L <Bar>
\endif<CR>
endif
" -----------------------------------------------------------------------------
" < 編譯、鏈接、運行配置 (目前只配置了C、C++、Java語言)>
" -----------------------------------------------------------------------------
" F9 一鍵保存、編譯、鏈接存並運行
nmap <F9> :call Run()<CR>
imap <F9> <ESC>:call Run()<CR>
" Ctrl + F9 一鍵保存並編譯
nmap <c-F9> :call Compile()<CR>
imap <c-F9> <ESC>:call Compile()<CR>
" Ctrl + F10 一鍵保存並鏈接
nmap <c-F10> :call Link()<CR>
imap <c-F10> <ESC>:call Link()<CR>
let s:LastShellReturn_C = 0
let s:LastShellReturn_L = 0
let s:ShowWarning = 1
let s:Obj_Extension = '.o'
let s:Exe_Extension = '.exe'
let s:Class_Extension = '.class'
let s:Sou_Error = 0
let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:windows_CPPFlags = 'g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CPPFlags = 'g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:JavaFlags = 'javac\ %'
func! Compile()
exe ":ccl"
exe ":update"
let s:Sou_Error = 0
let s:LastShellReturn_C = 0
let Sou = expand("%:p")
let v:statusmsg = ''
if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
let Obj = expand("%:p:r").s:Obj_Extension
let Obj_Name = expand("%:p:t:r").s:Obj_Extension
if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))
redraw!
if expand("%:e") == "c"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CFlags
else
exe ":setlocal makeprg=".s:linux_CFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CPPFlags
else
exe ":setlocal makeprg=".s:linux_CPPFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_C = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_C != 0
exe ":bo cope"
echohl WarningMsg | echo " compilation failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " compilation successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " compilation successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Obj_Name"is up to date"
endif
elseif expand("%:e") == "java"
let class = expand("%:p:r").s:Class_Extension
let class_Name = expand("%:p:t:r").s:Class_Extension
if !filereadable(class) || (filereadable(class) && (getftime(class) < getftime(Sou)))
redraw!
exe ":setlocal makeprg=".s:JavaFlags
echohl WarningMsg | echo " compiling..."
silent make
redraw!
if v:shell_error != 0
let s:LastShellReturn_C = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_C != 0
exe ":bo cope"
echohl WarningMsg | echo " compilation failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " compilation successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " compilation successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""class_Name"is up to date"
endif
else
let s:Sou_Error = 1
echohl WarningMsg | echo " please choose the correct source file"
endif
exe ":setlocal makeprg=make"
endfunc
func! Link()
call Compile()
if s:Sou_Error || s:LastShellReturn_C != 0
return
endif
if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
let s:LastShellReturn_L = 0
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
let Exe_Name = expand("%:p:t:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
let Exe_Name = expand("%:p:t:r")
endif
let v:statusmsg = ''
if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))
redraw!
if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))
if expand("%:e") == "c"
setlocal makeprg=gcc\ -o\ %<\ %<.o
echohl WarningMsg | echo " linking..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
setlocal makeprg=g++\ -o\ %<\ %<.o
echohl WarningMsg | echo " linking..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_L = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_L != 0
exe ":bo cope"
echohl WarningMsg | echo " linking failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " linking successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " linking successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Exe_Name"is up to date"
endif
endif
setlocal makeprg=make
elseif expand("%:e") == "java"
return
endif
endfunc
func! Run()
let s:ShowWarning = 0
call Link()
let s:ShowWarning = 1
if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0
return
endif
let Sou = expand("%:p")
if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
endif
if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)
redraw!
echohl WarningMsg | echo " running..."
if g:iswindows
exe ":!%<.exe"
else
if g:isGUI
exe ":!gnome-terminal -x bash -c './%<; echo; echo 請按 Enter 鍵繼續; read'"
else
exe ":!clear; ./%<"
endif
endif
redraw!
echohl WarningMsg | echo " running finish"
endif
elseif expand("%:e") == "java"
let class = expand("%:p:r").s:Class_Extension
if getftime(class) >= getftime(Sou)
redraw!
echohl WarningMsg | echo " running..."
if g:iswindows
exe ":!java %<"
else
if g:isGUI
exe ":!gnome-terminal -x bash -c 'java %<; echo; echo 請按 Enter 鍵繼續; read'"
else
exe ":!clear; java %<"
endif
endif
redraw!
echohl WarningMsg | echo " running finish"
endif
endif
endfunc
" -----------------------------------------------------------------------------
" < 在瀏覽器中預覽 Html 或 PHP 文件 >
" -----------------------------------------------------------------------------
" 修改前請先通讀此模塊,明白了再改以免錯誤
" F5 加瀏覽器名稱縮寫調用瀏覽器預覽,啓用前先肯定有安裝相應瀏覽器,並在下面的配置好其安裝目錄
if g:iswindows
"如下爲只支持Windows系統的瀏覽器
" 調用系統IE瀏覽器預覽,若是已卸載可將其註釋
nmap <F5>ie :call ViewInBrowser("ie")<cr>
imap <F5>ie <ESC>:call ViewInBrowser("ie")<cr>
" 調用IETester(IE測試工具)預覽,若是有安裝可取消註釋
" nmap <F5>ie6 :call ViewInBrowser("ie6")<cr>
" imap <F5>ie6 <ESC>:call ViewInBrowser("ie6")<cr>
" nmap <F5>ie7 :call ViewInBrowser("ie7")<cr>
" imap <F5>ie7 <ESC>:call ViewInBrowser("ie7")<cr>
" nmap <F5>ie8 :call ViewInBrowser("ie8")<cr>
" imap <F5>ie8 <ESC>:call ViewInBrowser("ie8")<cr>
" nmap <F5>ie9 :call ViewInBrowser("ie9")<cr>
" imap <F5>ie9 <ESC>:call ViewInBrowser("ie9")<cr>
" nmap <F5>ie10 :call ViewInBrowser("ie10")<cr>
" imap <F5>ie10 <ESC>:call ViewInBrowser("ie10")<cr>
" nmap <F5>iea :call ViewInBrowser("iea")<cr>
" imap <F5>iea <ESC>:call ViewInBrowser("iea")<cr>
elseif g:islinux
"如下爲只支持Linux系統的瀏覽器
"暫未配置,待有時間再弄了
endif
"如下爲支持Windows與Linux系統的瀏覽器
" 調用Firefox瀏覽器預覽,若是有安裝可取消註釋
" nmap <F5>ff :call ViewInBrowser("ff")<cr>
" imap <F5>ff <ESC>:call ViewInBrowser("ff")<cr>
" 調用Maxthon(遨遊)瀏覽器預覽,若是有安裝可取消註釋
" nmap <F5>ay :call ViewInBrowser("ay")<cr>
" imap <F5>ay <ESC>:call ViewInBrowser("ay")<cr>
" 調用Opera瀏覽器預覽,若是有安裝可取消註釋
" nmap <F5>op :call ViewInBrowser("op")<cr>
" imap <F5>op <ESC>:call ViewInBrowser("op")<cr>
" 調用Chrome瀏覽器預覽,若是有安裝可取消註釋
" nmap <F5>cr :call ViewInBrowser("cr")<cr>
" imap <F5>cr <ESC>:call ViewInBrowser("cr")<cr>
" 瀏覽器調用函數
function! ViewInBrowser(name)
if expand("%:e") == "php" || expand("%:e") == "html"
exe ":update"
if g:iswindows
"獲取要預覽的文件路徑,並將路徑中的'\'替換爲'/',同時將路徑文字的編碼轉換爲gbk(同cp936)
let file = iconv(substitute(expand("%:p"), '\', '/', "g"), "utf-8", "gbk")
"瀏覽器路徑設置,路徑中使用'/'斜槓,更改路徑請更改雙引號裏的內容
"下面只啓用了系統IE瀏覽器,如需啓用其它的可將其取消註釋(得先安裝,並配置好安裝路徑),也可按需增減
let SystemIE = "C:/progra~1/intern~1/iexplore.exe" "系統自帶IE目錄
" let IETester = "F:/IETester/IETester.exe" "IETester程序目錄(可按實際更改)
" let Chrome = "F:/Chrome/Chrome.exe" "Chrome程序目錄(可按實際更改)
" let Firefox = "F:/Firefox/Firefox.exe" "Firefox程序目錄(可按實際更改)
" let Opera = "F:/Opera/opera.exe" "Opera程序目錄(可按實際更改)
" let Maxthon = "C:/Progra~2/Maxthon/Bin/Maxthon.exe" "Maxthon程序目錄(可按實際更改)
"本地虛擬服務器設置,我測試的是phpStudy2014,可根據本身的修改,更改路徑請更改雙引號裏的內容
let htdocs ="F:/phpStudy2014/WWW/" "虛擬服務器地址或目錄(可按實際更改)
let url = "localhost" "虛擬服務器網址(可按實際更改)
elseif g:islinux
"暫時尚未配置,有時間再弄了。
endif
"瀏覽器調用縮寫,可根據實際增減,注意,上面瀏覽器路徑中沒有定義過的變量(等號右邊爲變量)不能出如今下面喲(可將其註釋或刪除)
let l:browsers = {} "定義縮寫字典變量,此行不能刪除或註釋
" let l:browsers["cr"] = Chrome "Chrome瀏覽器縮寫
" let l:browsers["ff"] = Firefox "Firefox瀏覽器縮寫
" let l:browsers["op"] = Opera "Opera瀏覽器縮寫
" let l:browsers["ay"] = Maxthon "遨遊瀏覽器縮寫
let l:browsers["ie"] = SystemIE "系統IE瀏覽器縮寫
" let l:browsers["ie6"] = IETester."-ie6" "調用IETESTER工具以IE6預覽縮寫(變量加參數)
" let l:browsers["ie7"] = IETester."-ie7" "調用IETESTER工具以IE7預覽縮寫(變量加參數)
" let l:browsers["ie8"] = IETester."-ie8" "調用IETESTER工具以IE8預覽縮寫(變量加參數)
" let l:browsers["ie9"] = IETester."-ie9" "調用IETESTER工具以IE9預覽縮寫(變量加參數)
" let l:browsers["ie10"] = IETester."-ie10" "調用IETESTER工具以IE10預覽縮寫(變量加參數)
" let l:browsers["iea"] = IETester."-al" "調用IETESTER工具以支持的全部IE版本預覽縮寫(變量加參數)
if stridx(file, htdocs) == -1 "文件不在本地虛擬服務器目錄,則直接預覽(但不能解析PHP文件)
exec ":silent !start ". l:browsers[a:name] ." file://" . file
else "文件在本地虛擬服務器目錄,則調用本地虛擬服務器解析預覽(先啓動本地虛擬服務器)
let file = substitute(file, htdocs, "http://".url."/", "g") "轉換文件路徑爲虛擬服務器網址路徑
exec ":silent !start ". l:browsers[a:name] file
endif
else
echohl WarningMsg | echo " please choose the correct source file"
endif
endfunction
" -----------------------------------------------------------------------------
" < 其它配置 >
" -----------------------------------------------------------------------------
set writebackup "保存文件前創建備份,保存成功後刪除該備份
set nobackup "設置無備份文件
" set noswapfile "設置無臨時文件
" set vb t_vb= "關閉提示音
" =============================================================================
" << 如下爲經常使用插件配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
" < a.vim 插件配置 >
" -----------------------------------------------------------------------------
" 用於切換C/C++頭文件
" :A ---切換頭文件並獨佔整個窗口
" :AV ---切換頭文件並垂直分割窗口
" :AS ---切換頭文件並水平分割窗口
" -----------------------------------------------------------------------------
" < Align 插件配置 >
" -----------------------------------------------------------------------------
" 一個對齊的插件,用來——排版與對齊代碼,功能強大,不過用到的機會很少
" -----------------------------------------------------------------------------
" < auto-pairs 插件配置 >
" -----------------------------------------------------------------------------
" 用於括號與引號自動補全,不過會與函數原型提示插件echofunc衝突
" 因此我就沒有加入echofunc插件
" -----------------------------------------------------------------------------
" < BufExplorer 插件配置 >
" -----------------------------------------------------------------------------
" 快速輕鬆的在緩存中切換(至關於另外一種多個文件間的切換方式)
" <Leader>be 在當前窗口顯示緩存列表並打開選定文件
" <Leader>bs 水平分割窗口顯示緩存列表,並在緩存列表窗口中打開選定文件
" <Leader>bv 垂直分割窗口顯示緩存列表,並在緩存列表窗口中打開選定文件
" -----------------------------------------------------------------------------
" < ccvext.vim 插件配置 >
" -----------------------------------------------------------------------------
" 用於對指定文件自動生成tags與cscope文件並鏈接
" 若是是Windows系統, 則生成的文件在源文件所在盤符根目錄的.symbs目錄下(如: X:\.symbs\)
" 若是是Linux系統, 則生成的文件在~/.symbs/目錄下
" 具體用法可參考www.vim.org中此插件的說明
" <Leader>sy 自動生成tags與cscope文件並鏈接
" <Leader>sc 鏈接已存在的tags與cscope文件
" -----------------------------------------------------------------------------
" < cSyntaxAfter 插件配置 >
" -----------------------------------------------------------------------------
" 高亮括號與運算符等
au! BufRead,BufNewFile,BufEnter *.{c,cpp,h,java,javascript} call CSyntaxAfter()
" -----------------------------------------------------------------------------
" < ctrlp.vim 插件配置 >
" -----------------------------------------------------------------------------
" 一個全路徑模糊文件,緩衝區,最近最多使用,... 檢索插件;詳細幫助見 :h ctrlp
" 常規模式下輸入:Ctrl + p 調用插件
" -----------------------------------------------------------------------------
" < emmet-vim(前身爲Zen coding) 插件配置 >
" -----------------------------------------------------------------------------
" HTML/CSS代碼快速編寫神器,詳細幫助見 :h emmet.txt
" -----------------------------------------------------------------------------
" < indentLine 插件配置 >
" -----------------------------------------------------------------------------
" 用於顯示對齊線,與 indent_guides 在顯示方式上不一樣,根據本身喜愛選擇了
" 在終端上會有屏幕刷新的問題,這個問題能解決有更好了
" 開啓/關閉對齊線
nmap <leader>il :IndentLinesToggle<CR>
" 設置Gvim的對齊線樣式
if g:isGUI
let g:indentLine_char = "┊"
let g:indentLine_first_char = "┊"
endif
" 設置終端對齊線顏色,若是不喜歡能夠將其註釋掉採用默認顏色
let g:indentLine_color_term = 239
" 設置 GUI 對齊線顏色,若是不喜歡能夠將其註釋掉採用默認顏色
" let g:indentLine_color_gui = '#A4E57E'
" -----------------------------------------------------------------------------
" < vim-javacompleteex(也就是 javacomplete 加強版)插件配置 >
" -----------------------------------------------------------------------------
" java 補全插件
" -----------------------------------------------------------------------------
" < Mark--Karkat(也就是 Mark) 插件配置 >
" -----------------------------------------------------------------------------
" 給不一樣的單詞高亮,代表不一樣的變量時頗有用,詳細幫助見 :h mark.txt
" " -----------------------------------------------------------------------------
" " < MiniBufExplorer 插件配置 >
" " -----------------------------------------------------------------------------
" " 快速瀏覽和操做Buffer
" " 主要用於同時打開多個文件並相與切換
" " let g:miniBufExplMapWindowNavArrows = 1 "用Ctrl加方向鍵切換到上下左右的窗口中去
" let g:miniBufExplMapWindowNavVim = 1 "用<C-k,j,h,l>切換到上下左右的窗口中去
" let g:miniBufExplMapCTabSwitchBufs = 1 "功能加強(不過好像只有在Windows中才有用)
" " <C-Tab> 向前循環切換到每一個buffer上,並在但前窗口打開
" " <C-S-Tab> 向後循環切換到每一個buffer上,並在當前窗口打開
" 在不使用 MiniBufExplorer 插件時也可用<C-k,j,h,l>切換到上下左右的窗口中去
noremap <c-k> <c-w>k
noremap <c-j> <c-w>j
noremap <c-h> <c-w>h
noremap <c-l> <c-w>l
" -----------------------------------------------------------------------------
" < neocomplcache 插件配置 >
" -----------------------------------------------------------------------------
" 關鍵字補全、文件路徑補全、tag補全等等,各類,很是好用,速度超快。
let g:neocomplcache_enable_at_startup = 1 "vim 啓動時啓用插件
" let g:neocomplcache_disable_auto_complete = 1 "不自動彈出補全列表
" 在彈出補全列表後用 <c-p> 或 <c-n> 進行上下選擇效果比較好
" -----------------------------------------------------------------------------
" < nerdcommenter 插件配置 >
" -----------------------------------------------------------------------------
" 我主要用於C/C++代碼註釋(其它的也行)
" 如下爲插件默認快捷鍵,其中的說明是以C/C++爲例的,其它語言相似
" <Leader>ci 以每行一個 /* */ 註釋選中行(選中區域所在行),再輸入則取消註釋
" <Leader>cm 以一個 /* */ 註釋選中行(選中區域所在行),再輸入則稱重複註釋
" <Leader>cc 以每行一個 /* */ 註釋選中行或區域,再輸入則稱重複註釋
" <Leader>cu 取消選中區域(行)的註釋,選中區域(行)內至少有一個 /* */
" <Leader>ca 在/*...*/與//這兩種註釋方式中切換(其它語言可能不同了)
" <Leader>cA 行尾註釋
let NERDSpaceDelims = 1 "在左註釋符以後,右註釋符以前留有空格
" -----------------------------------------------------------------------------
" < nerdtree 插件配置 >
" -----------------------------------------------------------------------------
" 有目錄村結構的文件瀏覽插件
" 常規模式下輸入 F2 調用插件
nmap <F2> :NERDTreeToggle<CR>
" -----------------------------------------------------------------------------
" < omnicppcomplete 插件配置 >
" -----------------------------------------------------------------------------
" 用於C/C++代碼補全,這種補全主要針對命名空間、類、結構、共同體等進行補全,詳細
" 說明能夠參考幫助或網絡教程等
" 使用前先執行以下 ctags 命令(本配置中能夠直接使用 ccvext 插件來執行如下命令)
" ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
" 我使用上面的參數生成標籤後,對函數使用跳轉時會出現多個選擇
" 因此我就將--c++-kinds=+p參數給去掉了,若是大俠有什麼其它解決方法但願不要保留呀
set completeopt=menu "關閉預覽窗口
" -----------------------------------------------------------------------------
" < powerline 插件配置 >
" -----------------------------------------------------------------------------
" 狀態欄插件,更好的狀態欄效果
" -----------------------------------------------------------------------------
" < repeat 插件配置 >
" -----------------------------------------------------------------------------
" 主要用"."命令來重複上次插件使用的命令
" -----------------------------------------------------------------------------
" < snipMate 插件配置 >
" -----------------------------------------------------------------------------
" 用於各類代碼補全,這種補全是一種對代碼中的詞與代碼塊的縮寫補全,詳細用法能夠參
" 考使用說明或網絡教程等。不過有時候也會與 supertab 插件在補全時產生衝突,若是大
" 俠有什麼其它解決方法但願不要保留呀
" -----------------------------------------------------------------------------
" < SrcExpl 插件配置 >
" -----------------------------------------------------------------------------
" 加強源代碼瀏覽,其功能就像Windows中的"Source Insight"
nmap <F3> :SrcExplToggle<CR> "打開/閉瀏覽窗口
" -----------------------------------------------------------------------------
" < std_c 插件配置 >
" -----------------------------------------------------------------------------
" 用於加強C語法高亮
" 啓用 // 注視風格
let c_cpp_comments = 0
" -----------------------------------------------------------------------------
" < surround 插件配置 >
" -----------------------------------------------------------------------------
" 快速給單詞/句子兩邊增長符號(包括html標籤),缺點是不能用"."來重複命令
" 不過 repeat 插件能夠解決這個問題,詳細幫助見 :h surround.txt
" -----------------------------------------------------------------------------
" < Syntastic 插件配置 >
" -----------------------------------------------------------------------------
" 用於保存文件時查檢語法
" -----------------------------------------------------------------------------
" < Tagbar 插件配置 >
" -----------------------------------------------------------------------------
" 相對 TagList 能更好的支持面向對象
" 常規模式下輸入 tb 調用插件,若是有打開 TagList 窗口則先將其關閉
nmap tb :TlistClose<CR>:TagbarToggle<CR>
let g:tagbar_width=30 "設置窗口寬度
" let g:tagbar_left=1 "在左側窗口中顯示
" -----------------------------------------------------------------------------
" < TagList 插件配置 >
" -----------------------------------------------------------------------------
" 高效地瀏覽源碼, 其功能就像vc中的workpace
" 那裏面列出了當前文件中的全部宏,全局變量, 函數名等
" 常規模式下輸入 tl 調用插件,若是有打開 Tagbar 窗口則先將其關閉
nmap tl :TagbarClose<CR>:Tlist<CR>
let Tlist_Show_One_File=1 "只顯示當前文件的tags
" let Tlist_Enable_Fold_Column=0 "使taglist插件不顯示左邊的摺疊行
let Tlist_Exit_OnlyWindow=1 "若是Taglist窗口是最後一個窗口則退出Vim
let Tlist_File_Fold_Auto_Close=1 "自動摺疊
let Tlist_WinWidth=30 "設置窗口寬度
let Tlist_Use_Right_Window=1 "在右側窗口中顯示
" -----------------------------------------------------------------------------
" < txtbrowser 插件配置 >
" -----------------------------------------------------------------------------
" 用於文本文件生成標籤與與語法高亮(調用TagList插件生成標籤,若是能夠)
au BufRead,BufNewFile *.txt setlocal ft=txt
" -----------------------------------------------------------------------------
" < ZoomWin 插件配置 >
" -----------------------------------------------------------------------------
" 用於分割窗口的最大化與還原
" 常規模式下按快捷鍵 <c-w>o 在最大化與還原間切換
" =============================================================================
" << 如下爲經常使用工具配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
" < cscope 工具配置 >
" -----------------------------------------------------------------------------
" 用Cscope本身的話說 - "你能夠把它當作是超過頻的ctags"
if has("cscope")
"設定可使用 quickfix 窗口來查看 cscope 結果
set cscopequickfix=s-,c-,d-,i-,t-,e-
"使支持用 Ctrl+] 和 Ctrl+t 快捷鍵在代碼間跳轉
set cscopetag
"若是你想反向搜索順序設置爲1
set csto=0
"在當前目錄中添加任何數據庫
if filereadable("cscope.out")
cs add cscope.out
"不然添加數據庫環境中所指出的
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set cscopeverbose
"快捷鍵設置
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
endif
" -----------------------------------------------------------------------------
" < ctags 工具配置 >
" -----------------------------------------------------------------------------
" 對瀏覽代碼很是的方便,能夠在函數,變量之間跳轉等
set tags=./tags; "向上級目錄遞歸查找tags文件(好像只有在Windows下才有用)
" -----------------------------------------------------------------------------
" < gvimfullscreen 工具配置 > 請確保已安裝了工具
" -----------------------------------------------------------------------------
" 用於 Windows Gvim 全屏窗口,可用 F11 切換
" 全屏後再隱藏菜單欄、工具欄、滾動條效果更好
if (g:iswindows && g:isGUI)
nmap <F11> <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
endif
" -----------------------------------------------------------------------------
" < vimtweak 工具配置 > 請確保以已裝了工具
" -----------------------------------------------------------------------------
" 這裏只用於窗口透明與置頂
" 常規模式下 Ctrl + Up(上方向鍵) 增長不透明度,Ctrl + Down(下方向鍵) 減小不透明度,<Leader>t 窗口置頂與否切換
if (g:iswindows && g:isGUI)
let g:Current_Alpha = 255
let g:Top_Most = 0
func! Alpha_add()
let g:Current_Alpha = g:Current_Alpha + 10
if g:Current_Alpha > 255
let g:Current_Alpha = 255
endif
call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
endfunc
func! Alpha_sub()
let g:Current_Alpha = g:Current_Alpha - 10
if g:Current_Alpha < 155
let g:Current_Alpha = 155
endif
call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
endfunc
func! Top_window()
if g:Top_Most == 0
call libcallnr("vimtweak.dll","EnableTopMost",1)
let g:Top_Most = 1
else
call libcallnr("vimtweak.dll","EnableTopMost",0)
let g:Top_Most = 0
endif
endfunc
"快捷鍵設置
nmap <c-up> :call Alpha_add()<CR>
nmap <c-down> :call Alpha_sub()<CR>
nmap <leader>t :call Top_window()<CR>
endif
" =============================================================================
" << 如下爲經常使用自動命令配置 >>
" =============================================================================
" 自動切換目錄爲當前編輯文件所在目錄
au BufRead,BufNewFile,BufEnter * cd %:p:h
" =============================================================================
" << windows 下解決 Quickfix 亂碼問題 >>
" =============================================================================
" windows 默認編碼爲 cp936,而 Gvim(Vim) 內部編碼爲 utf-8,因此經常輸出爲亂碼
" 如下代碼能夠將編碼爲 cp936 的輸出信息轉換爲 utf-8 編碼,以解決輸出亂碼問題
" 但好像只對輸出信息所有爲中文才有滿意的效果,若是輸出信息是中英混合的,那可能
" 不成功,會形成其中一種語言亂碼,輸出信息所有爲英文的好像不會亂碼
" 若是輸出信息爲亂碼的能夠試一下下面的代碼,若是不行就仍是給它註釋掉
" if g:iswindows
" function QfMakeConv()
" let qflist = getqflist()
" for i in qflist
" let i.text = iconv(i.text, "cp936", "utf-8")
" endfor
" call setqflist(qflist)
" endfunction
" au QuickfixCmdPost make call QfMakeConv()
" endif
" =============================================================================
" << 其它 >>
" =============================================================================
" 注:上面配置中的"<Leader>"在本軟件中設置爲"\"鍵(引號裏的反斜槓),如<Leader>t
" 指在常規模式下按"\"鍵加"t"鍵,這裏不是同時按,而是先按"\"鍵後按"t"鍵,間隔在一
" 秒內,而<Leader>cs是先按"\"鍵再按"c"又再按"s"鍵;如要修改"<leader>"鍵,能夠把
" 下面的設置取消註釋,並修改雙引號中的鍵爲你想要的,如修改成逗號鍵。
" let mapleader = ","
" =============================================================================
" << 糾結 >>
" =============================================================================
" 代碼高亮
colorscheme monokai
" 設置字體
set gfn=Microsoft_YaHei_Mono:h12:cGB2312
" 字典補全
set dictionary=$vim\dict.txt
" 一鍵編譯代碼
func CompileRun()
exec "w"
if &filetype == "python"
exec " !python % "
elseif &filetype == "html"
exec " !% "
elseif &filetype == "c"
exec " !gcc % -o %< "
exec " !%< "
endif
endfunc
map <F9> :call CompileRun()<CR>