While typing I realize that I need to move to the beginning of the line. Usually I use Esc and I. But I am wondering if there is another way to move to the beginning of the line in the insert mode.
I will remap some shortcut keys in my vimrc, most of them are cursor moving under the Insert mode.
For example, I will use the Emacs-Like (as same as in Linux Terminal) shortcut:
map <C-a> <ESC>^ imap <C-a> <ESC>I map <C-e> <ESC>$ imap <C-e> <ESC>A inoremap <M-f> <ESC><Space>Wi inoremap <M-b> <Esc>Bi inoremap <M-d> <ESC>cW
- Ctrl+a: Go to beginning of the line [Normal Mode && Insert Mode]
- Ctrl+e: Go to end of line [Normal Mode && Insert Mode]
- Alt+f: Backward a word [Insert Mode]
- Alt+b: Forward a word [Insert Mode]
- Alt+d: Delete a word (backward) [Insert Mode]
Of cause, vim has default shortcut key for Delete a word (forward) [Insert Mode], that is Ctrl+w
While in Insert mode, the "Home" key moves the cursor to the beginning of the current line. Perhaps a better way, from Insert mode, is
where X is the line number, and you can now move to the beginning of any line number you specify. (Note: ":set nu" enables line numbering. ":set nonu" disables it).
If you don't need the beginning of the line, per se, please note, you can also use other movements to your liking. For example, "CTRL+o 10k" moves exactly 10 lines from the current line position. Your cursor is not moved to the beginning of the line, however, rather preserving your cursor's relative position in line.
From Normal mode, however, "SHIFT+I" positions the cursor in the first position of the current line, in Insert mode.
This is my Vim version and platform:
$>vim --version VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 21 2021 23:02:54) MS-Windows 64-bit console version Included patches: 1-2541 Compiled by appveyor@APPVYR-WIN Huge version without GUI.