You should read TODO in the manual before proceeding.
Vim mode is implemented in src/ui/vim.h and src/ui/vim.cpp. It is enabled
and disabled by calling Vim::enable.
When a QWidget or GObject receives a keyPressEvent, it has the
option to process that event in Vim mode. It is supposed to call
Vim::registerKeyPress, providing the incoming event and a pointer to a
callback function as parameters. The callback function will be invoked if a
proper key sequence is matched.
Todo
Add more details.
-
namespace
Vim Typedefs
-
typedef Count
N
Functions
-
void
enable(bool enable)
-
bool
enabled()
-
Count
n()
-
void
addBinding(const QString &sequence, const QString &action)
-
void
addBindings(const QMap<QString, QString> &map)
-
void
registerKeyPress(QKeyEvent *event, std::function<bool(const Action &action)> callback, bool allowCount = true, )
-
void
resetStroke()
-
QString
getStatusText()
-
class
Action Public Functions
-
explicit
Action(const QString &command, int count = 0)
-
QString
getCommand() const
-
Count
getCount() const
-
bool
operator==(const QString &cmd) const
-
explicit
-
class
Count Public Functions
-
Count(int count)
-
operator int() const
-
int
raw() const
-
-
typedef Count
-
namespace
Vim Everything related to vim-mode inside schim.
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.
- Parameters
sequence -- The key sequence that triggers
action.action -- The vim-action that is performed when the key sequence is input.
-
void
addBindings(const QMap<QString, QString> &map) Convenient alternative to multiple calls of
Vim::addBinding.- Parameters
map -- Map of bindings to be registered with vim-mode.
-
void
registerKeyPress(QKeyEvent *event, std::function<bool(const Action &action)> callback, bool allowCount = true, ) Process a key press in vim-mode.
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.- See
- See
First we determine if we are listening for the user to input a count (only if
allowCountistrue). We correspondingly process all digits the user enters and form a count.Then, we test if the sequence matches a binding. If it does,
callbackis 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.Note
If vim-mode is not enabled, this function does nothing.
Note
If
allowCountisfalse, treat numbers as normal key sequences.- Parameters
event -- KeyPress event that triggered this.
callback -- Callback for when the input key sequence matches a binding.
allowCount -- Process vim-counts as part of a key sequence.
-
void
resetStroke() Discard the current key sequence and reset vim status indicator.
-
QString
getStatusText() Get the vim status text for the current key sequence.
-
class
Action - #include <vim.h>
An action in vim-mode.
A vim-action is a key sequence that is accompanied with some extra data:
a vim-count [optional]
input register [TODO]
a vim-command
a vim-motion [TODO]
output register [TODO]
Public Functions
-
explicit
Action(const QString &command, int count = 0) Construct a vim-action.
-
QString
getCommand() const Get the vim-command associated with this action.
-
Count
getCount() const Get the vim-count associated with this action.
-
bool
operator==(const QString &cmd) const Is this action's command identical to
cmd?
-
class
Count - #include <vim.h>
Representation of a vim-count.
When the user inputs a key sequence, usually a count can also be specified. This count determines how many times the command will be repeated. An unspecified count is equal to
Count(0).Different commands will treat a 0-count differently. Some commands equate a 0-count with a 1-count, others treat it in some special way. This class provides a uniform interface for each use case.
Casting a
Vim::Countto anintyields a basic count, i.e.int(Count(0)) == 1. On the other hand,raw()yields the raw count, i.e.Count(0).raw() == 0.Note
For non-zero counts,
int()andraw()are equivalent.- See
Public Functions
-
Count(int count) Construct a vim-count.
- Parameters
count -- The raw vim-count.
-
operator int() const Conversion to integer.
- Returns
The basic count.
-
int
raw() const Get the raw count from this
Count.
-
typedef Count