I want to remap <C-i>*character* to i*character*<Esc> for easy inserting of single characters. This is what I've written:let printable_characters = [ '!', '', '#', '$', '%', '&', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']for val in printable_characters    silent! execute nnoremap <C-i> . val .  i . val . <Esc>    silent! execute nnoremap <C-a> . val .  a . val . <Esc>    unlet valendforWhen I try to source it by executing :source %, the following happens:It will complain about how I forgot the endforOnce I press return, the file will look like this:let printable_characters = [ '!', '', '#', '$', '%', '&', '''', '(',          ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']for val in printable_characters    silent! execute nnoremap <C-i> . val .  i . val . <Esc>    silent! execute nnoremap <C-a> . val .  a . val . <Esc>    unlet val    silent! execute nnoremap <C-a> . val .  a . val . <Esc>    unlet val    endforendfor
Vimscript file rewrites itself and complains of a mismatched endfor
key bindings;vimscript
There is a much better way of accomplishing this than brute forcing it.  You can use these simple expr mappings instead:nnoremap <expr> <c-i> i . nr2char(getchar()) . <Esc>nnoremap <expr> <c-a> a . nr2char(getchar()) . <Esc>Here is how they work:nnoremap <expr> <c-i> - Create a mapping for Ctrli with the <expr> flag.  This flag tells vim to interpret all of the characters after <c-i> as an expression when the mapping is triggered, which means you can use functions, variables, operators and the like.i . nr2char(getchar()) . <Esc> - A simple expression which concatenates i, a single character given by the user, and <Esc>.  getchar returns a number representing the pressed key, so nr2char is used to convert it to a string.  The result of this concatenation is what is used as the final mapping when the user presses Ctrli.  For example, if the user presses Ctrlit then this expression evaluates to it<Esc>, which then results in those keys being pressed.For more, see :help :map-<expr>.Also, look at the other answers for why your current solution doesn't work.