sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

tinymode.vim : allows definition of tiny modes for Normal mode

 script karma  Rating 22/7, Downloaded by 1643    Comments, bugs, improvements  Vim wiki

created by
Andy Wokula
script type
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:
vimscript #2467
install details
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.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
tinymode_0.5.zip 0.5 2008-08-15 7.0 Andy Wokula 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 ...
tinymode.vim 0.3 2008-05-14 7.0 Andy Wokula 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
tinymode.zip 0.2 2008-05-02 7.0 Andy Wokula added support for the count (both initial v:count and digits typed within the mode)
tinymode.zip 0.1 2008-05-01 7.0 Andy Wokula Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo