Reputation: 25729
I know that I can use either:
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.
Any thoughts?
Upvotes: 85
Views: 55222
Reputation: 1
i use this command to go to end of line without leaving insert mode
inoremap jl <esc><S-a>
Similarly to go to beginning of line will be:
inoremap jl <esc><S-i>
Upvotes: 0
Reputation: 29519
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_
doesn't conflict with any motions (you're already at the start of line)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 __
.
Upvotes: 0
Reputation: 1
You can map the keys to this:
inoremap II <Esc>I
ref: http://vim.wikia.com/wiki/Quick_command_in_insert_mode
Upvotes: 0
Reputation: 516
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.
inoremap <C-e> <Esc>A
inoremap <C-a> <Esc>I
Upvotes: 25
Reputation: 1138
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.
Upvotes: 3
Reputation: 9279
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.
Upvotes: 159
Reputation: 42218
You could enter insert mode using I
(capital 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.
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>
Upvotes: 60
Reputation: 2346
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
Upvotes: 1