[gnome-builder] vim: Add support for change and substitute commands



commit 2023dfa4f99322681e348c99635037717b8abe06
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Oct 4 17:29:26 2014 +0200

    vim: Add support for change and substitute commands
    
    The c-commands are handy shortcuts for delete-and-start-insert,
    's' is a (surprisingly handy) shorthand for 'cl' ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737961

 src/editor/gb-editor-vim.c |   64 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index b170ded..1ac2106 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -149,6 +149,15 @@ static guint       gSignals [LAST_SIGNAL];
 static void gb_editor_vim_cmd_select_line (GbEditorVim *vim,
                                            guint        count,
                                            gchar        modifier);
+static void gb_editor_vim_cmd_delete (GbEditorVim *vim,
+                                      guint        count,
+                                      gchar        modifier);
+static void gb_editor_vim_cmd_delete_to_end (GbEditorVim *vim,
+                                             guint        count,
+                                             gchar        modifier);
+static void gb_editor_vim_cmd_insert_before_line (GbEditorVim *vim,
+                                                  guint        count,
+                                                  gchar        modifier);
 
 GbEditorVim *
 gb_editor_vim_new (GtkTextView *text_view)
@@ -2846,6 +2855,38 @@ gb_editor_vim_cmd_backward_word (GbEditorVim *vim,
 }
 
 static void
+gb_editor_vim_cmd_change (GbEditorVim *vim,
+                          guint        count,
+                          gchar        modifier)
+{
+  g_assert (GB_IS_EDITOR_VIM (vim));
+
+  if (modifier == 'c')
+    {
+      gb_editor_vim_cmd_delete (vim, count, 'd');
+      gb_editor_vim_cmd_insert_before_line (vim, 0, '\0');
+    }
+  else
+    {
+      gb_editor_vim_cmd_delete (vim, count, modifier);
+      gb_editor_vim_set_mode (vim, GB_EDITOR_VIM_INSERT);
+    }
+}
+
+static void
+gb_editor_vim_cmd_change_to_end (GbEditorVim *vim,
+                                 guint        count,
+                                 gchar        modifier)
+{
+  g_assert (GB_IS_EDITOR_VIM (vim));
+
+  gb_editor_vim_cmd_delete_to_end (vim, count, '\0');
+  gb_editor_vim_set_mode (vim, GB_EDITOR_VIM_INSERT);
+  gb_editor_vim_move_forward (vim);
+}
+
+
+static void
 gb_editor_vim_cmd_delete (GbEditorVim *vim,
                           guint        count,
                           gchar        modifier)
@@ -3095,6 +3136,16 @@ gb_editor_vim_cmd_overwrite (GbEditorVim *vim,
 }
 
 static void
+gb_editor_vim_cmd_substitute (GbEditorVim *vim,
+                              guint        count,
+                              gchar        modifier)
+{
+  g_assert (GB_IS_EDITOR_VIM (vim));
+
+  gb_editor_vim_cmd_change (vim, count, 'l');
+}
+
+static void
 gb_editor_vim_cmd_undo (GbEditorVim *vim,
                         guint        count,
                         gchar        modifier)
@@ -3390,6 +3441,15 @@ gb_editor_vim_class_init (GbEditorVimClass *klass)
                                         GB_EDITOR_VIM_COMMAND_FLAG_NONE,
                                         GB_EDITOR_VIM_COMMAND_MOVEMENT,
                                         gb_editor_vim_cmd_backward_word);
+  gb_editor_vim_class_register_command (klass, 'c',
+                                        GB_EDITOR_VIM_COMMAND_FLAG_REQUIRES_MODIFIER |
+                                        GB_EDITOR_VIM_COMMAND_FLAG_VISUAL,
+                                        GB_EDITOR_VIM_COMMAND_CHANGE,
+                                        gb_editor_vim_cmd_change);
+  gb_editor_vim_class_register_command (klass, 'C',
+                                        GB_EDITOR_VIM_COMMAND_FLAG_NONE,
+                                        GB_EDITOR_VIM_COMMAND_CHANGE,
+                                        gb_editor_vim_cmd_change_to_end);
   gb_editor_vim_class_register_command (klass, 'd',
                                         GB_EDITOR_VIM_COMMAND_FLAG_REQUIRES_MODIFIER |
                                         GB_EDITOR_VIM_COMMAND_FLAG_VISUAL,
@@ -3455,6 +3515,10 @@ gb_editor_vim_class_init (GbEditorVimClass *klass)
                                         GB_EDITOR_VIM_COMMAND_FLAG_NONE,
                                         GB_EDITOR_VIM_COMMAND_CHANGE,
                                         gb_editor_vim_cmd_overwrite);
+  gb_editor_vim_class_register_command (klass, 's',
+                                        GB_EDITOR_VIM_COMMAND_FLAG_NONE,
+                                        GB_EDITOR_VIM_COMMAND_CHANGE,
+                                        gb_editor_vim_cmd_substitute);
   gb_editor_vim_class_register_command (klass, 'u',
                                         GB_EDITOR_VIM_COMMAND_FLAG_NONE,
                                         GB_EDITOR_VIM_COMMAND_CHANGE,


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