而在插入模式在Vim,有任何方法来遍历文本移动一些字符向前和向后除了使用方向键?

如果我在插入模式下按下h, j, k和l,实际字符将打印在屏幕上,而不是在文本中移动。

我现在这样做的方式是不得不诉诸Ctrl + [(Esc)和遍历文本;但很明显,这是没有成效的。


当前回答

在GVim中,您可以使用鼠标。但说实话,使用方向键有什么错呢?它们在键盘上是有原因的。

其他回答

为了在插入模式下有更好的导航,为什么不映射一些键呢?

imap <C-b> <Left>
imap <C-f> <Right>
imap <C-e> <End>
imap <C-a> <Home>
" <C-a> is used to repeat last entered text. Override it, if its not needed

如果您可以在您的终端中使用元键,那么您可以更好地模拟emacs模式。正常模式下的导航更好,但对于较短的移动,它有助于保持插入模式。

对于较长的跳跃,我更喜欢以下默认翻译:

<Meta-b>    maps to     <Esc><C-left>

这将切换到正常模式并返回一个单词

对于一些常用的动作和动作,我定义了以下映射。与CTRL+O组合相比,这节省了一次击键,因为我经常需要它们,它们在长期内是有回报的 运行。

inoremap <A-$> <C-o>$
inoremap <A-^> <C-o>^
inoremap <A-h> <Left>
inoremap <A-l> <Right>
inoremap <A-O> <C-O>O
inoremap <A-o> <C-o>o

我相信Home和End(以及PageUp/PageDn)在插入模式下也能正常工作,但除此之外,我不相信还有其他为文本遍历定义的标准键。

抱歉,vim不是这样工作的。

你应该切换到“正常”模式,导航,然后返回插入。

在插入模式下,使用CtrlO切换到正常模式,只执行一个命令:

CTRL-O h  move cursor left 
CTRL-O l  move cursor right
CTRL-O j  move cursor down
CTRL-O k  move cursor up

这可能是做你想做的事情的最简单的方法,也很容易记住。

插入模式中其他非常有用的控制键:

CTRL-W    delete word to the left of cursor
CTRL-O D  delete everything to the right of cursor
CTRL-U    delete everything to the left of cursor
CTRL-H    backspace/delete
CTRL-J    insert newline (easier than reaching for the return key)
CTRL-T    indent current line
CTRL-D    un-indent current line

这将消除许多浪费的开关回到正常模式。