15 条回复  ·  383 次点击
qwq11 小成 2023-3-15 05:51:49
有空格就放空格上面 r<CR>
没空格就只能老老实实 i<CR><ESC>
hxy100 初学 2023-3-15 08:04:46
尝试在  ~/.vimrc 中加入以下代码,实现单、双引号自动补齐,小括号、大括号、中括号自动补全
------

" 括号自动补全
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {<CR>}<Esc>O
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>


function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf


function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf


function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<Esc>i"
endif
endf
andy2415 该用户已被删除 2023-3-15 09:32:07
提示: 作者被禁止或删除 内容自动屏蔽
jiekeop 小成 2023-3-15 11:02:12
@hxy100 是不是贴错了一些,我放进去输入一个" 提示报错
=QuoteDelim('"')
Error detected while processing function QuoteDelim:
line    3:
E114: Missing quote: "\"
Press ENTER or type command to continue
zhuisui 小成 2023-3-15 11:41:28
我的快捷键 `nnoremap <Leader>o o<ESC>`
不论是在哪个字符位置, 直接下面起一行
timothyye 小成 2023-3-15 21:00:39
大写 O 就行
12
返回顶部