首页 > 其他分享 >vim配置

vim配置

时间:2023-07-30 23:22:07浏览次数:26  
标签:set co c# 配置 nnoremap vim coc let

.vimrc

"通用配置"

set title
let mapleader=";"           "快捷键前置
set nocompatible            "不兼容原始vi模式"
filetype on                 "开启文件类型检测
filetype plugin on          "开启文件类型插件检测
set noeb                    "关闭错误提示"
syntax enable               "开启语法高亮
syntax on                   
set t_Co=256                "开启256色
set cmdheight=1             "底行状态栏高度2
set backspace=2
set showcmd                 "底行显示操作命令"
set showmatch               "显示对应的圆、方、大括号"
" set visualbell              "出错,屏幕闪烁"

"set nonu
set nu                      "开启行号显示
set ts=4                    "tab更换4个空格
set shiftwidth=4            "换行自动补全空格
set noshowmode              
set laststatus=2            "显示状态栏"
set ruler                   "总是显示光标位置"
"set cursorline             "高亮显示当前行"
set virtualedit=block,onemore   " 允许光标出现在最后一个字符的后面"
set ttimeoutlen=0               "设置<ESC>响应时间"
" set mouse=a

set sidescroll=10

"代码缩进和排版"

set cindent                  "C语言格式化
set autoindent               "自动格式化


set bg=dark                  "暗色背景, dark/light
colorscheme gruvbox


"搜索设置""
set ignorecase
set hlsearch
set incsearch

"缓存设置"
set nobackup
set noswapfile
set autoread
set autowrite

"<Leader> 快捷键配置"
nmap <Leader>w :w<CR>

nmap <Tab> :bn<CR>

inoremap jj <ESC>
" nnoremap  <C-l> :%!clang-format<CR>
"

function! ClangFormat()
	let save_cursor = getpos('.')
	execute '%!clang-format'
	call setpos('.',save_cursor)
endfunction
nnoremap  <C-l> :call ClangFormat()<CR>


" 设置捷键 F5 用执行C++代码
nnoremap <F5> :w<CR>:!g++ % -o %< && ./%<<CR>


"插件管理"
call plug#begin('~/.vim/plugged')


" 通用插件
" 括号自动补全
Plug 'jiangmiao/auto-pairs' 
" coc.nvim 自动补全等功能
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" 底行状态栏
Plug 'itchyny/lightline.vim'
" 格式化
Plug 'rhysd/vim-clang-format'
" 注释插件
Plug 'preservim/nerdcommenter'
"模板插件
Plug 'aperezdc/vim-template'
" 目录树
Plug 'preservim/nerdtree'
" C++ highlight
Plug 'octol/vim-cpp-enhanced-highlight'
" vim-wintabs
Plug 'zefei/vim-wintabs'
Plug 'zefei/vim-wintabs-powerline'
call plug#end()




"coc.nvim default config

" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count
" utf-8 byte sequence
set encoding=utf-8
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup

" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes



" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" 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>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

function! CheckBackspace() 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

" 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 ShowDocumentation()<CR>

function! ShowDocumentation()
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    call feedkeys('K', 'in')
  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 code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying code actions at the cursor position
nmap <leader>ac  <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>as  <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf  <Plug>(coc-fix-current)

" Remap keys for applying refactor code actions
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)

" Run the Code Lens action on the current line
nmap <leader>cl  <Plug>(coc-codelens-action)

" 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> to 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 CocActionAsync('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     CocActionAsync('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></CR>


" nnoremap <F4> :CocCommand document.toggleInlayHint<CR>
set pumheight=10


" nerdcommenter default config
" Create default mappings
let g:NERDCreateDefaultMappings = 1

" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1

" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1

" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'

" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1

" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '//'}, 'cpp': { 'left': '//' } }

" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1

" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1

" Enable NERDCommenterToggle to check all selected lines is commented or not 
let g:NERDToggleCheckAllLines = 1

" 代码模板
let g:username = "zxinlog"
let g:email = "[email protected]"


"nnoremap <leader>n :NERDTreeFocus<CR>
"nnoremap <C-n> :NERDTree<CR>
"nnoremap <C-t> :NERDTreeToggle<CR>
"nnoremap <C-f> :NERDTreeFind<CR>
nnoremap <leader>n :NERDTreeToggle<CR>
nnoremap <leader>m :NERDTree<CR>

" C++ lightline
let g:cpp_class_scope_highlight = 1
"let g:cpp_member_variable_highlight = 1
"let g:cpp_class_decl_highlight = 1
"let g:cpp_posix_standard = 1
"let g:cpp_experimental_simple_template_highlight = 1
"let g:cpp_no_function_highlight = 1
"let g:cpp_concepts_highlight = 1

.clang-format

Language: Cpp
#基于那个配置文件
BasedOnStyle: Google
#指针的*的挨着哪边
PointerAlignment: Right
DerivePointerAlignment: false
#缩进宽度
IndentWidth: 4
# 连续的空行保留几行
MaxEmptyLinesToKeep: 1
# 在 @property 后面添加空格, \@property (readonly) 而不是 \@property(readonly).
#ObjCSpaceAfterProperty: true
# OC block后面的缩进
ObjCBlockIndentWidth: 4
# 是否允许短方法单行
AllowShortFunctionsOnASingleLine: false
# 是否允许短if单行 If true, if (a) return; 可以放到同一行
AllowShortIfStatementsOnASingleLine: false
#注释对齐
AlignTrailingComments: true
# 换行的时候对齐操作符
AlignOperands: false
# 中括号两边空格 [] 
SpacesInSquareBrackets: false
# 小括号两边添加空格
SpacesInParentheses : false
#多行声明语句按照=对齐
AlignConsecutiveDeclarations: false
#连续的赋值语句以 = 为中心对齐
AlignConsecutiveAssignments: false
#等号两边的空格
SpaceBeforeAssignmentOperators: true
# 容器类的空格 例如 OC的字典
SpacesInContainerLiterals: true
#缩进
IndentWrappedFunctionNames: true
#在block从空行开始
KeepEmptyLinesAtTheStartOfBlocks: true
#在构造函数初始化时按逗号断行,并以冒号对齐
BreakConstructorInitializersBeforeComma: true
#函数参数换行
AllowAllParametersOfDeclarationOnNextLine: false
#括号后添加空格
SpaceAfterCStyleCast: true
#tab键盘的宽度
TabWidth: 4
UseTab: Never
ColumnLimit: 120
#访问修饰符的偏移量
AccessModifierOffset: -4
#成员初始化放在单独的一行
ConstructorInitializerAllOnOneLineOrOnePerLine: false
#extern C 块缩进
#IndentExternBlock: true

标签:set,co,c#,配置,nnoremap,vim,coc,let
From: https://www.cnblogs.com/zxinlog/p/17592353.html

相关文章

  • Gvim
                     文件加密 解除密码 set/Enter key :   空密码                  大小写替换   多窗口操作   ......
  • Linux环境Arduino IDE中配置ATOM S3
    linux选择ubuntu发行版。硬件设备有多小呢:功能超级强大。之前的ROS1和ROS2案例已经全部移植完成并测试结束(三轮纯人力校验......
  • go项目实现在配置文件实现配置项统一管理
    转载请注明出处:go项目中实现配置项统一管理,实现逻辑:将配置项整理为一个json的数据结构,并保存到go.conf文件中,然后在go项目启动main方法中加载go.conf文件,读取go.conf文件的json数据结构,并进行反序列化为go的数据结构,从而在go项目中可以全局使用go.conf文件中的配置项......
  • vscode+gdb 配置
    到这个网址下载mingwc语言环境https://sourceforge.net/projects/mingw-w64/files/mingw-w64/我是windows64位,直接下载这个: 配置好环境变量下载c/c++插件配置vscode文件: launch.json文件:{//使用IntelliSense了解相关属性。//悬停以查看现有属性......
  • mac安装maven环境并配置
    参考:https://www.bilibili.com/video/BV1mW4y1q72A/?spm_id_from=333.337.search-card.all.click&vd_source=56102d8741b60f8a5fd28fed8a3d6e46https://blog.csdn.net/hzqit520/article/details/129166916......
  • c#传统读取配置文件
    usingMicrosoft.Extensions.Configuration;usingMicrosoft.Extensions.Configuration.Json;namespaceConsoleApp1{internalclassProgram{staticvoidMain(string[]args){//配置系统//jsonxmlini都是支持......
  • [linux]VIM实用技巧
    一、文本对象1.文本对象文本对象:基于结构定义的文本区域文本对象字符由两个字符组成,第一个字符永远是a/ii开头的文本对象会选择分隔符内部的文本a开头的文本对象会选择分隔符在内的整个文本即:i不包含边界,a包含边界注:1.文本对象可结合可视模式使用(v—可视字符)2.文本对象可结......
  • Mask_RCNN项目下载、配置、运行保姆级教程
    1.下载项目进入国内github镜像https://hub.nuaa.cf/搜索要找的模型下载完成后,放到自己写代码的文件夹内,解压。右键用pycharm打开打开requirements.txt,里面有需要安装的包.(可以在网上查MaskRCNN或你想查的项目的环境配置,网上有的说的很详细,这个requirement说的不太详细,如果版本不......
  • 6.Pod的资源配置模板
    资源范式:五个一级字段kind:<String>指明对象的类型(资源类型),类型标签apiVersion:<String>指明对象的类型(资源类型),类型隶属的API群组metadata:<Object>对象元数据,名称/标签/注解和隶属的名称空间spec:<Object>对象数据,期望状态status:<Object>资源的实际状态,由系......
  • GVIM 使用技巧
    本文参考《GVIM教程基于明德扬课程》哔哩哔哩_bilibili1.GVIM三种模式GVIM有三个操作模式,分别是命令模式、编辑模式和列操作模式。默认GVIM是命令模式。在命令模式下,输入i进入编辑模式。在任何模式下,按Esc进入命令模式。在命令模式下,按ctrl+q进入列操作模式。......