Author Topic: VI mode: visual block insert  (Read 15604 times)

sunray

  • Community Member
  • Posts: 8
  • Hero Points: 0
VI mode: visual block insert
« on: August 22, 2008, 08:44:52 AM »
Hi,

In vim it is possible to do a visual block selection ( Ctrl-v ) and press 'I' to insert. SlickEdit does not
support this command. Doing a block selection and press 'c' to change, does work.

Visual block and insert is particular useful to insert comments (e.g. # in Python) in front of large code blocks.

I modified  slickedit/macros/vivmode.e and added to following function:

Code: [Select]
/**
 * By default this command handles the 'I' key pressed in visual mode.                 
 * The cursor moves in front of the selected text, and insert mode is turned on.
 *                                                                                     
 * @return                                                                             
 */
_command int vi_visual_insert() name_info(','VSARG2_MARK|VSARG2_CMDLINE|VSARG2_REQUIRES_EDITORCTL|VSARG2_LASTKEY){
   if (!vi_visual_maybe_command()) {
      if (!in_block_visual_mode) {
         begin_select();
         vi_visual_toggle();
         vi_switch_mode('I');
      } else {
         // switch to block insert mode for block selections
         int num_lines = count_lines_in_selection();
         end_select();
         typeless p;
         _save_pos2(p);
         begin_select();
         int col = p_col;
         _select_block();
         _restore_pos2(p);
         p_col = col;
         _select_block();
         block_insert_mode();
      }
      return(0);
   }
   return(0);
}

It's a copy of the vi_visual_change() function and removed the part that deletes the selected code.

I changed the following line in slickedit/macros/videf.e:

Code: [Select]
//def 'I' = vi_visual_maybe_command;
def  'I'= vi_visual_insert;

After reloading these two macros, the visual insert works.

It would be nice if vi_visual_insert could be part of the standard slickedit distribution.


Raymond

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: VI mode: visual block insert
« Reply #1 on: August 22, 2008, 01:33:43 PM »
Sure, I think that'd be a good addition.  FYI, if you want to accomplish this now, without modifying any Slick-C, you can just invoke block_insert_mode after you have your visual block selection.  Certainly you won't be able to bind 'i' to block_insert_mode, but you could bind something else and use that.  Thanks for the feedback.

- Ryan

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: VI mode: visual block insert
« Reply #2 on: August 22, 2008, 01:34:20 PM »
Oh and now is a good time to mention any Vim commands that you are missing in our emulation, for inclusion in our next release...if there are others.

- Ryan

sunray

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: VI mode: visual block insert
« Reply #3 on: August 25, 2008, 09:46:25 AM »
I think the other commands I am missing can probably be solved by changing the key-bindings:

  • Redo command in VIM is <CTRL>-r.
  • Change entire word: ciw, can probably bound to: bcw. (ciw, changes the whole word, instead of the part from the cursor to the end.)

Another VIM issue is sometimes I have to press escape twice. This happens when the code completion dialog pops up or when
I type an if-statement. The if-statement creates this blue area where you can select what code block should be included in
the if. Escape once removes this area and brings me back to the insert mode, escape once again brings me to command mode.


Thanks a lot,

Raymond.

livingintown

  • Community Member
  • Posts: 51
  • Hero Points: 2
Re: VI mode: visual block insert
« Reply #4 on: August 25, 2008, 10:43:44 AM »
Regarding ESC twice, you can set this macro def_vim_esc_codehelp to 1. it will turn to cmd mode when ESC pressed from any place.

sunray

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: VI mode: visual block insert
« Reply #5 on: August 25, 2008, 12:19:31 PM »
Excellent! This solves the issue for the code completion dialog. Found also the def_vi_always_highlight_all macro, which makes me very happy :).

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: VI mode: visual block insert
« Reply #6 on: August 25, 2008, 01:46:26 PM »
Thanks for the feedback...def_vim_esc_codehelp should probably be extended to dynamic surround (the blue area), even though it was originally intended to only affect code help dialogs.  I think it makes sense.

- Ryan

Tim Keating

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: VI mode: visual block insert
« Reply #7 on: December 04, 2008, 09:32:03 PM »
(Resurrecting an old thread, rather than spinning up a new one.)

One VIM feature I'd love to see support for is incsearch. Basically, while you are typing the search, it advances the cursor to the next occurrance. If you cancel the search with ESC, it moves back to the previous cursor position.

TK

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: VI mode: visual block insert
« Reply #8 on: December 04, 2008, 09:49:02 PM »
The existing i-search does the incremental search thing, but it doesn't jump back to starting pos on Esc.


rdroaten

  • Community Member
  • Posts: 13
  • Hero Points: 0
Re: VI mode: visual block insert
« Reply #9 on: December 05, 2008, 02:45:32 PM »
Something I'd like to see in SE's vim emulation is smarter behavior of the "." (repeat) command after using completion. I want SE to repeat insertion of the results of the completion. That's what I intuitively expect it to do, not all of the cursor movement, etc. it took to display the completion popup. As a result, the current implementation usually inserts only part of what I would expect, and that somewhere below and to the right of the current cursor position.