termencoding:VIM 所工作的终端 (或者 Windows 的 Console 窗口) 的字符编码方式。这个选项在 Windows 下对我们常用的 GUI 模式的 gVim 无效,而对 Console 模式的 Vim 而言就是 Windows 控制台的代码页,并且通常我们不需要改变它。
配置
1
set fileencodings=utf-8,gb2312,gbk,gb18030 " 自动从这些编码识别文件编码
命令
:set fileencoding=utf-8: 将文件用utf-8保存
:e ++enc=gbk: 使用gbk重新打开文件
:w ++enc=utf-8: 使用utf-8保存文件
4. 格式
配置
1
set fileformats=unix,dos " 自动识别unix和dos格式打开
命令
:set fileformat=unix: 将文件以unix保存
5. 读取和保存
配置
1 2 3
set autoread " 外部改动自动读取 set autowriteall " 和autowrite类似,不过支持跳转命令保存 set noswapfile " 不创建临时文件,防止被提交上去
6. 高亮
取消高亮
1 2
setnohlsearch setnoh
7. 行号
1 2
setnumber" 显示行号 set nonumber " 取消显示行号
8. tab缩进
8.1. 配置
1 2 3 4 5 6 7 8
set tabstop=4" 4个空格识别成tab,读到的\t解释成4个空格 set softtabstop=4" tab输入为4个空格宽度 setshiftwidth=4" 换行时的自动缩进列数 set expandtab " 输入tab转成空格 set noexpandtab " 输入tab不转成空格 set autoindent " 自动缩进 set smartindent " 智能缩进 filetypeindenton" 不同文件使用不同缩进
# 安装依赖库 sudo apt install gcc make libncurses5-dev libncursesw5-dev # 解压global到/opt目录 tar -xzvf globalxxx.tar.gz mv globalxxx /opt/global # 编译安装 cd /opt/global ./configure make sudo make install
配置
由于gtags和gscope可以增量更新tags文件,那不用想,肯定用
cscope直接弃用
ctags不能直接弃用,因为和vim深度匹配,但是gtags可以包含它的功能
那么就只用ctags来生成系统函数的标签,工程目录的标签全部交给gtags和gscope来监管
当前就出现,如果工程内查找,使用vim-gutentags的快捷键
如果需要看系统函数原型,使用ctags的快捷键Ctrl + ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
" gutentags set rtp+=~/.vim/bundle/vim-gutentags set cscopetag " use cscope for tags command set cscopeprg='gtags-cscope'" replace cscope with gtags-cscope letg:gutentags_auto_add_gtags_cscope=0" disable gutentags auto add gtags_cscope, use plus plugin to do this letg:gutentags_define_advanced_commands = 1" enable gutentags use advanced commands letg:gutentags_modules=['gtags_cscope'] " enable gtags module letg:gutentags_project_root = ['.root'] " define project root dir/file name for gutentags letg:gutentags_add_default_project_roots = 0" won't add default roots, only use root dir/file user add " let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q', '--c++-kinds=+px', '--c-kinds=+px'] " ctags extra args letg:gutentags_cache_dir = expand('~/.cache/tags') " put tags out of project
nmap<leader>d yiw:GscopeFind g <C-R>"<cr> :2cc<cr> :cclose<cr>
" gutentags_plus set rtp+=~/.vim/bundle/gutentags_plus
# These are the compilation flags that will be used in case there's no # compilation database set (by default, one is not set). # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. flags = [ '-Wall', '-Wextra', '-Werror', '-fexceptions', '-DNDEBUG', # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which # language to use when compiling headers. So it will guess. Badly. So C++ # headers will be compiled as C headers. You don't want that so ALWAYS specify # a "-std=<something>". # For a C project, you would set this to something like 'c99' instead of # 'c++11'. '-std=c++11', # ...and the same thing goes for the magic -x option which specifies the # language that the files to be compiled are written in. This is mostly # relevant for c++ headers. # For a C project, you would set this to 'c' instead of 'c++'. '-x', 'c++', '-isystem', '/usr/include/c++/9', '-isystem', '/usr/include', ]
" 1. Search in a specific sub-directory :CtrlSF {pattern} /path/to/dir
" 2. Search case-insensitively :CtrlSF -I foo
" 2. Search case-sensitively :CtrlSF -S Foo
" 3. Search with regular expression :CtrlSF -R {regex}
" 4. Show result with specific context setting :CtrlSF -A 3 -B 1 {pattern}
" 5. Search with specify filetype :CtrlSF -T {filetype} {pattern}
快捷键
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Maps by default in CtrlSF window: <Enter>, <o>, <2-LeftMouse> Open file which contains the line under cursor. <C-O> Open file in a horizontally split window. <p> Open a preview window to view file. <P> Open a preview window to view file and switch focus to it. <O> Like <o>, but always leave CtrlSF window open. <T> Like <t>, but focus CtrlSF window instead of opened new tab. <q> Quit CtrlSF. Also close preview window if any. <C-C> Stop running asynchronous searching. <C-J> Move cursor to next match. <C-K> Move cursor to previous match.
Maps by default in preview window: <q> Quit preview mode.