2023年8月2日发(作者:)
Linux——VIM开发C++⾃动补全(STL、括号)和开发环境配置⾸先确定vim编辑.cc或者.cpp⽂件时当前⾃动补全函数,在命令模式下输⼊
:set omnifunc?
如果得到的结果为:omnifunc=ccomplete#Complete,说明有必要进⾏以下的操作以实现针对c++的⾃动补全set tags+=~/.vim/tags/cpp_src/tags
4 修改~/.vimrc⽂件
在其中加⼊以下内容:"This line should not be removed as it ensures that various options are" properly set to work with the Vim-related packages available in " Uncomment the next line to make Vim more Vi-compatible" NOTE: sets 'nocompatible'. Setting 'compatible' changes numerous" options, so any other options should be set AFTER setting 'compatible'.set nocompatible" Vim5 and later versions support syntax highlighting. Uncommenting the" following enables syntax highlighting by has("syntax") syntax on " 语法⾼亮endifcolorscheme ron " elflord ron peachpuff default 设置配⾊⽅案,vim⾃带的配⾊⽅案保存在/usr/share/vim/vim72/colors⽬录下" detect file typefiletype onfiletype plugin on" If using a dark background within the editing area and syntax highlighting" turn on this option as wellset background=dark" Uncomment the following to have Vim jump to the last position when" reopening a fileif 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 onendif" 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-] 和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 abandonedset mouse=a " Enable mouse usage (all modes) "使⽤⿏标set number " Enable line number "显⽰⾏号"set previewwindow " 标识预览窗⼝"--状态⾏设置--set laststatus=2 " 总显⽰最后⼀个窗⼝的状态⾏;设为1则窗⼝数多于⼀个的时候显⽰最后⼀个窗⼝的状态⾏;0不显⽰最后⼀个窗⼝的状态⾏set ruler " 标尺,⽤于显⽰光标位置的⾏号和列号,逗号分隔。每个窗⼝都有⾃⼰的标尺。如果窗⼝有状态⾏,标尺在那⾥显⽰。否则,它显⽰在屏幕的"--命令⾏设置--set showcmd " 命令⾏显⽰输⼊的命令set showmode " 命令⾏显⽰vim当前模式"--find setting--set incsearch " 输⼊字符串就显⽰匹配点set hlsearch
" configure tags - add additional tags here or comment out not-used ones set tags+=~/.vim/tags/cpp set tags+=~/.vim/tags/gl set tags+=~/.vim/tags/fl
" build tags of your own project with CTRL+F12 map
⽤vim打开cpp⽂件,输⼊
std::
将得到std命名空间的所有标⽰符,按CTRL+N或者CTRL+P选择
继续输⼊std::vector vi,然后输⼊
vi.
vim将⾃动提⽰其成员我拉.vimrc(这个⽂件是在~⽂件夹下,⽤ ls -al 就可以看到) " configure tags - add additional tags here or comment out not-used ones set tags+=~/.vim/tags/cpp_src/tags set tags+=~/.vim/tags/gl set tags+=~/.vim/tags/fl " build tags of your own project with CTRL+F12 map
nnoremap
"⽐较⽂件
nnoremap
"新建标签
map
"列出当前⽬录⽂件
map
"打开树状⽂件⽬录
map
"C,C++ 按F5编译运⾏map
exec "!javac %"
exec "!java %<" elseif &filetype == 'sh' :!./% endifendfunc"C,C++的调试map
set completeopt=preview,menu
"允许插件
filetype plugin on"共享剪贴板
set clipboard+=unnamed
"从不备份
set nobackup"make 运⾏:set makeprg=g++ -Wall %"⾃动保存set autowriteset ruler " 打开状态栏标尺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=0set foldmethod=indent
set foldlevel=3
set foldenable " 开始折叠" 不要使⽤vi的键盘模式,⽽是vim⾃⼰的set nocompatible" 语法⾼亮set syntax=on" 去掉输⼊错误的提⽰声⾳set noeb" 在处理未保存或只读⽂件的时候,弹出确认set confirm" ⾃动缩进set autoindentset cindent" Tab键的宽度set tabstop=4" 统⼀缩进为4set softtabstop=4set shiftwidth=4" 不要⽤空格代替制表符set noexpandtab" 在⾏和段开始处使⽤制表符set smarttab" 显⽰⾏号set number" 历史记录数set history=1000"禁⽌⽣成临时⽂件set nobackupset noswapfile"搜索忽略⼤⼩写set ignorecase"搜索逐字符⾼亮set hlsearchset incsearch"⾏内替换set gdefault"编码设置set enc=utf-8set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936"语⾔设置set langmenu=zh_-8set 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,这⾥是2set 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=aset selection=exclusiveset 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⽂件(需要脚本)au BufRead,BufNewFile * setfiletype txt"⾃动补全:inoremap ( ()
"打开⽂件类型检测, 加了这句才可以⽤智能补全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:toolsjavatags
"autocmd FileType h,cpp,cc,c set tags+=D:toolscpptags
"let Tlist_Show_One_File=1 "不同时显⽰多个⽂件的tag,只显⽰当前⽂件的"设置tags
set tags=tags
"set autochdir """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""其他东东""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""默认打开Taglist
let Tlist_Auto_Open=1
2023年8月2日发(作者:)
Linux——VIM开发C++⾃动补全(STL、括号)和开发环境配置⾸先确定vim编辑.cc或者.cpp⽂件时当前⾃动补全函数,在命令模式下输⼊
:set omnifunc?
如果得到的结果为:omnifunc=ccomplete#Complete,说明有必要进⾏以下的操作以实现针对c++的⾃动补全set tags+=~/.vim/tags/cpp_src/tags
4 修改~/.vimrc⽂件
在其中加⼊以下内容:"This line should not be removed as it ensures that various options are" properly set to work with the Vim-related packages available in " Uncomment the next line to make Vim more Vi-compatible" NOTE: sets 'nocompatible'. Setting 'compatible' changes numerous" options, so any other options should be set AFTER setting 'compatible'.set nocompatible" Vim5 and later versions support syntax highlighting. Uncommenting the" following enables syntax highlighting by has("syntax") syntax on " 语法⾼亮endifcolorscheme ron " elflord ron peachpuff default 设置配⾊⽅案,vim⾃带的配⾊⽅案保存在/usr/share/vim/vim72/colors⽬录下" detect file typefiletype onfiletype plugin on" If using a dark background within the editing area and syntax highlighting" turn on this option as wellset background=dark" Uncomment the following to have Vim jump to the last position when" reopening a fileif 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 onendif" 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-] 和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 abandonedset mouse=a " Enable mouse usage (all modes) "使⽤⿏标set number " Enable line number "显⽰⾏号"set previewwindow " 标识预览窗⼝"--状态⾏设置--set laststatus=2 " 总显⽰最后⼀个窗⼝的状态⾏;设为1则窗⼝数多于⼀个的时候显⽰最后⼀个窗⼝的状态⾏;0不显⽰最后⼀个窗⼝的状态⾏set ruler " 标尺,⽤于显⽰光标位置的⾏号和列号,逗号分隔。每个窗⼝都有⾃⼰的标尺。如果窗⼝有状态⾏,标尺在那⾥显⽰。否则,它显⽰在屏幕的"--命令⾏设置--set showcmd " 命令⾏显⽰输⼊的命令set showmode " 命令⾏显⽰vim当前模式"--find setting--set incsearch " 输⼊字符串就显⽰匹配点set hlsearch
" configure tags - add additional tags here or comment out not-used ones set tags+=~/.vim/tags/cpp set tags+=~/.vim/tags/gl set tags+=~/.vim/tags/fl
" build tags of your own project with CTRL+F12 map
⽤vim打开cpp⽂件,输⼊
std::
将得到std命名空间的所有标⽰符,按CTRL+N或者CTRL+P选择
继续输⼊std::vector vi,然后输⼊
vi.
vim将⾃动提⽰其成员我拉.vimrc(这个⽂件是在~⽂件夹下,⽤ ls -al 就可以看到) " configure tags - add additional tags here or comment out not-used ones set tags+=~/.vim/tags/cpp_src/tags set tags+=~/.vim/tags/gl set tags+=~/.vim/tags/fl " build tags of your own project with CTRL+F12 map
nnoremap
"⽐较⽂件
nnoremap
"新建标签
map
"列出当前⽬录⽂件
map
"打开树状⽂件⽬录
map
"C,C++ 按F5编译运⾏map
exec "!javac %"
exec "!java %<" elseif &filetype == 'sh' :!./% endifendfunc"C,C++的调试map
set completeopt=preview,menu
"允许插件
filetype plugin on"共享剪贴板
set clipboard+=unnamed
"从不备份
set nobackup"make 运⾏:set makeprg=g++ -Wall %"⾃动保存set autowriteset ruler " 打开状态栏标尺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=0set foldmethod=indent
set foldlevel=3
set foldenable " 开始折叠" 不要使⽤vi的键盘模式,⽽是vim⾃⼰的set nocompatible" 语法⾼亮set syntax=on" 去掉输⼊错误的提⽰声⾳set noeb" 在处理未保存或只读⽂件的时候,弹出确认set confirm" ⾃动缩进set autoindentset cindent" Tab键的宽度set tabstop=4" 统⼀缩进为4set softtabstop=4set shiftwidth=4" 不要⽤空格代替制表符set noexpandtab" 在⾏和段开始处使⽤制表符set smarttab" 显⽰⾏号set number" 历史记录数set history=1000"禁⽌⽣成临时⽂件set nobackupset noswapfile"搜索忽略⼤⼩写set ignorecase"搜索逐字符⾼亮set hlsearchset incsearch"⾏内替换set gdefault"编码设置set enc=utf-8set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936"语⾔设置set langmenu=zh_-8set 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,这⾥是2set 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=aset selection=exclusiveset 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⽂件(需要脚本)au BufRead,BufNewFile * setfiletype txt"⾃动补全:inoremap ( ()
"打开⽂件类型检测, 加了这句才可以⽤智能补全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:toolsjavatags
"autocmd FileType h,cpp,cc,c set tags+=D:toolscpptags
"let Tlist_Show_One_File=1 "不同时显⽰多个⽂件的tag,只显⽰当前⽂件的"设置tags
set tags=tags
"set autochdir """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""其他东东""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""默认打开Taglist
let Tlist_Auto_Open=1
发布评论