vim config 2023



" echo $MYVIMRC
" source $MYVIMRC

set enc=utf-8
set fencs=utf-8,gbk,big5,cp936,gb18030,gb2312,utf-16
set fenc=utf-8
set shortmess=atI

"禁止bell
set belloff=all
set visualbell
set t_vb=

let mapleader = "\<Space>"
inoremap jj <ESC>

"-------------------------------------------------------------------------------
" 安装插件
"-------------------------------------------------------------------------------
call plug#begin()
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

Plug 'neoclide/coc.nvim', {'branch': 'release'}

"Plug 'Valloric/YouCompleteMe'
"Plug 'rdnetto/YCM-Generator'

Plug 'universal-ctags/ctags'
Plug 'preservim/tagbar'
Plug 'ludovicchabant/vim-gutentags'

"Plug 'ervandew/supertab'
Plug 'scrooloose/syntastic'
Plug 'puremourning/vimspector'

Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install'  }
Plug 'leafgarland/typescript-vim'
Plug 'tbastos/vim-lua'
Plug 'tikhomirov/vim-glsl'
Plug 'moll/vim-node'
Plug 'vhdirk/vim-cmake'
Plug 'lervag/vimtex'
Plug 'fatih/vim-go'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'rhysd/vim-clang-format'

Plug 'jrozner/vim-antlr'
Plug 'elzr/vim-json'
Plug 'pearofducks/ansible-vim'
Plug 'ekalinin/dockerfile.vim'
Plug 'aklt/plantuml-syntax'

Plug 'vim-airline/vim-airline'
Plug 'sickill/vim-monokai'
Plug 'ryanoasis/vim-devicons'

Plug 'luochen1990/rainbow'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'

Plug 'nathanaelkane/vim-indent-guides'
Plug 'tpope/vim-fireplace'
Plug 'skywind3000/asyncrun.vim'
Plug 'skywind3000/vim-quickui'
Plug 'dense-analysis/ale'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'tpope/vim-unimpaired'
Plug 'yggdroot/leaderf'
Plug 'godlygeek/tabular'
Plug 'chiel92/vim-autoformat'
Plug 'editorconfig/editorconfig-vim'

Plug 'bronson/vim-trailing-whitespace'
Plug 'tpope/vim-commentary'

Plug 'puremourning/vimspector'

Plug 'voldikss/vim-floaterm'

Plug '907th/vim-auto-save'

call plug#end()

"-------------------------------------------------------------------------------
" 去除行尾空白符 bronson/vim-trailing-whitespace
"-------------------------------------------------------------------------------
"This plugin causes trailing whitespace to be highlighted in red.

"To fix the whitespace errors, call :FixWhitespace.

"By default it operates on the entire file.

"Pass a range (or use V to select some lines)
"to restrict the portion of the file that gets fixed.

"fun! TrimWhiteSpace()
"    let l:save = winsaveview()
"    keeppatterns %s/\s\+$//e
"    call winrestview(l:save)
"endfun

"noremap <leader>t :call :FixWhitespace <CR>

"-------------------------------------------------------------------------------
" 注释 vim-commentary
"-------------------------------------------------------------------------------
" toggle注释单行
" normal mode: gcc

" toggle 多行注释
" 首先进入visual mode,然后选择。gc toggle注释

"-------------------------------------------------------------------------------
" 缩进
"-------------------------------------------------------------------------------
"  visual mode
"  shift+< 然后 > 增加缩进
"  shift+> 然后 > 减少缩进

" normal mode
" shift + > + >
" shift + < + <

"-------------------------------------------------------------------------------
" 大小写转换
"-------------------------------------------------------------------------------
"  visual mode
"  ~

"-------------------------------------------------------------------------------
"  视图
"-------------------------------------------------------------------------------
" normal mode
" <C-O>  <C-I> zz
" <C-E>  <C-D>
" <C-Y>  <C-U>
" G      gg

"-------------------------------------------------------------------------------
"  选择
"-------------------------------------------------------------------------------
" Make vaa select the entire file...
xmap aa VGo1G

" -------------------------------------------------------------------------------
" 搜索 yggdroot/leaderf
" -------------------------------------------------------------------------------
" 编译C语言扩展,搜索会快10倍
":LeaderfInstallCExtension

"<leader>f 打开窗口
"<C-R> 切换搜索模式,fuzzy或regex
"Ctrl j k 在搜索结果中选择
"<C-T> 在新标签页打开文件
"<C-]> 竖向分隔窗口打开文件

" let g:Lf_WindowPosition = 'popup'
let g:Lf_PreviewInPopup = 1
let g:Lf_WindowHeight = 0.85
let g:Lf_DefaultExternalTool = 'rg'
let g:Lf_ShowHidden = 1

noremap <A-n> :Leaderf file --no-ignore <CR>
noremap <A-m> :Leaderf rg --no-ignore <CR>
"<C-P> 预览当前文件
"Ctrl H L 滚动预览窗口
let g:Lf_CommandMap = {'<C-Up>': ['<C-L>'], '<C-Down>': ['<C-H>']}

"-------------------------------------------------------------------------------
" 字体 行号 主题
"-------------------------------------------------------------------------------
" 不与 Vi 兼容(采用 Vim 自己的操作命令)
set nocompatible

set number

let g:auto_save = 1

colorscheme monokai

" 字体
 if has('gui_running')
    if has("win16") || has("win32") || has("win95") || has("win64")
        set guifont=Sarasa_Mono_SC:h14
    else
        set guifont=Sarasa\ Mono\ SC\ 14
    endif
endif

" 在状态栏显示正在输入的命令
set showcmd

set mouse=a

" 启用256色
set t_Co=256

" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set autoindent

" 由于 Tab 键在不同的编辑器缩进不一致,该设置自动将 Tab 转为空格。
set expandtab
" tab相关变更
" 设置Tab键的宽度,等同的空格个数
set tabstop=4
" 每一次缩进对应的空格数
set shiftwidth=4
" 按退格键时可以一次删掉 4 个空格
set softtabstop=4

" 关闭自动折行
set nowrap

" 禁止自动在文件末尾添加空行
set nofixendofline

" 在状态栏显示光标的当前位置(位于哪一行哪一列)。
set  ruler
" 突出显示当前列
"set cursorcolumn
" 突出显示当前行
set cursorline

" 光标遇到圆括号、方括号、大括号时,自动高亮对应的另一个圆括号、方括号和大括号。
set showmatch

set history=1000

" 打开文件监视。如果在编辑过程中文件发生外部改变(比如被别的编辑器编辑了),就会发出提示。
set autoread

" undo redo
" u    <C-R>

"Square up visual selections...
set virtualedit=block

" Make BS/DEL work as expected in visual modes (i.e. delete the selected text)...
xmap <BS> x

" Prefer vertical orientation when using :diffsplit
set diffopt+=vertical

"可随时用倒退键删除
set backspace=2


"行号
map <leader>n  :set invnumber <CR>
"行折叠
map <leader>w  :set invwrap <CR>

"窗口分隔
map <leader>=  :vsp <CR>
map <leader>-  :sp <CR>

"窗口跳转
"<C-W> jkhl

"tab 跳转
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>

"关闭当前window
nnoremap <C-q> <ESC>:q <CR>
inoremap <C-q> <ESC>:q <CR>


"新tab中打开本文件
inoremap <C-T> <ESC>:tabnew %<CR> i
nnoremap <C-T> <ESC>:tabnew %<CR>

" 创建新tab
inoremap <C-N> <C-O>:tabnew <CR>
nnoremap <C-N> :tabnew <CR> i



"z Enter or  zt      puts current line to top of screen
"z.      or  zz      puts current line to center of screen
"z-      or  zb      puts current line to bottom of screen
"z Enter, z., and z- puts the cursor in the first non blank column.
"zt, zz, and zb leaves the cursor in the current column
"More info about scrolling at http://vimdoc.sourceforge.net/htmldoc/scroll.html or
"in vim type :help scroll-cursor


" ================ Turn Off Swap Files ==============

set noswapfile
set nobackup
set nowb

" ================ Persistent Undo ==================

" Set up persistent undo across all files.
set undofile
if !isdirectory(expand("~/.vim/undodir"))
  call mkdir(expand("~/.vim/undodir"), "p")
endif
set undodir=~/.vim/undodir

"-------------------------------------------------------------------------------
" NERDTree
"-------------------------------------------------------------------------------

"m 打开memu 增删文件

"toggle panel
map <leader>e :NERDTreeToggle<CR>

let NERDTreeAutoCenter=1

let NERDTreeShowLineNumbers=1

let NERDTreeShowHidden=1

let NERDTreeWinSize=35

" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1

let g:NERDTreeGitStatusIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

"-------------------------------------------------------------------------------
" 搜索
"-------------------------------------------------------------------------------
" 搜索时,高亮显示匹配结果。
set hlsearch
"highlight clear Search

"清除高亮
map <leader>c :nohl <CR>

" 搜索设置
set ignorecase
set incsearch

"-------------------------------------------------------------------------------
"  tag
"-------------------------------------------------------------------------------
set tags=./.tags;,.tags

" gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']

" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'

" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags

" 配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
   silent! call mkdir(s:vim_tags, 'p')
endif

"少用 CTRL-] 直接在当前窗口里跳转到定义
"多使用 CTRL-W ] 用新窗口打开并查看光标下符号的定义
"或者 CTRL-W } 使用 preview 窗口预览光标下符号的定义


"-------------------------------------------------------------------------------
"  静态检查lint
"-------------------------------------------------------------------------------
let g:ale_linters_explicit = 1
let g:ale_completion_delay = 500
let g:ale_echo_delay = 20
let g:ale_lint_delay = 500
let g:ale_echo_msg_format = '[%linter%] %code: %%s'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:airline#extensions#ale#enabled = 1

let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
let g:ale_c_cppcheck_options = ''
let g:ale_cpp_cppcheck_options = ''


"-------------------------------------------------------------------------------
"  auto complete
"-------------------------------------------------------------------------------

" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

let g:coc_global_extensions = ['coc-json', 'coc-git', "coc-cmake", "coc-emmet", "coc-highlight", "coc-lists", "coc-pairs", "coc-snippets", "coc-yank"]

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')


" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
" xmap <leader>f  <Plug>(coc-format-selected)
" nmap <leader>f  <Plug>(coc-format-selected)


posted @ 2023-03-09 14:43  fndefbwefsowpvqfx  阅读(38)  评论(0编辑  收藏  举报