I know the vi editor (and vim editor) can be a little hard to get started with, so I've been trying to share some short vi tutorials lately. Today I'd like to share some simple vi insert commands.
If you're already comfortable with the vi editor and just need to know some commands to insert in vi, here are the vi insert commands I use every day:
|i||insert at the current position|
|I||insert at the beginning of line|
|a||append just after the current cursor position|
|A||append at the end of line|
|o||Open a new line below the current line|
|O||Open a new line above the current line|
One point to remember: All of those commands can be issued in vi command mode. If you're new to vi, you can typically make sure you're in vi command mode by pressing the [Esc] key.
The lowercase letter "i" is almost certainly the most common vi insert command. It lets you insert text at your current cursor position.
If you want to insert text immediately after the current cursor position, just use the lowercase letter "a" to append text. This command essentially moves the cursor one position to the right, and puts you in insert mode there.
The uppercase letter "I" lets you insert text at the beginning of the current line. That is, wherever you are on the current line, this command moves you to the first column of that line and puts you in insert mode at that position.
If instead you want to insert text at the end of the current line, use the uppercase letter "A" to append text there. This command moves you to the end of the line and puts you in insert mode there.
Besides those insert commands, the vi and vim editors offer two new line commands that let you create ("open") new lines in your text files.
The lowercase letter "o" lets you open a new line just below your current line. When you use this command, vi creates a new blank line below your current line, and puts you in insert mode at that position.
The uppercase letter "o" lets you open a new line just above your current line. When you use this command, vi creates a new blank line above your current line, and puts you in insert mode there.