mkdir -p ~/.vim/bundle/Vundle.vim
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
####################################################.vimrc ####################################################
set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' Plugin 'taghighlight' Plugin 'majutsushi/tagbar' nmap tb :TagbarToggle<CR> let g:tagbar_ctags_bin='ctags' "ctags程序的路径 let g:tagbar_width=30 "窗口宽度的设置 "map <F3> :Tagbar<CR> "autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen() "如果是c语言的程序的话,tagbar自动开启 Plugin 'scrooloose/nerdtree' "文件资源管理器
nmap fb :NERDTreeToggle<CR>
let NERDTreeWinPos='left' let NERDTreeWinSize=30 "map <F2> :NERDTreeToggle<CR> Plugin 'git://github.com/kien/ctrlp.vim.git' "NERDTree 下按Ctrl-p搜索文件名
Plugin 'bling/vim-airline' "状态栏 set laststatus=2 Plugin 'fholgado/minibufexpl.vim' let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplModSelTarget = 1 let g:miniBufExplMoreThanOne = 0 map <F11> :MBEbp<CR> map <F12> :MBEbn<CR> Plugin 'vim-scripts/DoxygenToolkit.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo Plugin 'tpope/vim-fugitive' " plugin from http://vim-scripts.org/vim/scripts.html " Plugin 'L9' " Git plugin not hosted on GitHub ""Plugin 'git://git.wincent.com/command-t.git' " git repos on your local machine (i.e. when working on your own plugin) ""Plugin 'file:///home/gmarik/path/to/plugin' " The sparkup vim script is in a subdirectory of this repo called vim. " Pass the path to set the runtimepath properly. ""Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " Install L9 and avoid a Naming conflict if you've already installed a " different version somewhere else. " Plugin 'ascenator/L9', {'name': 'newL9'} " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just:PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line set nu set ts=4 set expandtab set smartindent set shiftwidth=4 set encoding=utf-8 set termencoding=utf-8 set fileencodings=utf-8,gbk,latin1 set hls "hi comment ctermfg=6 func CFileTitle() call setline(1, "/**") call append(1, "* ".expand("%")) call append(2, "* wangkaichao@skyworth.com ".strftime("%Y-%m-%d")) call append(3, "*/") endfunc map title :call CFileTitle()<CR> "inoremap { {}<LEFT> "inoremap [ []<LEFT> "inoremap ( ()<LEFT> "inoremap " ""<LEFT> "inoremap ' ''<LEFT>
#################################################### 基本应用 ####################################################
(1) 调出 vim 命令历史列表
<ESC>q:
(2) 查看 打开的文件缓冲区
<ESC>:ls
(2) 文件缓冲区 文件切换
方法1 <ESC>:bn # n是ls显示的id号
方法2 <Ctrl + 6> #顺序切换
方法3 <ESC>:e filename
(3) <ESC>:vs 垂直分割窗口
(4) <ESC>:sv 水平分割窗口
(5) <ESC><Ctrl + w> hjkl 在窗口之间切换
Ctrl-w H或键入:wincmd H
从水平布局到垂直布局。
Ctrl-w J或键入:wincmd J
从垂直布局到水平布局。
Ctrl-w r或键入:wincmd r
到交换两个缓冲区,但保持窗口布局相同。
Ctrl-w w或键入:wincmd w
到移动光标两个窗口/缓冲器之间。
(6) 不同窗口文件间复制粘贴
复制 <ESC>v(进块模式) 选择文件内容 +y 或者*y
粘贴 <ESC>+p 或者*p
(6.1)寄存器复制粘贴
复制 <ESC>v(进块模式) 选择文件内容
"[a-z]y
"[a-z]p
(7) 调整窗口大小
水平调整窗口的各种操作:
<ESC><Ctrl+w> 松手,n+ #窗口边界上移n
<ESC><Ctrl+w> 松手,n- #窗口边界下移n
<ESC><Ctrl+w> _ #将当前窗口调到最大
<ESC><Ctrl+w> = #平分窗口
垂直调整窗口的各种操作:
<ESC><Ctrl+w> 松手,n< #窗口边界左移n
<ESC><Ctrl+w> 松手,n> #窗口边界右移n
<ESC><Ctrl+w> | #将当前窗口调到最大
<ESC><Ctrl+w> = #平分窗口,这个快捷键是通用的。
(8) 常用删除操作
di( #删除括号内内容
di[
di{
daB #删除{内容包括{}
(9) vim 前后台切换
<ESC><Ctrl-z> #进入后台
jobs #查看当前后台的vim
fg n #根据jobs列出的id,将该id切入前台
(10) vim 编辑目录
<ESC>:e pathanme
<ESC>:Exp[lore] pathname # 浏览该目录
<ESC>:Sex[plore] . #在水平分割窗口中浏览该目录
<ESC>:Vex[plore] . #在垂直分割窗口中浏览该目录
(11) vim 使用文件标签tab
<ESC>:tabe filename
<ESC>:tabs #显示已打开标签页的列表,并用“>”标识出当前页面,用“+”标识出已更改的页面。
<ESC>:tabc n #关闭tabs 列出来的签页id=n,tabc不加参数,默认关闭 “>”,即当前标签页 。
<ESC>:tabo #关闭所有的标签页。
<ESC>:tabn或<ESC>gt #移动到下一个标签页。
<ESC>:tabp或<ESC>gT #移动到上一个标签页。
#################################################### cscope ####################################################
#######################################cscope 貌似比ctags强大,存系统api的符号更好,不用更新
apt-get install cscope
find /opt/hisi-linux/x86-arm/arm-hisiv300-linux/arm-hisiv300-linux-uclibcgnueabi/include/c++/4.8.3 -name "*" > c++.files
cscope -bkq -i c++.files -f c++.out
find /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include -name "*.[h|c]" > c.files
cscope -bkq -i c.files -f c.out
vim file
<ESC> cs add /path/c.out
注意在查找标识符之前,当前文件一定要<ESC>:w
<ESC> cs find g/s funcname
显示多个项,按空格,输入id,跳转到声明出,返回方法:ls + bn 或者<Ctrl+6>
#################################################### ctags ####################################################
####################################################比较灵活,多用来同步应用代码的标识,要更新
apt-get install ctags
ctags --c++-kinds=+p --fields=+iaS --extra=+q -R -f xxtags ./
# set tags+=xxtags
<Ctrl> + ] 跳转到的定义
<Ctrl> + o/t 返回
=========================================================================================================
set fenc 查看现在文本的编码
:set fenc=编码 转换当前文本的编码为指定的编码
:set enc=编码 以指定的编码显示文本,但不保存到文件中。
:set ff? 查看当前文本的模式类型,一般为dos,unix
:set ff=dos 转换为dos模式
:set ff=unix 转换为unix模式,等同于:%s/^M//g