- gvim安装包
官网下载 - 插件管理器vim-plug
github,只需要把plug.vim拷贝到安装目录下autoload里面就行了 但是因为国内访问时断时续,所以plug.vim要做点修改,换到一个镜像站,这样下载会快很多 环境配置完成后执行一条命令即可自动安装
:PlugInstall
- clangd 语法检测和跳转服务
下载链接,上不去换时间换地点多试几次。。,下载解压,bin目录添加环境变量 因为单片机等嵌入式设备不是标准c,有些特殊关键字的错误导致clangd跳不过去的函数基本可以用ctags跳过去,特殊变量暂时不清楚,下载后只需要把ctags.exe 复制到gvim.exe同级目录下即可,配置文件自定义键盘映射:
"生成tags
map <F2> :!ctags -R * <CR>
ctags下载
- node.js,coc插件依赖
官网下载,coc只提供补全,语法检测和跳转依赖coc语言服务器也就是coc插件,使用插件安装后使用coc命令安装,比如:
:CocInstall coc-clangd //C语言
:CocInstall coc-lua //lua
:CocList extensions //查看已安装扩展
- 上面图片使用的字体文件、比较喜欢的两个配色文件、修改过源的vim-plug插件、我的配置文件,打包放在了下面的链接,当然,所有资源只要百度都搜索的到
csdn下载链接
完
下面贴上配置方便参考查询,对neovim和vim大部分也可以用
"切换到工作目录
cd D:\WorkSpace
"最大化打开
autocmd GUIEnter * simalt ~x
" autocmd VimEnter * NERDTree "自动打开文件树
"首先设置编码,否则中文乱码
"vim内部编码,寄存器那些使用
set encoding=utf-8
"编码自动识别列表,首先用第一项解码,逐次向后
set fileencodings=utf-8,gb2312
"设置退格键功能
set backspace=indent,eol,start
"设置颜色主题,该主题不在默认安装,需要下载
colorscheme onedark
"设置字体,该字体需要下载安装
set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
"自动重载配置文件,只对一部分配置有效,插件配置和环境变量修改需要重新启动vim
autocmd BufWritePost $MYVIMRC source $MYVIMRC
"语法高亮,需要重启
syntax on
"显示行号
set number
"设置tab键宽度为4
set tabstop=4
"设置自动缩进长度为4
set shiftwidth=4
"按c语言格式缩进
set cindent
"继承前一行的缩进方式
set autoindent
"解决粘贴缩进异常
"set paste
"显示不可见字符
set list
set listchars=tab:>-,trail:-
"输入搜索内容时高亮
set incsearch
"搜索结果高亮
set hlsearch
"不需要兼容Vi
set nocompatible
"突出显示光标行列位置
set cursorline
set cursorcolumn
"开启底边栏状态条,使用插件不开启
"set ruler
"状态栏行数
"set laststatus=2
"响应鼠标点击,gvim安装时可以配置,不需要
"set mouse=a
"set selection=exclusive
"selectmode=mouse,key
"光标距离顶行底行5滚动
set scrolloff=5
"***********************************************************************************
"*******************************插件配置区******************************************
"***********************************************************************************
call plug#begin('D:\Program Files (x86)\Vim\vim82\autoload')
"文件浏览器
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"tags生成和边栏
Plug 'preservim/tagbar', { 'on': 'TagbarToggle' }
"底栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"括号自动关闭
Plug 'Townk/vim-autoclose'
"自动函数注释
Plug 'babaybus/DoxygenToolkit.vim'
"补全和语法检测支持
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"彩色括号
Plug 'luochen1990/rainbow'
"快速注释
Plug 'preservim/nerdcommenter'
call plug#end()
"---------------------------------------------------------------------------------------------------
"快速注释默认配置
let g:NERDCreateDefaultMappings = 1
"---------------------------------------------------------------------------------------------------
"彩色括号配置
let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
"---------------------------------------------------------------------------------------------------
"函数自动注释配置
let g:DoxygenToolkit_briefTag_pre="@Synopsis "
let g:DoxygenToolkit_paramTag_pre="@Param "
let g:DoxygenToolkit_returnTag="@Returns "
let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
let g:DoxygenToolkit_blockFooter="--------------------------------------------------------------------------"
let g:DoxygenToolkit_authorName="Wang Jiancong"
let g:DoxygenToolkit_licenseTag="My own license"
"---------------------------------------------------------------------------------------------------
"底行配置
let g:airline#extensions#tabline#enable = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#formatter = 'default'
"---------------------------------------------------------------------------------------------------
"文件树配置
let NERDTreeShowBookmarks=1
"---------------------------------------------------------------------------------------------------
"ctags 配置
set tags=tags;
set autochdir
"---------------------------------------------------------------------------------------------------
"coc相关配置,来自示例配置未修改。。。。。。。。
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" 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
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" 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 K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" 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)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
"
"" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
"" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
"***********************************************************************************
"*************************自定义快捷键配置*************************************
"***********************************************************************************
"生成tags
map <F2> :!ctags -R * <CR>
"打开/关闭文件树
map <F3> :NERDTreeToggle<CR>
"打开/关闭tagbar
map <F4> :TagbarToggle<CR>
"窗口切换
nnoremap <leader>s <C-W>h<CR>
nnoremap <leader>d <C-W>l<CR>
nnoremap <leader>j <C-W>x<CR>
"窗口大小调整
nnoremap <leader>w :vertical resize -10<CR>
nnoremap <leader>e :vertical resize +10<CR>
"保存工作区
" Automatically save the current session whenever vim is closed
"autocmd VimLeave * mksession! ~/.vim/shutdown_session.vim
" <F5> restores that 'shutdown session'
"noremap <F5> :source ~/.vim/shutdown_session.vim<CR>
" If you really want to, this next line should restore the shutdown session
" automatically, whenever you start vim. (Commented out for now, in case
" somebody just copy/pastes this whole block)
"
" autocmd VimEnter source ~/.vim/shutdown_session.vim<CR>
" manually save a session with <F5>
noremap <F5> :mksession! ~/.vim/manual_session.vim<cr>
" recall the manually saved session with <F6>
noremap <F6> :source ~/.vim/manual_session.vim<cr>
"***********************************************************************************
"******************************自定义功能区*****************************************
"***********************************************************************************
"-----------------------------keil------------------------------
function MakeKeilTarget(options)
let l:target = ''
let l:target51 = ''
wa
echo '当前目录:'expand('<sfile>:p')
"-------------------------MDK-------------------------
if !empty(glob('*.uvprojx'))
let l:target = glob('*.uvprojx')
elseif !empty(glob('../*.uvprojx'))
let l:target = glob('../*.uvprojx')
elseif !empty(glob('../../*.uvprojx'))
let l:target = glob('../../*.uvprojx')
elseif !empty(glob('../MDK-ARM/*.uvprojx')) "stm32-Cube
let l:target = glob('../MDK-ARM/*.uvprojx')
elseif !empty(glob('../../MDK-ARM/*.uvprojx')) "stm32-Cube
let l:target = glob('../../MDK-ARM/*.uvprojx')
endif
"-------------------------8051-------------------------
if !empty(glob('*.uvproj'))
let l:target51 = glob('*.uvproj')
elseif !empty(glob('../*.uvproj'))
let l:target51 = glob('../*.uvproj')
elseif !empty(glob('../../*.uvproj'))
let l:target51 = glob('../../*.uvproj')
endif
if !empty(l:target)
execute ':silent !uv4 '.a:options.l:target.' -j0 -o "\%TEMP\%/mdk_log.txt"'
"execute ':!uv4 '.a:options.l:target.' -o "\%TEMP\%/mdk_log.txt" && type "\%TEMP\%\mdk_log.txt" && pause'
execute ':silent !type "\%TEMP\%\mdk_log.txt" && pause'
elseif !empty(l:target51)
execute ':silent !uv4 '.a:options.l:target51.' -j0 -o "\%TEMP\%/mdk_log.txt"'
"execute ':!uv4 '.a:options.l:target51.' -o "\%TEMP\%/mdk_log.txt" && type "\%TEMP\%\mdk_log.txt" && pause'
execute ':silent !type "\%TEMP\%\mdk_log.txt" && pause'
else
echo 'Target not found!'
endif
endfunction
"编译快捷键,需要把keil可执行文件Uv4.exe添加到环境变量,需要把源文件先在keil里添加好
nnoremap <leader>kb :call MakeKeilTarget('-b ')<CR>
"nnoremap <leader>kr :call MakeKeilTarget('-b -z ')<CR>
nnoremap <leader>kr :call MakeKeilTarget('-cr ')<CR>
nnoremap <leader>kd :call MakeKeilTarget('-f ')<CR>
个人vim专栏里面还有两篇文章,有兴趣的同学可以看看^_^
|