Vim mappings you create can have arbitrary lengths. Typically you'll try to make them short, since the shorter they are, the easier to type.
Three character mappings are fairly common though. For example, many plug-ins that comment and uncomment lines (such as vim-commentary or NERD Commenter) use gcc
to toggle comment on the current line.
As another example, the SpaceVim distribution sets up many 3 or 4 character mappings, most of them starting with <Space>
(or SPC
) which is SpaceVim's "leader" key. For example, SPC c l
to toggle comment on lines, SPC i l p
to insert a "lorem-ipsum" paragraph (of filler text), SPC x a =
to align on the "=" symbol, SPC b n
to switch to the next buffer, etc. Since SpaceVim creates so many mappings, its flagship feature is actually a hierarchical menu displaying the next choices, triggered by the SPC
at the start of the mapping, to help users navigate so many possible choices. (SpaceVim also displays an interactive menu for g
and z
, which are Vim's native multi-character prefixes for mappings.)
If I want to enter in a template empty docstring under a function's definition based on the language (since docstrings have a different syntax in different languages), the first character can be i
for insert, then d
for docstring, and then e.g. p
for Python or c
for C++.
As mentioned, using i
as a prefix is not a good idea, since it's already a one-character command.
If you're assuming these would come after a leader (possibly the one you set to mapleader
, which you access in mappings with <Leader>
), then it's fine.
But: do you really need both i
and d
? Do you have another action to do on a docstring other than inserting it? Shouldn't <Leader>d
perhaps suffice? (But then, if you have many many mappings, you might really need another level of mappings.)
Regarding supporting multiple languages, you should probably implement a single mapping to insert a docstring and have it insert the appropriate format based on the type of file. Vim can recognize file types (or you can set them explicitly) through the 'filetype'
option.
See :help filetype-plugin
for help creating a plug-in for a specific file type, which you can use to create sets of similar mappings implementing the same feature (such as inserting a docstring) for each relevant file type.
For inserting boilerplate, consider also the many snippet plug-ins available in Vim, which are perfect for this kind of task and typically allow you to define snippets per file type (so, again, you can use a single trigger for docstring and implement it differently for each language you care about.) Snippet plug-ins normally expand snippets from insert mode, so you usually don't need to reserve normal mode mappings (and deal with deep mappings, with long character sequences), which addresses another motivation you mentioned in the question.
i
as the first character of your mapping may not be desirable as when you just want to go from Normal mode to Insert (i.e. by hittingi
) you will encounter a small delay (whose length is configurable). Most people prefer to start with an unbound key (and that usually means their leader key). – B Layer Sep 1 '20 at 1:28'timeout'
,'ttimeout'
,'timeoutlen'
,'ttimeoutlen
. It's for those times when what happens next is ambiguous to vim since there may be a mapping x as well as a mapping xx. Or xy and xz. In those cases what happens when you've just hit x. – B Layer Sep 1 '20 at 2:11:h map-typing
, too – B Layer Sep 1 '20 at 2:20