If you haven't noticed by now, vim is a modeful editor. Vim has 6 different basic modes of operation. The modes are Normal, Visual, Select, Insert, Command line, and Ex. Each mode is suited to a particular purpose. The following sections will cover the basics of each of these modes.
If you are not sure which mode you are in simply tap the Escape key twice and you will be put into Normal mode. |
To get more information on modes type:
:help vim-modes |
Normal mode is the mode vim normally starts in. Normal mode is also known as command mode. Be careful not to confuse this with Command line mode.
Normal mode is where you use most of the built in commands and is primarily used to move the cursor around.
To get some basic information about normal mode type:
:help normal-mode |
Visual mode is a nice way to select large blocks of text so that you can perform other operations on them. You enter visual mode by pressing v (lowercase v), V (capital V), or CTRL-V. The v command highlights the block of text by character, the V command highlights text by the line, and the CTRL-V highlights the text by block.
Once you enter visual mode you can use the movement keys (h, k, j, l, w ...) to change which text is highlighted. You can then enter a sequence of Normal commands to manipulate the text. You can also enter Command line mode by typing the : (colon) and then entering a command.
If you enter command line mode from visual mode you'll notice this in the "status bar":
This is just vim's notation for selecting that block of text. Don't backspace over it. It will be part of the command you enter. |
As an example, open vim and create a new document, or simply use vimtutor and manipulate that file. Type several sentences on several different lines. Press V to enter "linewise" visual mode. Use your cursor/movement keys to select the first line and type: gU. This should change the entire selected text to all uppercase letters. Once the text is highlighted you can also use the (y)ank and (d)elete commands to "copy" or "cut" the text so you can paste it elsewhere with the (p)aste command. Experiment with it a little. You'll use these commands a lot.
TODO. Need some useful examples of visual mode. Anyone want to coauthor?
To get more information on what's possible type:
:help visual-mode |
TODO. Need some useful examples of select mode. Anyone want to coauthor?
To get more information on what's possible type:
:help select-mode |
Insert mode is the mode in which the letters you type are input into the document. This mode resembles a regular editor. There are other options which will allow you to do additional things as well. For instance, if you use vim with languages which have accented characters that do not appear on your keyboard you can use the digraph option to type those characters.
To use digraphs you need to issue the command:
:set digraph |
If you get an error after using this command your version of vim was not compiled with digraph support. The default version of vim in Debian has digraph support. |
Digraphs are used by typing a character, the Backspace key, and then another character. These combinations of characters are called maps. You can see which digraph maps are available to you by typing:
:digraph |
Here is the output of that command:
~! ¡ 161 c| ¢ 162 $$ £ 163 ox ¤ 164 e= ¤ 164 Y- ¥ 165 || ¦ 166 pa § 167 "" ¨ 168 cO © 169 a- ª 170 << « 171 -, ¬ 172 -- 173 rO ® 174 -= ¯ 175 ~o ° 176 +- ± 177 22 ² 178 33 ³ 179 '' ´ 180 ju µ 181 pp ¶ 182 ~. · 183 ,, ¸ 184 11 ¹ 185 o- º 186 >> » 187 14 ¼ 188 12 ½ 189 34 ¾ 190 ~? ¿ 191 A` À 192 A' Á 193 A^ Â 194 A~ Ã 195 A" Ä 196 A@ Å 197 AA Å 197 AE Æ 198 C, Ç 199 E` È 200 E' É 201 E^ Ê 202 E" Ë 203 I` Ì 204 I' Í 205 I^ Î 206 I" Ï 207 D- Ð 208 N~ Ñ 209 O` Ò 210 O' Ó 211 O^ Ô 212 O~ Õ 213 O" Ö 214 /\ × 215 OE × 215 O/ Ø 216 U` Ù 217 U' Ú 218 U^ Û 219 U" Ü 220 Y' Ý 221 Ip Þ 222 ss ß 223 a` à 224 a' á 225 a^ â 226 a~ ã 227 a" ä 228 a@ å 229 aa å 229 ae æ 230 c, ç 231 e` è 232 e' é 233 e^ ê 234 e" ë 235 i` ì 236 i' í 237 i^ î 238 i" ï 239 d- ð 240 n~ ñ 241 o` ò 242 o' ó 243 o^ ô 244 o~ õ 245 o" ö 246 :- ÷ 247 oe ÷ 247 o/ ø 248 u` ù 249 u' ú 250 u^ û 251 u" ü 252 y' ý 253 ip þ 254 |
The columns are arranged so that the first character is typed followed by a backspace and then the second character is typed. For example, to get the ¡ (an upside down exclamation point) character I would simply type ~-Backspace-!.
These mappings seem to change between systems and versions of vim. Make sure you double check what your maps are so you get what you expect. |
If you use these characters frequently you may wish to explore the langmap option as well. For more information type the command :help langmap. |
To get more information on what's possible with digraphs type:
:help digraphs |
To get more information on what's possible with insert mode type:
:help insert-mode |
Command line mode is entered by typing : (the colon). Once typed the "status bar" along the bottom of the console shows the colon and whatever you type. All the previous :help commands you have typed are examples.
Command line mode is entered from Normal mode. If you type the colon and can't seem to get into command line mode try tapping the escape key twice and then type the colon. |
Command line mode contains a "history" much like the shell does. By typing the beginning of your command and then using the arrow keys you can scroll through a list of the previous commands you entered.
Command line mode also has "tab-completion" much like the shell does. By typing the beginning of your command and then the TAB key the command line will complete the available commands for you.
To get more information on what's possible with command line mode type:
:help cmdline-mode |