[gnome-builder/wip/vim] vim: implement `0` (zero) command.



commit 6684f215d609eb6ae0c3bd04fd39392baf91633e
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 30 16:04:31 2014 -0700

    vim: implement `0` (zero) command.
    
    This jumps to the 0 offset in the current line. It ignores any sort of
    forward jump to the first word like ^ does.

 src/editor/gb-editor-vim.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 9be1149..4d2d859 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -291,6 +291,29 @@ gb_editor_vim_move_line_start (GbEditorVim *vim)
 }
 
 static void
+gb_editor_vim_move_line0 (GbEditorVim *vim)
+{
+  GtkTextBuffer *buffer;
+  GtkTextIter iter;
+  GtkTextIter selection;
+  gboolean has_selection;
+
+  g_assert (GB_IS_EDITOR_VIM (vim));
+
+  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (vim->priv->text_view));
+  has_selection = gb_editor_vim_get_selection_bounds (vim, &iter, &selection);
+
+  gtk_text_iter_set_line_offset (&iter, 0);
+
+  if (has_selection)
+    gb_editor_vim_select_range (vim, &iter, &selection);
+  else
+    gtk_text_buffer_select_range (buffer, &iter, &iter);
+
+  vim->priv->target_line_offset = gb_editor_vim_get_line_offset (vim);
+}
+
+static void
 gb_editor_vim_move_line_end (GbEditorVim *vim)
 {
   GbEditorVimPrivate *priv;
@@ -1455,9 +1478,17 @@ gb_editor_vim_handle_normal (GbEditorVim *vim,
       gb_editor_vim_move_line_end (vim);
       return TRUE;
 
+    case GDK_KEY_0:
+      /*
+       * Move to the first offset (even if it is whitespace) on the current
+       * line.
+       */
+      gb_editor_vim_move_line0 (vim);
+      return TRUE;
+
     case GDK_KEY_asciicircum:
       /*
-       * Move to the beginning of the line.
+       * Move to the first word in the line.
        */
       gb_editor_vim_move_line_start (vim);
       return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]