See help inoremap. Really, the help tells you, very concisely, what you need to know. I don't need to repeat it here.
e.g.
inoremap dcv document.createElement("div") " insert mode
Mapping modes
Actually I had to google this one. It's in the docs but I couldn't easily find it within vim's help:
1.3 MAPPING AND MODES *:map-modes*
*mapmode-nvo* *mapmode-n* *mapmode-v* *mapmode-o*
There are six sets of mappings
- For Normal mode: When typing commands.
- For Visual mode: When typing commands while the Visual area is highlighted.
- For Select mode: like Visual mode but typing text replaces the selection.
- For Operator-pending mode: When an operator is pending (after "d", "y", "c",
etc.). See below: |omap-info|.
- For Insert mode. These are also used in Replace mode.
- For Command-line mode: When entering a ":" or "/" command.
Special case: While typing a count for a command in Normal mode, mapping zero
is disabled. This makes it possible to map zero without making it impossible
to type a count with a zero.
Thinking about how the 'mapping engine' works.
So you start with an input sequence of characters. Let's assume there's no timeout mechanism (where e.g. pressing j followed by k and waiting a second is the same as j followed by k and not waiting).
There is then an output sequence and a temporary sequence. Things in the output sequence are interpreted by the core program.
Our map is a Trie, and our state is a position in the trie. We initially start at the root of the trie. If the first input character is unrecognised, we dump the temporary
sequence to the output sequence (i.e. unrecognised sequences pass through unmodified), clear the temporary sequence and reset our state to the root of the trie. If the first character is defined in the current node, append the current character to the temporary sequence, and move our state to the node pointed to by that char. If we find ourself in a node with an expansion, in the case of map, we prepend the expansion to the input sequence; and in case of noremap we append the expansion to the output sequence, and in either case we then clear the temporary sequence. Presumably it's just as easy to be able to do both. This has similarities to how \(\TeX\)'s macro system works.