只通过在vimrc文件写东西来实现或安装vim的插件
2023年9月23日,周日上午
有时候觉得用插件管理器来安装插件太麻烦了,
所以我就在想能不能只通过在vimrc文件写东西来实现或安装vim的插件,
不过这样做肯定有很大的局限性,但我会尽量做到最好的效果
不定期更新
把下面这些代码直接复制到vimrc文件即可!!!
括号补全
" 括号自动补全
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>" 自动补全引号
inoremap " ""<left>
inoremap ' ''<left>
轻量化自动补全
这段代码来自GitHub:GitHub - skywind3000/vim-auto-popmenu: Display the Completion Menu Automantically (next AutoComplPop) !!
" enable this plugin for filetypes, '*' for all files.
let g:apc_enable_ft = {'text':1, 'markdown':1, 'php':1, 'c':1, 'cpp':1, 'h':1, 'java':1}" source for dictionary, current or other loaded buffers, see ':help cpt'
set cpt=.,k,w,b" don't select the first item.
set completeopt=menu,menuone,noselect" suppress annoy messages.
set shortmess+=c" vim: set noet fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :
"
" apc.vim - auto popup completion window
"
" Created by skywind on 2020/03/05
" Last Modified: 2022/12/05 21:22
"
" Features:
"
" - auto popup complete window without select the first one
" - tab/s-tab to cycle suggestions, <c-e> to cancel
" - use ApcEnable/ApcDisable to toggle for certiain file.
"
" Usage:
"
" set cpt=.,k,b
" set completeopt=menu,menuone,noselect
" let g:apc_enable_ft = {'text':1, 'markdown':1, 'php':1}let g:apc_enable_ft = get(g:, 'apc_enable_ft', {}) " enable filetypes
let g:apc_enable_tab = get(g:, 'apc_enable_tab', 1) " remap tab
let g:apc_min_length = get(g:, 'apc_min_length', 2) " minimal length to open popup
let g:apc_key_ignore = get(g:, 'apc_key_ignore', []) " ignore keywords
let g:apc_trigger = get(g:, 'apc_trigger', "\<c-n>") " which key to trigger popmenu" get word before cursor
function! s:get_context()return strpart(getline('.'), 0, col('.') - 1)
endfuncfunction! s:meets_keyword(context)if g:apc_min_length <= 0return 0endiflet matches = matchlist(a:context, '\(\k\{' . g:apc_min_length . ',}\)$')if empty(matches)return 0endiffor ignore in g:apc_key_ignoreif stridx(ignore, matches[1]) == 0return 0endifendforreturn 1
endfuncfunction! s:check_back_space() abortreturn col('.') < 2 || getline('.')[col('.') - 2] =~# '\s'
endfuncfunction! s:on_backspace()if pumvisible() == 0return "\<BS>"endiflet text = matchstr(s:get_context(), '.*\ze.')return s:meets_keyword(text)? "\<BS>" : "\<c-e>\<bs>"
endfunc" autocmd for CursorMovedI
function! s:feed_popup()let enable = get(b:, 'apc_enable', 0)let lastx = get(b:, 'apc_lastx', -1)let lasty = get(b:, 'apc_lasty', -1)let tick = get(b:, 'apc_tick', -1)if &bt != '' || enable == 0 || &pastereturn -1endiflet x = col('.') - 1let y = line('.') - 1if pumvisible()let context = s:get_context()if s:meets_keyword(context) == 0call feedkeys("\<c-e>", 'n')endiflet b:apc_lastx = xlet b:apc_lasty = ylet b:apc_tick = b:changedtickreturn 0elseif lastx == x && lasty == yreturn -2elseif b:changedtick == ticklet lastx = xlet lasty = yreturn -3endiflet context = s:get_context()if s:meets_keyword(context)silent! call feedkeys(get(b:, 'apc_trigger', g:apc_trigger), 'n')let b:apc_lastx = xlet b:apc_lasty = ylet b:apc_tick = b:changedtickendifreturn 0
endfunc" autocmd for CompleteDone
function! s:complete_done()let b:apc_lastx = col('.') - 1let b:apc_lasty = line('.') - 1let b:apc_tick = b:changedtick
endfunc" enable apc
function! s:apc_enable()call s:apc_disable()augroup ApcEventGroupau!au CursorMovedI <buffer> nested call s:feed_popup()au CompleteDone <buffer> call s:complete_done()augroup ENDlet b:apc_init_autocmd = 1if g:apc_enable_tabinoremap <silent><buffer><expr> <tab>\ pumvisible()? "\<c-n>" :\ <SID>check_back_space() ? "\<tab>" : \ get(b:, 'apc_trigger', g:apc_trigger)inoremap <silent><buffer><expr> <s-tab>\ pumvisible()? "\<c-p>" : "\<s-tab>"let b:apc_init_tab = 1endifif get(g:, 'apc_cr_confirm', 0) == 0inoremap <silent><buffer><expr> <cr> \ pumvisible()? "\<c-y>\<cr>" : "\<cr>"elseinoremap <silent><buffer><expr> <cr> \ pumvisible()? "\<c-y>" : "\<cr>"endifinoremap <silent><buffer><expr> <bs> <SID>on_backspace()let b:apc_init_bs = 1let b:apc_init_cr = 1let b:apc_save_infer = &infercasesetlocal infercaselet b:apc_enable = 1
endfunc" disable apc
function! s:apc_disable()if get(b:, 'apc_init_autocmd', 0)augroup ApcEventGroupau! augroup ENDendifif get(b:, 'apc_init_tab', 0)silent! iunmap <buffer><expr> <tab>silent! iunmap <buffer><expr> <s-tab>endifif get(b:, 'apc_init_bs', 0)silent! iunmap <buffer><expr> <bs>endifif get(b:, 'apc_init_cr', 0)silent! iunmap <buffer><expr> <cr>endifif get(b:, 'apc_save_infer', '') != ''let &l:infercase = b:apc_save_inferendiflet b:apc_init_autocmd = 0let b:apc_init_tab = 0let b:apc_init_bs = 0let b:apc_init_cr = 0let b:apc_save_infer = ''let b:apc_enable = 0
endfunc" check if need to be enabled
function! s:apc_check_init()if &bt != '' || get(b:, 'apc_enable', 1) == 0returnendifif get(g:apc_enable_ft, &ft, 0) != 0ApcEnableelseif get(g:apc_enable_ft, '*', 0) != 0ApcEnableelseif get(b:, 'apc_enable', 0)ApcEnableendif
endfunc" commands & autocmd
command! -nargs=0 ApcEnable call s:apc_enable()
command! -nargs=0 ApcDisable call s:apc_disable()augroup ApcInitGroupau!au FileType * call s:apc_check_init()au BufEnter * call s:apc_check_init()au TabEnter * call s:apc_check_init()
augroup END