Schim
Classes | Typedefs | Functions
Vim Namespace Reference

Everything related to vim-mode inside schim. More...

Classes

class  Action
 An action in vim-mode. More...
 
class  Count
 Representation of a vim-count. More...
 

Typedefs

typedef Count N
 Convenience typedef.
 

Functions

void enable (bool enable)
 Enable/Disable vim-mode throughout the application instance.
 
bool enabled ()
 Is vim-mode enabled?
 
Count n ()
 The vim-count from the current key sequence.
 
void addBinding (const QString &sequence, const QString &action)
 Register a keybinding with Vim-mode. More...
 
void addBindings (const QMap< QString, QString > &map)
 Convenient alternative to multiple calls of Vim::addBinding. More...
 
void registerKeyPress (QKeyEvent *event, std::function< bool(const Action &action)> callback, bool allowCount=true)
 Process a key press in vim-mode. More...
 
void resetStroke ()
 Discard the current key sequence and reset vim status indicator.
 
QString getStatusText ()
 Get the vim status text for the current key sequence.
 

Detailed Description

Everything related to vim-mode inside schim.

Function Documentation

◆ addBinding()

void Vim::addBinding ( const QString &  sequence,
const QString &  action 
)

Register a keybinding with Vim-mode.

Parameters
sequenceThe key sequence that triggers action.
actionThe vim-action that is performed when the key sequence is input.

◆ addBindings()

void Vim::addBindings ( const QMap< QString, QString > &  map)

Convenient alternative to multiple calls of Vim::addBinding.

Parameters
mapMap of bindings to be registered with vim-mode.

◆ registerKeyPress()

void Vim::registerKeyPress ( QKeyEvent *  event,
std::function< bool(const Action &action)>  callback,
bool  allowCount = true 
)

Process a key press in vim-mode.

Parameters
eventKeyPress event that triggered this.
callbackCallback for when the input key sequence matches a binding.
allowCountProcess vim-counts as part of a key sequence.

When a widget receives a KeyPress event, it should call this function if vim-like behavior is desired. The event will be processed, the current vim key sequence will be updated and it will be shown in the vim status indicator of the main window. If the sequence matches a binding callback will be called with an appropriate Vim::Action.

Note
If vim-mode is not enabled, this function does nothing.
If allowCount is false, treat numbers as normal key sequences.
See also
Vim::Action
Vim::addBinding

First we determine if we are listening for the user to input a count (only if allowCount is true). We correspondingly process all digits the user enters and form a count.

Then, we test if the sequence matches a binding. If it does, callback is called. Otherwise, we test if any binding starts with the sequence that has been input so far. If even this is not the case, the sequence is discarded and the vim status is reset.