在插入模式下移动到行开始。

时间:2022-12-13 15:32:04

I know that I can use either:

我知道我也可以用:

  1. Home in insert mode
  2. 在插入模式
  3. Esc + i to exit insert mode and enter it again, effectively going to the beginning of line.
  4. Esc + i退出插入模式并再次输入,有效地进入行开始。

But neither satisfies me. In first case I have to tilt my head to hit Home, because I can't blindly hit it. In second case my left arm has to leave the home row to hit Esc, which is annoying too.

但是没有满足我。在第一种情况下,我必须倾斜我的头部才能击中要害,因为我不能盲目地击中它。在第二种情况下,我的左手臂必须离开主行来攻击Esc,这也很烦人。

Any thoughts?

任何想法吗?

8 个解决方案

#1


125  

Ctrl+O whilst in insert mode puts you in command mode for one key press only. Therefore Ctrl+O then Shift+I should accomplish what you're looking for.

在插入模式下,按Ctrl+O键只需要一个按键。所以按Ctrl+O然后Shift+我就可以完成你想要的了。

#2


40  

You could enter insert mode using I (capital i).

您可以使用I(大写I)输入插入模式。

It will put the cursor at the beginning of the line.

它将把光标放在行的开始处。

Similarly you can use A to add something at the end of the line.

同样,您可以使用A在该行的末尾添加一些东西。

Though, it does not really solve the problem of moving while already being in Insert mode.

虽然,它并不能真正解决在插入模式下移动的问题。

I have just checked help on Insert mode, there is no key combination in insert mode to move at the beginning of the line.

我刚刚检查了插入模式的帮助,在插入模式中没有键组合在开始的时候移动。

Other idea : Remap a new command only in insert mode

其他想法:仅在插入模式下重新映射一个新命令。

inoremap <C-i> <Home>

inoremap <我> <家>

#3


18  

I've got Ctrl+a and Ctrl+e mapped to beginning and end of line, respectively. This matches the behavior of most bash command lines. Works well for me.

我已经将Ctrl+a和Ctrl+e分别映射到行的开始和结束。这与大多数bash命令行的行为相匹配。让我很受用。

inoremap <C-e> <Esc>A
inoremap <C-a> <Esc>I

#4


3  

If you are using MacOS Terminal go to Preferences...>Settings>Keyboard and map the end key to Ctrl-O$ (it is displayed as \017$) and then use fn+left to simulate the end key. Do the same for the home key. Escape sequence \033[H also works for home.

如果你正在使用MacOS终端,请选择…>设置>键盘,并将结束键映射到Ctrl-O$(显示为\017$),然后使用fn+左侧来模拟结束键。对home键也这样做。Escape sequence \033[H也适用于家庭。

#5


1  

Your best course of action is to remap the action to a different key (see How to remap <Ctrl-Home> to go to first line in file? for ideas)

您的最佳操作方法是将操作重新映射到不同的键(请参见如何重新映射 到文件的第一行)?的想法)

I'd think of how often I use this "feature" and map it to a keystroke accordinly

我会考虑我使用这个“功能”的频率,并把它映射成一个按键。

#6


0  

You can map the keys to this:

你可以把键映射到这个:

inoremap II <Esc>I

ref: http://vim.wikia.com/wiki/Quick_command_in_insert_mode

裁判:http://vim.wikia.com/wiki/Quick_command_in_insert_mode

#7


0  

A shortcut that has worked for me (both muscle memory and intuitiveness) is to map __ (which is a double _) to "insert at start of current line".

为我工作的捷径(肌肉记忆和直觉)是将__(这是一个双_)映射到“在当前行开始时插入”。

Rationale:

理由是:

  • _ already goes to the start of line
  • 已经开始排队了。
  • in vim, doubling anything is a very common way of doing that "to this line"
  • 在vim中,翻倍是一种很常见的做法"到这一行"
  • double _ doesn't conflict with any motions (you're already at the start of line)
  • double _不会与任何动作发生冲突(你已经在开始排队了)
  • your hand is already in the right place if you went to the beginning of the line and now want to insert.
  • 你的手已经在正确的位置,如果你走到线的开始,现在想插入。

vimscript:

vimscript:

"insert at start of current line by typing in __ (two underscores)
function DoubleUnderscore()
    if v:count == 0 && getcurpos()[2] == 1
        :silent call feedkeys('I', 'n')
    else
        :silent call feedkeys('^', v:count + 'n')
    endif
endfunction
nnoremap <silent> _ :call DoubleUnderscore()<CR>

It's this complicated because the easy alternative nnoremap __ _I causes vim to delay on pressing _ to distinguish between _ and __.

这是很复杂的,因为简单的nnoremap __ _I会导致vim延迟,以区分_和__。

#8


0  

ctrl+o then 0
     |      |
  letter  number

#1


125  

Ctrl+O whilst in insert mode puts you in command mode for one key press only. Therefore Ctrl+O then Shift+I should accomplish what you're looking for.

在插入模式下,按Ctrl+O键只需要一个按键。所以按Ctrl+O然后Shift+我就可以完成你想要的了。

#2


40  

You could enter insert mode using I (capital i).

您可以使用I(大写I)输入插入模式。

It will put the cursor at the beginning of the line.

它将把光标放在行的开始处。

Similarly you can use A to add something at the end of the line.

同样,您可以使用A在该行的末尾添加一些东西。

Though, it does not really solve the problem of moving while already being in Insert mode.

虽然,它并不能真正解决在插入模式下移动的问题。

I have just checked help on Insert mode, there is no key combination in insert mode to move at the beginning of the line.

我刚刚检查了插入模式的帮助,在插入模式中没有键组合在开始的时候移动。

Other idea : Remap a new command only in insert mode

其他想法:仅在插入模式下重新映射一个新命令。

inoremap <C-i> <Home>

inoremap <我> <家>

#3


18  

I've got Ctrl+a and Ctrl+e mapped to beginning and end of line, respectively. This matches the behavior of most bash command lines. Works well for me.

我已经将Ctrl+a和Ctrl+e分别映射到行的开始和结束。这与大多数bash命令行的行为相匹配。让我很受用。

inoremap <C-e> <Esc>A
inoremap <C-a> <Esc>I

#4


3  

If you are using MacOS Terminal go to Preferences...>Settings>Keyboard and map the end key to Ctrl-O$ (it is displayed as \017$) and then use fn+left to simulate the end key. Do the same for the home key. Escape sequence \033[H also works for home.

如果你正在使用MacOS终端,请选择…>设置>键盘,并将结束键映射到Ctrl-O$(显示为\017$),然后使用fn+左侧来模拟结束键。对home键也这样做。Escape sequence \033[H也适用于家庭。

#5


1  

Your best course of action is to remap the action to a different key (see How to remap <Ctrl-Home> to go to first line in file? for ideas)

您的最佳操作方法是将操作重新映射到不同的键(请参见如何重新映射 到文件的第一行)?的想法)

I'd think of how often I use this "feature" and map it to a keystroke accordinly

我会考虑我使用这个“功能”的频率,并把它映射成一个按键。

#6


0  

You can map the keys to this:

你可以把键映射到这个:

inoremap II <Esc>I

ref: http://vim.wikia.com/wiki/Quick_command_in_insert_mode

裁判:http://vim.wikia.com/wiki/Quick_command_in_insert_mode

#7


0  

A shortcut that has worked for me (both muscle memory and intuitiveness) is to map __ (which is a double _) to "insert at start of current line".

为我工作的捷径(肌肉记忆和直觉)是将__(这是一个双_)映射到“在当前行开始时插入”。

Rationale:

理由是:

  • _ already goes to the start of line
  • 已经开始排队了。
  • in vim, doubling anything is a very common way of doing that "to this line"
  • 在vim中,翻倍是一种很常见的做法"到这一行"
  • double _ doesn't conflict with any motions (you're already at the start of line)
  • double _不会与任何动作发生冲突(你已经在开始排队了)
  • your hand is already in the right place if you went to the beginning of the line and now want to insert.
  • 你的手已经在正确的位置,如果你走到线的开始,现在想插入。

vimscript:

vimscript:

"insert at start of current line by typing in __ (two underscores)
function DoubleUnderscore()
    if v:count == 0 && getcurpos()[2] == 1
        :silent call feedkeys('I', 'n')
    else
        :silent call feedkeys('^', v:count + 'n')
    endif
endfunction
nnoremap <silent> _ :call DoubleUnderscore()<CR>

It's this complicated because the easy alternative nnoremap __ _I causes vim to delay on pressing _ to distinguish between _ and __.

这是很复杂的,因为简单的nnoremap __ _I会导致vim延迟,以区分_和__。

#8


0  

ctrl+o then 0
     |      |
  letter  number