aeghn
1
我喜欢 emacs 有很大一部分原因是 emacs 有很多行为是正好击中我的甜点。
比如 默认的缩进当前行行为可以说是我最喜欢的点之一。最近也想把 vim 多少收拾收拾,多少靠近一点 emacs,所以想问一下这点如何在 vim 中实现。
我知道 ==
可以缩进当前行,所以我在插入模式下做了如下映射:
imap <tab> <esc>==i
大体上也能满足我的需求,但是 ==
这个缩进会自动回行首,让我有些烦恼,也就是说
下面一个 c 例子,插入模式
int main() {
printf("He<光标>llo, world.\n");
return 0;
}
那么执行完 ==
后,会变成
int main() {
<光标>printf("Hello, world.\n");
return 0;
}
但是我想要的是
int main() {
printf("He<光标>llo, world.\n");
return 0;
}
请问有办法做到吗?
Gneal
2
Neovim没有发现光标回行首
试了一下vim确实调缩进会回行首,不管是==还是<< >>
Vim 有 insert 模式下的绑定,自带的。
<C-t>
缩进。
<C-d>
反缩进。
另外记得设置 smartindent 一下,autoindent 还是别开了。
aeghn
4
自己糊了一个函数,能满足自己的需求了
function IndentLine()
let ofpos = match(getline(line(".")),'\S')
if ofpos == -1
call setline(line("."), "a")
execute "normal! ==D"
return
endif
let diff = col(".") - ofpos
let diff = diff < 1 ? 0 : (diff - 1)
if diff == 0
let command = "normal! =="
else
let command = "normal! ==" . diff . "l"
endif
execute command
endfunction