文件:.vimrc

VIM 快捷键速记

  1. 行内快速定位:f字母

  2. 查找:/查找内容

  3. 替换:[addr]s/源字符串/目的字符串/[option]

    [addr]表示检索范围,如:
    
    "1,n":表示从第1行到n行
    "%":表示整个文件,同"1,$"
    ".,$":表示从当前行到文件尾
    
    [addr]省略时表示当前行
    [option] : 表示操作类型,如:
    
    g:globe,表示全局替换
    
    c:confirm,表示进行确认
    
    p:表示替代结果逐行显示(Ctrl + L恢复屏幕)
    
    i:ignore,不区分大小写
    
"文件:.config/nvim/init.vim
"--------v20211021-----------
"---注意首次运行如果出错
"---在nvim命令行:
"PlugInstall
":UpdateRemotePlugins
"----------------------------
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'

" 主题
"Plug 'morhetz/gruvbox'

"好看的状态栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
let g:airline#extensions#hunks#enabled = 0
" 语法检查
Plug 'neomake/neomake'

" 括号匹配
Plug 'jiangmiao/auto-pairs'
" 自动补全
Plug 'neoclide/coc.nvim', {'branch': 'release'}

" 主要为vimspector提供调试模板文件列表(.vim/vimspector_json/):cpp.json python.json shell.json 
" File navigation
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
"文件.bashrc中尾添加 [ -f ~/.fzf.bash ] && source ~/.fzf.bash

"F10键 终端 编辑/首选项/常规/(取消)启用菜单快捷键 
"F11键 终端 快捷键/(取消)启用快捷键
Plug 'puremourning/vimspector',{'do':'./install_gadget.py --force-enable-rust -enable-python --enable-go --enable-bash --enable-c'}


call plug#end()

"vim 与 系统共享粘贴板
set clipboard=unnamedplus

let g:airline#extensions#hunks#enabled = 0

" 主题
"colorscheme gruvbox
"set background=dark " 或者 set background=light
" 语法检查 忽视警告
let g:neomake_python_enabled_makers = ['pyflakes']
call neomake#configure#automake('nrwi', 500)	" 自动检查
" 代码补充的键位替换
"inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"

map <F2> :!rustc % -g -o %< <CR>
map ,q :call CompileRunGcc()<CR>
" 一键执行
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec '!g++ % -g -o %<'
        exec '!time ./%<'
    elseif &filetype == 'cpp'
	
        exec '!g++ % -g -o %<'
        exec '!time ./%<'
    elseif &filetype == 'python'
        exec '!python %'
    elseif &filetype == 'sh'
        :!time bash %
		endif
endfunc<Paste>

func! AddWatch()
	let wordUnderCursor = expand("<cword>")
	"exec 'echo "add:"wordUnderCursor'
	call vimspector#AddWatch(wordUnderCursor)
endfunc<Paste>
map ,a :call AddWatch()<CR>
func! AddWatch2()
	let var1=input('Enter watch expression:','')

	call vimspector#AddWatch(var1)
endfunc<Paste>
map ,w :call AddWatch2()<CR>
map ,m :call Make()<CR>
func! Make()
	if filereadable("build/Makefile")
		exec "w"
		exec '!cd %:p:h/build && make'		
	elseif filereadable("Makefile")
		exec "w"
		exec '!cd %:p:h && make'
	endif
endfunc<Paste>

" 键位的映射
map ,n :call ShowNumberToggle()<CR>
func! ShowNumberToggle()
	if &nu
		set nonu
		set mouse=v
	else
		set nu
		set mouse=a
	endif
endfunc<Paste>
noremap <F12> :NERDTreeToggle<CR>
noremap <C-x> :q<CR>
noremap <C-s> :w<CR>
inoremap <C-x> <Esc>:q<CR>

noremap <M-x> :q!<CR>
inoremap <M-x> <Esc>:q!<CR>

inoremap <C-s> <Esc>:w<CR>
noremap ,l :sp<CR><C-w>j:term ipython<CR> i %run 
noremap ,s :sp<CR><C-w>j:term <CR>i

noremap ,r :source ~/.config/nvim/init.vim<CR>
inoremap ,r <Esc>:source ~/.config/nvim/init.vim<CR>a

noremap ,, <Esc>
inoremap ,, <Esc><Right>
noremap ,h ^
inoremap ,h <Esc>^i
noremap ,l $
inoremap ,l <Esc>$a

"map <Up> <Nop>
"map <Down> <Nop>
"map <Left> <Nop>
"map <Right> <Nop>

"inoremap <Up> <Nop>
"inoremap <Down> <Nop>
"inoremap <Left> <Nop>
"inoremap <Right> <Nop>


set guifont=Courier/20
set foldenable      " 允许折叠  
set showcmd         " 输入的命令显示出来,看的清楚些 
set shortmess=atI   " 启动的时候不显示那个援助乌干达儿童的提示 
" 语法高亮
set syntax=on
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=2
set shiftwidth=2
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限  
set nocompatible  
"设置编码
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
" 括号匹配
set showmatch
" 鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 显示行号
set number
" 高亮当前行
set cursorline
highlight CursorLine   cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
" 设置空白字符的视觉提示
"set list listchars=extends:,precedes:,tab:▸\ ,trail:˽
"autocmd vimenter * NERDTree "启动时打开插件
"退出编辑窗口就直接关闭目录树窗口
autocmd BufEnter * if 0 == len(filter(range(1, winnr('$')), 'empty(getbufvar(winbufnr(v:val), "&bt"))')) | qa! | endif

" ===
" === vimspector
" ===
let g:vimspector_enable_mappings = 'HUMAN'
function! s:read_template_into_buffer(template)
    " has to be a function to avoid the extra space fzf#run insers otherwise
    execute '0r ~/.vim/vimspector_json/'.a:template
endfunction
command! -bang -nargs=* LoadVimSpectorJsonTemplate call fzf#run({
            \   'source': 'ls -1 ~/.vim/vimspector_json',
            \   'down': 20,
            \   'sink': function('<sid>read_template_into_buffer')
            \ })
" %:p:h返回当前调试源文件所在的目录
" 如果没有%:p:h时.vimspector.json会被默认存到vim/nvim启动目录
" ~$nvim test/main.cpp  没有%:p:h时则返回~/.vimspector.json 如果有 %:p:h/.vimspector.json返回~/test/.vimspector.json
"按\vs键选择模板
noremap <leader>vs :tabe %:p:h/.vimspector.json<CR>:LoadVimSpectorJsonTemplate<CR>
sign define vimspectorBP text=🛑 texthl=Normal
sign define vimspectorBPDisabled text=🚫 texthl=Normal
sign define vimspectorPC text=👉 texthl=SpellBad

" ===
" === coc.vim
" ===
" 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值