tinymode.vim : allows definition of tiny modes for Normal mode
| script karma
Downloaded by 1573
Comments, bugs, improvements
script versions (upload new version)
|We cannot add new Vim modes using Vim script. But we can map keys in a way
that comes close. Example:
nmap <C-W>+ <C-W>+<SID>ws
nmap <C-W>- <C-W>-<SID>ws
nn <script> <SID>ws+ <C-W>+<SID>ws
nn <script> <SID>ws- <C-W>-<SID>ws
nmap <SID>ws <Nop>
These mappings make the builtin CTRL-W_+ and CTRL-W_- (in short ^W+, ^W-)
keys a little smarter: You can now type ^W++- instead of ^W+^W+^W- to change
the window size. It's like ^W+ enters a "Vim mode" with the new keys + and - .
tinymode.vim is not needed to create such mappings, but it adds some
- tinymode-style notation of the above mappings:
call tinymode#EnterMap("winsize", "<C-W>+", "+")
call tinymode#EnterMap("winsize", "<C-W>-", "-")
call tinymode#Map("winsize", "+", "wincmd +")
call tinymode#Map("winsize", "-", "wincmd -")
Ok, no benefits yet, but read on:
- you can enable support for a count typed within a mode:
call tinymode#ModeArg("winsize", "owncount", 1)
you need a literal [N] in the commands for the count to be recognized:
call tinymode#Map("winsize", "+", "[N]wincmd +")
call tinymode#Map("winsize", "-", "[N]wincmd -")
- mode message
call tinymode#ModeMsg("winsize", "Change window size +/-")
The mode message makes it easy to spot that a mode is active. It is even
more useful when it shows the available keys.
- different 'timeoutlen'
call tinymode#ModeArg("winsize", "timeoutlen", 5000)
In most cases, the default 'timeoutlen' of 1000 ms is too short. That's
why tinymode sets the default to 3000 ms throughout a mode. If this is
not enough, another value can be given.
- interruption recovery
The "tinymode technique" has a backdraw: If a command "beeps" or you press
CTRL-C, the chain of mappings is interrupted, which means the necessary
clean up before leaving a mode is skipped. "Clean up" means to set some
options back to previous values ('timeoutlen', 'cpo', 'showcmd').
Unfortunately, a beep cannot be catched like other errors.
If you detect this situation, you can start and leave a mode in a clean
way or execute :LeaveMode .
- timeout warning
Sooner or later a tiny mode times out automatically. As a visual hint
that a mode will time out soon the color of the mode message will be
changed from ModeMsg to Normal.
(btw: this exact description is not part of the zip package)
2008 Nov 14
looks as if a similar script has been added:
|extract the archive to your vim folder (e.g. ~/.vim or ~\vimfiles), files in the archive:
tinym_ex.vim is not required, it contains examples.
Click on the package to download.
ip used for rating: 22.214.171.124
||still work in progress, but an upload is due:
resets more important options (lz, cpo), custom 'timeoutlen', 2nd timeout step, more mode options, modes no longer quit on (catchable) errors, 0 can be command or count, some more ...
||exec commands when entering/leaving a mode, via ModeArg()
now works with i_Ctrl-O
keep error messages on screen
now ModeMsg(..., "") removes the message entry
fixed init bug with Map() followed by EnterMap() for same key
||added support for the count (both initial v:count and digits typed within the mode)