MalacoWiki

wiki of malacology

Vim

vim 是一款不错的终端文本编辑器

vim基础配置

对于主题,我使用比较流行的 gruvbox,使用以下命令安装

yay -S vim-gruvbox

配置文件为~/.vimrc,不同用户的~不同,需要自行配置。

"设置搜索高亮
set hlsearch
"启用高亮
syntax on
"设置当前行突出显示
set cursorline
"设置显示行号
set number
"选择颜色配置为gruvbox(这里可以看/usr/share/vim/vim82/colors/下的颜色方案)
colorscheme gruvbox
set bg=dark
"设置立即显示搜索高亮
set incsearch
"设置字典(ctrl+x;ctrl+k)模式会调用
set spell
set dictionary=/home/i/.vim/funclist.txt
set complete+=k
" autocmd是设置文件类型的自动补全,ctrl+x;ctrl+o可以调用
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
" 设置SuperTabContinued插件的默认tab方式,奶牛这里用的是上方所说的ctrl+x;ctrl+o调用
" let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
" 设置默认打开html等网页文件的自动补全
autocmd BufNewFile,BufRead *.html,*.htm,*.xml inoremap </ </<c-x><c-o>
" 指定某些类型新建文件时候的自动补全方式,例如js,更上面的那个设置略有不同
autocmd BufNewFile,BufRead *.js set omnifunc=javascriptcomplete#CompleteJS
" 自动补齐括号书名号引号等设置
inoremap ( ()<LEFT>
inoremap [ []<LEFT>
inoremap { {}<LEFT>
inoremap ' ''<LEFT>
inoremap " ""<LEFT>
" 鼠标
set mouse=a
" 跨行移动光标
set whichwrap=b,s,<,>,[,]
" 记录光标位置
augroup resCur
  autocmd!
  autocmd BufReadPost * call setpos(".", getpos("'\""))
augroup END
" 快捷键设置,符合习惯,Ctrl+C 复制 Ctrl+V 粘贴 Ctrl+S 保存 Ctrl+Q 退出 Ctrl+A 全选 Ctrl+F 搜索 Ctrl+Z 撤销 Ctrl+Y 重做
vmap <C-c> "+y
vmap <C-x> "+c
nmap <C-v> i<CR>"+gP<CR>
vmap <C-v> "+p
imap <C-v> <C-r><C-o>"+
imap <C-s> <ESC>:w<CR>
nmap <C-q> :wq<CR>
imap <C-q> <ESC>:wq<CR>
nmap <C-a> ggVG<CR>
imap <C-a> <ESC>ggVR<CR>i
imap <C-f> <ESC>/
nmap <C-f> /
imap <C-z> <ESC>u<CR>i
nmap <C-z> u<CR>
imap <C-y> <ESC>^R<CR>i
nmap <C-y> ^R<CR>

文件列表 nerdtree

安装插件

sudo pacman -S vim-nerdtree

配置文件

" NERDTree config
map <C-n> :NERDTreeToggle<CR>
" 自动关闭多个窗口
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif
" 自动打开
" autocmd vimenter * NERDTree
" 显示隐藏文件
let NERDTreeShowHidden=1
" 高亮当前文件
let NERDTreeHightCursorline=1
" 关闭文件夹 o
" 显示菜单   m
" 打开上层   u

tag列表 tagbar

这个主要是针对编程文件

sudo pacman -S vim-tagbar

配置文件

" Tagbar config
" 将开启tagbar的快捷键设置为 <Leader>tb
nmap <F12> :TagbarToggle<CR>
let g:tagbar_ctags_bin='/usr/bin/ctags'  " 设置ctags所在路径
let g:tagbar_width=25 "设置tagbar的宽度
" 在某些情况自动打开,这里是 cpp c h hpp cc cxx 文件后缀的自动打开
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()

语法检查 syntastic

安装

sudo pacman -S vim-syntastic

配置

" syntastic config
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
let g:syntastic_loc_list_height = 4 "设置高度

补全插件 youcompleteme

安装

yay -S 	vim-youcompleteme-git

配置

" complete config
let g:ycm_min_num_identifier_candidate_chars = 2
let g:ycm_key_invoke_completion = '<C-b>'
let g:ycm_semantic_triggers =  {
  \   'c' : ['->', '.'],
  \   'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
  \             're!\[.*\]\s'],
  \   'ocaml' : ['.', '#'],
  \   'cpp,objcpp' : ['->', '.', '::'],
  \   'perl' : ['->'],
  \   'php' : ['->', '::'],
  \   'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
  \   'ruby' : ['.', '::'],
  \   'lua' : ['.', ':'],
  \   'erlang' : [':'],
  \ }

文献引用 pandoc插件

安装

yay -S vim-pandoc-git

配置

" pandoc config
" 激活pandoc
let g:pandoc#filetypes#handled = ["pandoc", "markdown"]
let g:pandoc#filetypes#pandoc_markdown = 0
"let g:pandoc#modules#enabled = ["formatting"]
let g:pandoc#folding#mode = "syntax" "relative差别小,stacked没有差别
"g:pandoc#folding#fold_yaml = "1" "YAML文件的folding
let g:pandoc#folding#fastfolds = "1" "为了folding的计算正确
let g:pandoc#biblio#sources = "bcg" "同名同目录b 当前目录c default文件l 规定的g:pandoc#biblio#bibs为g
let b:pandoc_biblio_bibs = "./bib.bib" "设置bib文件名
"let g:pandoc#biblio#use_bibtool = 1 "补全,yay -S bibtool
let g:pandoc#completion#bib#mode = "fallback" "fallaback支持bibtex
" omnicppcomplete 快捷键<C-x><C-o>引用
filetype plugin on
set omnifunc=syntaxcomplete#Complete
" vim-pandoc 与 vim-youcompleteme 联动
  if !exists('g:ycm_semantic_triggers')
    let g:ycm_semantic_triggers = {}
  endif
  let g:ycm_semantic_triggers.pandoc = ['@']

  let g:ycm_filetype_blacklist = {}
Last updated on 28 Oct 2021
Published on 28 Oct 2021

Powered by Arch. Copyright by Guoyi.