服务器搭建以及vim配置过程
2015-08-05 11:11
477 查看
服务器搭建以及vim配置过程
1、设置静态IP修改/etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.12.51
netmask 255.255.255.0
gateway 192.168.12.254
2、修改 vim /etc/samba/smb.conf
添加smb共享目录
[work]
comment = work
path = /home/usrname
guest ok = no
browseable = yes
create mask = 0775
directory mask = 0775
3、修改用户组:
chown usrname:usrname usrname
4、添加BCM、ST、MSTAR、HISI的编译环境放在/opt/目录下
5、安装编译使用工具:sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 /*不安装会提示找不到编译工具,并且无法执行。错误提示bash: ./arm-none-linux-gnueabi-gcc: No such file or directory*/
sudo apt-get install liblzo2-dev/*64位*/
sudo apt-get install liblzo2-dev:i386/*32位*/
sudo apt-get install uuid-dev:i386/*32位*/
sudo apt-get install gcc
sudo apt-get install lib32stdc++6
sudo apt-get install build-essential bison libc6-dev
6、安装小乌龟工具:sudo apt-get install subversion
7、安装NFS服务器:
sudo apt-get install nfs-kernel-server nfs-common portmap
配置NFS服务器:vim /etc/exports
最后一行添加:
/home *(rw,sync,no_root_squash,no_subtree_check)
B、2014.10.30
1、配置GVim::vim .vimrc
set wildmenu "增强模式中的命令行自动完成操作
set foldmethod=manual "设定折叠方式为手动
set sta "插入<tab>时使用'shiftwidth'
syntax enable "设置高亮关键字显示
"set background=dark "背景使用黑色
"set enc=utf-8 "设置编码为中文
set winaltkeys=no "Alt组合键不映射到菜单上
autocmd FileType python setlocal et sta sw=4 sts=4
" 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 nocompatible
" detect file type
filetype on
filetype plugin on
" 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
"have Vim load indentation rules and plugins according to the detected filetype
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 ignorecase " 搜索模式里忽略大小写
"set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。
set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
"set smartindent " 智能对齐方式
set tabstop=4 " 设置制表符(tab键)的宽度
set softtabstop=4 " 设置软制表符的宽度
set shiftwidth=4 " (自动) 缩进使用的4个空格
set cindent " 使用 C/C++ 语言的自动缩进方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
"set backspace=2 " 设置退格键可用
set showmatch " 设置匹配模式,显示匹配的括号
set linebreak " 整词换行
set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
"set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes) "使用鼠标
set number " Enable line number "显示行号
"set previewwindow " 标识预览窗口
set history=50 " set command history to 50 "历史记录50条
"--状态行设置--
set laststatus=2 " 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P> "设置状态栏
set ruler " 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。
"--命令行设置--
set showcmd " 命令行显示输入的命令
set showmode " 命令行显示vim当前模式
"--find setting--
set incsearch " 输入字符串就显示匹配点
set hlsearch
2、安装vim中文帮助手册
$tar xvf vimcdoc-1.8.0.tar.gz
$cd vimcdoc-1.8.0/
$./vimcdoc.sh -i
~/.vimrc里加上set helplang=cn
3、添加bash和C/C++支持
unzip bash-support.zip
unzip cvim.zip
4、安装tags和taglist
sudo apt-get install exuberant-ctags
unzip taglist_46.zip
5、WinManager(调整窗口布局)
unzip winmanager.zip
6、安装cscope:
sudo apt-get install cscope
7、配置自动补全建立系统tags
ctags -R -f ~/.vim/systags –c-kinds=+p –c++-kinds=+px –fields=+iaS –extra=+q –python-kinds=-i /usr/include /usr/local/include
8、修改.vimrc文件
"禁止自动改变当前Vim窗口的大小
let Tlist_Inc_Winwidth=0
"把方法列表放在屏幕的右侧
let Tlist_Use_Right_Window=1
"让当前不被编辑的文件的方法列表自动折叠起来, 这样可以节约一些屏幕空间
let Tlist_File_Fold_Auto_Close=1
"映射F3为功能键调出winmanager的文件浏览器
"映射双击F3调出Taglist的符号浏览器
"let g:winManagerWindowLayout='FileExplorer|TagList' "你要是喜欢这种布局可以注释掉这一行
map <F3> :WMToggle<cr>
map <F3><F3> :TlistToggle<cr>
"将系统已经生成的tags导入
set tags+=~/.vim/systags
"映射F10为添加cscope和ctags
map <F10> :call Do_CsTag()<CR>
map <F10><F10> :call Add_CsTag()<CR>
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>
function Do_CsTag()
silent! execute "!ctags -R '.'"
if(executable('cscope') && has("cscope") )
silent! execute "!find -L `pwd` -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' -o -name '*.cxx' -o -name '*.hxx'> cscope.files -o -name '*.hpp' -o -name '*.py'" endif
silent! execute "!cscope -bq"
silent! execute "call Add_CsTag()"
endf
function Add_CsTag()
if filereadable("cscope.out")
execute "cs add cscope.out"
execute "set tags+=./tags"
endif
endf
silent! execute "call Add_CsTag()"
9、同名头文件和源文件切换:
a.vim 放到 ~/.vim/plugin 中
10、代码块和常用语句模板自动补全
code_complete.vim放到 ~/.vim/plugin 中
将下边这一段加入到template段中以添加bash模板补全功能
"Bash Templates
"Bash Structure by warmbupt@gmail.com
let g:template['sh'] = {}
let g:template['sh']['sif'] = "if ".g:rs."…".g:re." ; then/".g:rs."…".g:re."/fi"
let g:template['sh']['sife'] = "if ".g:rs."…".g:re." ; then/".g:rs."…".g:re."/else/".g:rs."…".
/g:re."/fi"
let g:template['sh']['scase'] = "case ".g:rs."…".g:re." in/".g:rs."…".g:re.")//" .g:rs."…".g:re.";;//".
/g:rs."…".g:re.")//" .g:rs."…".g:re.";;///esac/"
let g:template['sh']['swhile'] = "while ".g:rs."…".g:re." /do/".g:rs."…".g:re."/done"
let g:template['sh']['suntil'] = "until ".g:rs."…".g:re." /do/".g:rs."…".g:re."/done"
let g:template['sh']['sfor'] = "for ".g:rs."…".g:re." in " .g:rs."…".g:re."/do/".g:rs."…".g:re."/done"
let g:template['sh']['sselect'] = "select ".g:rs."…".g:re." in " .g:rs."…".g:re."/do/".g:rs."…".g:re."/done"
11、代码补全:supertab+snipMate+omnicppcomplete
vim打开supertab.vba,然后使用:so % 进行安装
vim neocomplcache-6.1.vba然后使用:so % 进行安装
12、函数原型提示:
echofunc.vim放到 ~/.vim/plugin 中
在 ~/.vimrc中添加:
"-------------------------------------------------
"函数原型提示
let g:EchoFuncKeyNext='<C-n>'
let g:EchoFuncKeyPrev='<C-p>'
13、.C/STL/Python Doc提示:
tar xvf stlrefvim.tar.gz
unzip crefvim.zip
unzip pyref.zip
把plugin/pyref.vim移动到ftplugin中,这样只针对python文件的插件。
在.vimrc中添加:let g:pyref_mapping = 'K'
14、简单注释:
comments.vim放到plugin目录中
15、代码格式整理:
在vimrc中写入:
"定义源代码格式化
map <F12> :call FormartSrc()<CR>
"定义FormartSrc()
func FormartSrc()
exec "w"
if &filetype == 'c'
exec "!astyle % –style=ansi –suffix=none %"
exec "e! %"
elseif &filetype == 'cpp'
"exec "!astyle % –style=ansi –suffix=none %"
"exec "e! %"
elseif &filetype == 'perl'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'py'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'java'
exec "!astyle –style=java –suffix=none %"
exec "e! %"
elseif &filetype == 'jsp'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'xml'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'html'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'htm'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
endif
endfunc
"结束定义FormartSrc
16、多tab支持:
unzip NERD_tree.zip
在vimrc中写入:
"设置tab的快捷键
"Shift+t为新建一个标签,按两次Shirt+t为跳转标签
map <S-t> :tabnew .<CR>
map <S-t><S-t> <ESC>:tabnext<CR>
17、Python自动补全支持:
mkdir -p tools/pydiction/
mkdir -p after/ftplugin/
pydiction-1.2.zip解压放到~/.vim/after/ftplugin/ 路径下
将complete-dict文件放到~/.vim/tools/pydiction/目录中
在vimrc中写入:
"------------------------------------------------------
"设置python自动补全
"pydiction 1.2 python auto complete
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
let g:pydiction_menu_height = 20
18、自动检查Python语法:
pyflakes-vim.zip,在~/.vim/目录下解压。
19、Python常用功能:
python_fn.vim, 放到~/.vim/ftplugin/python中
20、Python代码自动折叠:
python_editing.vim,放在~/.vim/ftplugin/python中
21、代码文档化工具:
DoxygenToolkit.vim,放到~/.vim/plugin
安装doxygen:sudo apt-get install doxygen
在vimrc中写入:
map <F4>a :DoxAuthor<CR> 文件头注释
map <F4>f :Dox<CR>
map <F4>b :DoxBlock<CR>
map <F4>l :DoxLic<CR>
"map <F4>c odocClass<C-B>
"map <F4>m odocMember<C-B>
let g:DoxygenToolkit_authorName="pchuang, http://blog.csdn.net"
let s:licenseTag = "Copyright(C)\<enter>"
let s:licenseTag = s:licenseTag . "For free\<enter>"
let s:licenseTag = s:licenseTag . "All right reserved\<enter>"
let g:DoxygenToolkit_licenseTag = s:licenseTag
let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1
22、配置一键编译调试:
在vimrc中写入:
"--------------------------------------------------------
"添加自动编译和调试 现在使用交叉编译工具一下函数暂时不用
"map <F8> :w<CR>:call CompileRun()<CR>
"map <F8><F8> :w<CR>:call Debug()<CR>
func CompileRun()
exec "w"
if &filetype == 'c'
exec "!gcc % -g -o %<"
exec "!.\/%<"
elseif &filetype =='cpp'
exec "!g++ % -g -o %<"
exec "!.\/%<"
elseif &filetype == 'python'
exec "!python %"
endif
endfunc
func Debug()
exec "w"
if &filetype == 'c'
exec "!rm %<"
exec "!gcc % -g -o %<"
exec "!gdb %<"
elseif &filetype == 'cpp'
exec "!rm %<"
exec "!g++ % -g -o %<"
exec "!gdb %<"
exec "!rm %<.class"
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
elseif &filetype == 'python'
exec "!pdb %"
endif
endfunc
23、shell脚本自动加上执行权限:
在vimrc中写入:
"--------------------------------------------------------
"自动修改shell脚本执行权限
function ModeChange()
if getline(1) =~ "^#!"
if getline(1) =~ "/bin/"
silent !chmod a+x <afile>
endif
endif
endfunction
au BufWritePost * call ModeChange()
24、从上次退出时编辑的位置继续编辑:
在vimrc中写入:
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
25、配置括号自动添加:
在vimrc中写入:
"------------------------------------------------------
"配置括号自动添加:
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
26、添加一些快捷键:
在vimrc中写入:
map <F5> :w<CR>:make<CR>
map <F5><F5> :make clean<CR>
map <F6> :cw<CR>
map <F6><F6> :ccl<CR>
map <F7> :cn<CR>
map <F7><F7> :cp<CR>
map <S-o> o<ESC><CR>
map <C-a> ggVG
map <S-q><S-q> :q!<CR>:q!<CR>:q!<CR>
map <C-H> :L1,L2s/src/tar/g
map <S-F12> <ESC>I//<ESC><CR>
map! <S-F12> <ESC>I//<ESC><CR>
map <S-F12><S-F12> 02x<ESC><CR>
map! <S-F12><S-F12> <ESC>02x<ESC><CR>
map <F12> <ESC>$a//
map! <F12> <ESC>$a//
27、在vim配置文件/home/user/.vimrc中加入如下的配置:
"-- omnicppcomplete setting --
" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-I>
set completeopt=menu,menuone " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 " enable the global scope search
let OmniCpp_DisplayMode=1 " Class scope completion mode: always show all members
"let OmniCpp_DefaultNamespaces=["std"]
let OmniCpp_ShowScopeInAbbr=1 " show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1
1、设置静态IP修改/etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.12.51
netmask 255.255.255.0
gateway 192.168.12.254
2、修改 vim /etc/samba/smb.conf
添加smb共享目录
[work]
comment = work
path = /home/usrname
guest ok = no
browseable = yes
create mask = 0775
directory mask = 0775
3、修改用户组:
chown usrname:usrname usrname
4、添加BCM、ST、MSTAR、HISI的编译环境放在/opt/目录下
5、安装编译使用工具:sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 /*不安装会提示找不到编译工具,并且无法执行。错误提示bash: ./arm-none-linux-gnueabi-gcc: No such file or directory*/
sudo apt-get install liblzo2-dev/*64位*/
sudo apt-get install liblzo2-dev:i386/*32位*/
sudo apt-get install uuid-dev:i386/*32位*/
sudo apt-get install gcc
sudo apt-get install lib32stdc++6
sudo apt-get install build-essential bison libc6-dev
6、安装小乌龟工具:sudo apt-get install subversion
7、安装NFS服务器:
sudo apt-get install nfs-kernel-server nfs-common portmap
配置NFS服务器:vim /etc/exports
最后一行添加:
/home *(rw,sync,no_root_squash,no_subtree_check)
B、2014.10.30
1、配置GVim::vim .vimrc
set wildmenu "增强模式中的命令行自动完成操作
set foldmethod=manual "设定折叠方式为手动
set sta "插入<tab>时使用'shiftwidth'
syntax enable "设置高亮关键字显示
"set background=dark "背景使用黑色
"set enc=utf-8 "设置编码为中文
set winaltkeys=no "Alt组合键不映射到菜单上
autocmd FileType python setlocal et sta sw=4 sts=4
" 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 nocompatible
" detect file type
filetype on
filetype plugin on
" 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
"have Vim load indentation rules and plugins according to the detected filetype
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 ignorecase " 搜索模式里忽略大小写
"set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。
set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
"set smartindent " 智能对齐方式
set tabstop=4 " 设置制表符(tab键)的宽度
set softtabstop=4 " 设置软制表符的宽度
set shiftwidth=4 " (自动) 缩进使用的4个空格
set cindent " 使用 C/C++ 语言的自动缩进方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
"set backspace=2 " 设置退格键可用
set showmatch " 设置匹配模式,显示匹配的括号
set linebreak " 整词换行
set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
"set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes) "使用鼠标
set number " Enable line number "显示行号
"set previewwindow " 标识预览窗口
set history=50 " set command history to 50 "历史记录50条
"--状态行设置--
set laststatus=2 " 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P> "设置状态栏
set ruler " 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。
"--命令行设置--
set showcmd " 命令行显示输入的命令
set showmode " 命令行显示vim当前模式
"--find setting--
set incsearch " 输入字符串就显示匹配点
set hlsearch
2、安装vim中文帮助手册
$tar xvf vimcdoc-1.8.0.tar.gz
$cd vimcdoc-1.8.0/
$./vimcdoc.sh -i
~/.vimrc里加上set helplang=cn
3、添加bash和C/C++支持
unzip bash-support.zip
unzip cvim.zip
4、安装tags和taglist
sudo apt-get install exuberant-ctags
unzip taglist_46.zip
5、WinManager(调整窗口布局)
unzip winmanager.zip
6、安装cscope:
sudo apt-get install cscope
7、配置自动补全建立系统tags
ctags -R -f ~/.vim/systags –c-kinds=+p –c++-kinds=+px –fields=+iaS –extra=+q –python-kinds=-i /usr/include /usr/local/include
8、修改.vimrc文件
"禁止自动改变当前Vim窗口的大小
let Tlist_Inc_Winwidth=0
"把方法列表放在屏幕的右侧
let Tlist_Use_Right_Window=1
"让当前不被编辑的文件的方法列表自动折叠起来, 这样可以节约一些屏幕空间
let Tlist_File_Fold_Auto_Close=1
"映射F3为功能键调出winmanager的文件浏览器
"映射双击F3调出Taglist的符号浏览器
"let g:winManagerWindowLayout='FileExplorer|TagList' "你要是喜欢这种布局可以注释掉这一行
map <F3> :WMToggle<cr>
map <F3><F3> :TlistToggle<cr>
"将系统已经生成的tags导入
set tags+=~/.vim/systags
"映射F10为添加cscope和ctags
map <F10> :call Do_CsTag()<CR>
map <F10><F10> :call Add_CsTag()<CR>
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>
function Do_CsTag()
silent! execute "!ctags -R '.'"
if(executable('cscope') && has("cscope") )
silent! execute "!find -L `pwd` -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' -o -name '*.cxx' -o -name '*.hxx'> cscope.files -o -name '*.hpp' -o -name '*.py'" endif
silent! execute "!cscope -bq"
silent! execute "call Add_CsTag()"
endf
function Add_CsTag()
if filereadable("cscope.out")
execute "cs add cscope.out"
execute "set tags+=./tags"
endif
endf
silent! execute "call Add_CsTag()"
9、同名头文件和源文件切换:
a.vim 放到 ~/.vim/plugin 中
10、代码块和常用语句模板自动补全
code_complete.vim放到 ~/.vim/plugin 中
将下边这一段加入到template段中以添加bash模板补全功能
"Bash Templates
"Bash Structure by warmbupt@gmail.com
let g:template['sh'] = {}
let g:template['sh']['sif'] = "if ".g:rs."…".g:re." ; then/".g:rs."…".g:re."/fi"
let g:template['sh']['sife'] = "if ".g:rs."…".g:re." ; then/".g:rs."…".g:re."/else/".g:rs."…".
/g:re."/fi"
let g:template['sh']['scase'] = "case ".g:rs."…".g:re." in/".g:rs."…".g:re.")//" .g:rs."…".g:re.";;//".
/g:rs."…".g:re.")//" .g:rs."…".g:re.";;///esac/"
let g:template['sh']['swhile'] = "while ".g:rs."…".g:re." /do/".g:rs."…".g:re."/done"
let g:template['sh']['suntil'] = "until ".g:rs."…".g:re." /do/".g:rs."…".g:re."/done"
let g:template['sh']['sfor'] = "for ".g:rs."…".g:re." in " .g:rs."…".g:re."/do/".g:rs."…".g:re."/done"
let g:template['sh']['sselect'] = "select ".g:rs."…".g:re." in " .g:rs."…".g:re."/do/".g:rs."…".g:re."/done"
11、代码补全:supertab+snipMate+omnicppcomplete
vim打开supertab.vba,然后使用:so % 进行安装
vim neocomplcache-6.1.vba然后使用:so % 进行安装
12、函数原型提示:
echofunc.vim放到 ~/.vim/plugin 中
在 ~/.vimrc中添加:
"-------------------------------------------------
"函数原型提示
let g:EchoFuncKeyNext='<C-n>'
let g:EchoFuncKeyPrev='<C-p>'
13、.C/STL/Python Doc提示:
tar xvf stlrefvim.tar.gz
unzip crefvim.zip
unzip pyref.zip
把plugin/pyref.vim移动到ftplugin中,这样只针对python文件的插件。
在.vimrc中添加:let g:pyref_mapping = 'K'
14、简单注释:
comments.vim放到plugin目录中
15、代码格式整理:
在vimrc中写入:
"定义源代码格式化
map <F12> :call FormartSrc()<CR>
"定义FormartSrc()
func FormartSrc()
exec "w"
if &filetype == 'c'
exec "!astyle % –style=ansi –suffix=none %"
exec "e! %"
elseif &filetype == 'cpp'
"exec "!astyle % –style=ansi –suffix=none %"
"exec "e! %"
elseif &filetype == 'perl'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'py'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'java'
exec "!astyle –style=java –suffix=none %"
exec "e! %"
elseif &filetype == 'jsp'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'xml'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'html'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
elseif &filetype == 'htm'
exec "!astyle –style=gnu –suffix=none %"
exec "e! %"
endif
endfunc
"结束定义FormartSrc
16、多tab支持:
unzip NERD_tree.zip
在vimrc中写入:
"设置tab的快捷键
"Shift+t为新建一个标签,按两次Shirt+t为跳转标签
map <S-t> :tabnew .<CR>
map <S-t><S-t> <ESC>:tabnext<CR>
17、Python自动补全支持:
mkdir -p tools/pydiction/
mkdir -p after/ftplugin/
pydiction-1.2.zip解压放到~/.vim/after/ftplugin/ 路径下
将complete-dict文件放到~/.vim/tools/pydiction/目录中
在vimrc中写入:
"------------------------------------------------------
"设置python自动补全
"pydiction 1.2 python auto complete
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
let g:pydiction_menu_height = 20
18、自动检查Python语法:
pyflakes-vim.zip,在~/.vim/目录下解压。
19、Python常用功能:
python_fn.vim, 放到~/.vim/ftplugin/python中
20、Python代码自动折叠:
python_editing.vim,放在~/.vim/ftplugin/python中
21、代码文档化工具:
DoxygenToolkit.vim,放到~/.vim/plugin
安装doxygen:sudo apt-get install doxygen
在vimrc中写入:
map <F4>a :DoxAuthor<CR> 文件头注释
map <F4>f :Dox<CR>
map <F4>b :DoxBlock<CR>
map <F4>l :DoxLic<CR>
"map <F4>c odocClass<C-B>
"map <F4>m odocMember<C-B>
let g:DoxygenToolkit_authorName="pchuang, http://blog.csdn.net"
let s:licenseTag = "Copyright(C)\<enter>"
let s:licenseTag = s:licenseTag . "For free\<enter>"
let s:licenseTag = s:licenseTag . "All right reserved\<enter>"
let g:DoxygenToolkit_licenseTag = s:licenseTag
let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1
22、配置一键编译调试:
在vimrc中写入:
"--------------------------------------------------------
"添加自动编译和调试 现在使用交叉编译工具一下函数暂时不用
"map <F8> :w<CR>:call CompileRun()<CR>
"map <F8><F8> :w<CR>:call Debug()<CR>
func CompileRun()
exec "w"
if &filetype == 'c'
exec "!gcc % -g -o %<"
exec "!.\/%<"
elseif &filetype =='cpp'
exec "!g++ % -g -o %<"
exec "!.\/%<"
elseif &filetype == 'python'
exec "!python %"
endif
endfunc
func Debug()
exec "w"
if &filetype == 'c'
exec "!rm %<"
exec "!gcc % -g -o %<"
exec "!gdb %<"
elseif &filetype == 'cpp'
exec "!rm %<"
exec "!g++ % -g -o %<"
exec "!gdb %<"
exec "!rm %<.class"
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
elseif &filetype == 'python'
exec "!pdb %"
endif
endfunc
23、shell脚本自动加上执行权限:
在vimrc中写入:
"--------------------------------------------------------
"自动修改shell脚本执行权限
function ModeChange()
if getline(1) =~ "^#!"
if getline(1) =~ "/bin/"
silent !chmod a+x <afile>
endif
endif
endfunction
au BufWritePost * call ModeChange()
24、从上次退出时编辑的位置继续编辑:
在vimrc中写入:
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
25、配置括号自动添加:
在vimrc中写入:
"------------------------------------------------------
"配置括号自动添加:
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
26、添加一些快捷键:
在vimrc中写入:
map <F5> :w<CR>:make<CR>
map <F5><F5> :make clean<CR>
map <F6> :cw<CR>
map <F6><F6> :ccl<CR>
map <F7> :cn<CR>
map <F7><F7> :cp<CR>
map <S-o> o<ESC><CR>
map <C-a> ggVG
map <S-q><S-q> :q!<CR>:q!<CR>:q!<CR>
map <C-H> :L1,L2s/src/tar/g
map <S-F12> <ESC>I//<ESC><CR>
map! <S-F12> <ESC>I//<ESC><CR>
map <S-F12><S-F12> 02x<ESC><CR>
map! <S-F12><S-F12> <ESC>02x<ESC><CR>
map <F12> <ESC>$a//
map! <F12> <ESC>$a//
27、在vim配置文件/home/user/.vimrc中加入如下的配置:
"-- omnicppcomplete setting --
" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-I>
set completeopt=menu,menuone " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 " enable the global scope search
let OmniCpp_DisplayMode=1 " Class scope completion mode: always show all members
"let OmniCpp_DefaultNamespaces=["std"]
let OmniCpp_ShowScopeInAbbr=1 " show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1
相关文章推荐
- C/C++是怎么通过宏定义来判断操作系统的
- 第三方支付熟悉
- (FFOS Gecko & Gaia) OTA - 处理check结果
- 集训第四周(高效算法设计)A题 Ultra-QuickSort
- 区间DP UVA 11584 Partitioning by Palindromes
- Context-----Activity,Application之间的交流使者
- Windows10占用80端口,Apache无法启动的解决办法
- 配置ISCSI
- 南邮 OJ 1217 双色Hanoi塔问题
- 回调函数中JSON对象的解析方式
- iOS开发之获取沙盒路径
- 关于scheme的缩写
- python多线程编程(3): 使用互斥锁同步线程
- DEV控件:gridControl常用属性设置
- HDU 3720 深搜 枚举
- 经典SQL语句大全
- Spring 注解的方式进行事务管理
- hdu 2149 Public Sale(巴什博奕)
- LAMP环境的搭建
- CodeForces 1C - Ancient Berland Circus