### Class

# GtkSource VimIMContext

since: 5.4

#### Description [src]

    final class GtkSource.VimIMContext : Gtk.IMContext
    {
      /* No available fields */
    }

Vim emulation.

The `GtkSourceVimIMContext` is a `GtkIMContext` implementation that can be used to provide Vim-like editing controls within a `GtkSourceView`.

The `GtkSourceViMIMContext` will process incoming `GdkKeyEvent` as the user types. It should be used in conjunction with a `GtkEventControllerKey`.

Various features supported by `GtkSourceVimIMContext` include:

- Normal, Insert, Replace, Visual, and Visual Line modes
- Support for an integrated command bar and current command preview
- Search and replace
- Motions and Text Objects
- History replay
- Jumplists within the current file
- Registers including the system and primary clipboards
- Creation and motion to marks
- Some commonly used Vim commands

It is recommended that applications display the contents of `GtkSourceVimIMContext:command-bar-text` and `GtkSourceVimIMContext:command-text` to the user as they represent the command-bar and current command preview found in Vim.

`GtkSourceVimIMContext` attempts to work with additional `GtkIMContext` implementations such as IBus by querying the `GtkTextView` before processing the command in states which support it (notably Insert and Replace modes).

    GtkEventController *key;
    GtkIMContext *im_context;
    GtkWidget *view;

    view = gtk_source_view_new ();
    im_context = gtk_source_vim_im_context_new ();
    key = gtk_event_controller_key_new ();

    gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (key), im_context);
    gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
    gtk_widget_add_controller (view, key);
    gtk_im_context_set_client_widget (im_context, view);

    g_object_bind_property (im_context, "command-bar-text", command_bar_label, "label", 0);
    g_object_bind_property (im_context, "command-text", command_label, "label", 0);

    key = Gtk.EventControllerKey.new()
    im_context = GtkSource.VimIMContext.new()
    buffer = GtkSource.Buffer()
    view = GtkSource.View.new_with_buffer(buffer)

    key.set_im_context(im_context)
    key.set_propagation_phase(Gtk.PropagationPhase.CAPTURE)
    view.add_controller(key)
    im_context.set_client_widget(view)

    im_context.bind_property(
        source_property="command-text",
        target=command_label,
        target_property="label",
        flags=GObject.BindingFlags.DEFAULT,
    )

    im_context.bind_property(
        source_property="command-bar-text",
        target=command_bar_label,
        target_property="label",
        flags=GObject.BindingFlags.DEFAULT,
    )

Available since: 5.4

#### Hierarchy

#### Ancestors

- GtkIMContext
- GObject

#### Constructors

###### gtk_source_vim_im_context_new

No description available.

#### Instance methods

###### gtk_source_vim_im_context_execute_command

Executes `command` as if it was typed into the command bar by the user except that this does not emit the `GtkSourceVimIMContext::execute-command` signal.

since: 5.4

###### gtk_source_vim_im_context_get_command_bar_text

Gets the current command-bar text as it is entered by the user.

since: 5.4

###### gtk_source_vim_im_context_get_command_text

Gets the current command text as it is entered by the user.

since: 5.4

##### Methods inherited from GtkIMContext (15)

###### gtk_im_context_activate_osk

Requests the platform to show an on-screen keyboard for user input.

###### gtk_im_context_delete_surrounding

Asks the widget that the input context is attached to delete characters around the cursor position by emitting the `::delete_surrounding` signal.

###### gtk_im_context_filter_key

Allow an input method to forward key press and release events to another input method without necessarily having a `GdkEvent` available.

###### gtk_im_context_filter_keypress

Allow an input method to internally handle key press and release events.

###### gtk_im_context_focus_in

Notify the input method that the widget to which this input context corresponds has gained focus.

###### gtk_im_context_focus_out

Notify the input method that the widget to which this input context corresponds has lost focus.

###### gtk_im_context_get_preedit_string

Retrieve the current preedit string for the input context, and a list of attributes to apply to the string.

###### gtk_im_context_get_surrounding

Retrieves context around the insertion point.

###### gtk_im_context_get_surrounding_with_selection

Retrieves context around the insertion point.

###### gtk_im_context_reset

Notify the input method that a change such as a change in cursor position has been made.

###### gtk_im_context_set_client_widget

Set the client widget for the input context.

###### gtk_im_context_set_cursor_location

Notify the input method that a change in cursor position has been made.

###### gtk_im_context_set_surrounding

Sets surrounding context around the insertion point and preedit string.

###### gtk_im_context_set_surrounding_with_selection

Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the `GtkIMContext::retrieve-surrounding` signal, and will likely have no effect if called at other times.

###### gtk_im_context_set_use_preedit

Sets whether the IM context should use the preedit string to display feedback.

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### GtkSource.VimIMContext:command-bar-text

No description available.

###### GtkSource.VimIMContext:command-text

No description available.

##### Properties inherited from GtkIMContext (2)

###### Gtk.IMContext:input-hints

Additional hints that allow input methods to fine-tune their behaviour.

###### Gtk.IMContext:input-purpose

The purpose of the text field that the `GtkIMContext is connected to.

#### Signals

###### GtkSource.VimIMContext::edit

Requests the application open the file found at `path`.

since: 5.4

###### GtkSource.VimIMContext::execute-command

The signal is emitted when a command should be executed. This might be something like `:wq` or `:e <path>`.

since: 5.4

###### GtkSource.VimIMContext::format-text

Requests that the application format the text between `begin` and `end`.

since: 5.4

###### GtkSource.VimIMContext::write

Requests the application save the file.

since: 5.4

##### Signals inherited from GtkIMContext (6)

###### GtkIMContext::commit

The ::commit signal is emitted when a complete input sequence has been entered by the user.

###### GtkIMContext::delete-surrounding

The ::delete-surrounding signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.

###### GtkIMContext::preedit-changed

The ::preedit-changed signal is emitted whenever the preedit sequence currently being entered has changed.

###### GtkIMContext::preedit-end

The ::preedit-end signal is emitted when a preediting sequence has been completed or canceled.

###### GtkIMContext::preedit-start

The ::preedit-start signal is emitted when a new preediting sequence starts.

###### GtkIMContext::retrieve-surrounding

The ::retrieve-surrounding signal is emitted when the input method requires the context surrounding the cursor.

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct GtkSourceVimIMContextClass {
      GtkIMContextClass parent_class;

    }

No description available.

###### Class members

`parent_class: GtkIMContextClass`

  No description available.