<C-r> keystroke in Insert mode is used to insert the contents of a register, so
<C-r>a will insert the contents of register
<C-r>" will insert the contents of the default register. See
The expression register is a bit special, in that inserting it (or otherwise reading from it in another context) switches to a special expression input (on the last line, where you typically have the Ex command line or you enter search patterns following a
? command.) It will then accept an expression, evaluate it, and use it as the value of the register. There's even a direct tag for the usage of that register with
<C-r> in the documentation, see
When you use it in a mapping, the mapping gets to type the expression. The
<CR> at the end is still needed, in order to actually let Vim know that the expression is over and it can go ahead and evaluate it. (Same as if you were to write a Normal mode mapping that starts a
: command, or a
/ search, you also need a
<CR> on those to execute them.) The documentation for the expression register mentions the need for
:help quote_= for that documentation.
Why not just do the same thing with:
:imap <c-t> <c-o>:!./script.py<cr>
They're not really the same.
:!command<CR> will only run the external command, but not insert its output into the current buffer. The output from the command only goes to the screen, to display to the user, it's not incorporated into the current buffer.
<C-r>=system('command')<CR> is inserting the output of that system command at the current cursor position, running the external command without any specific input coming through stdin.
:.!command<CR>, which will on the other hand filter the current line through the external command, replacing it with the output of the external command. Or
:r !command<CR>, which will append the output of the external command into the current buffer, but starting on the next line (and not on the cursor position.)