Attached is a patch to add an 'autotextobject' setting which will treat undefined text-objects like quote text objects, using the provided character as bounds. For example, with this setting if a user enters "di," with the cursor between two commas, the text between the commas will be removed. This is very useful for editing lists. Similarly, if one is composing TeX being able to quickly operate on the area between dollar signs is useful. If one is editing snake_case_variables, being able to do a quick "ci_" is also nice. The key here is that it happens on-the-fly with all as-of-yet-undefined objects without requiring the user consider every possible character he/she would be interested in ahead of time.
Outside of documentation and adding the setting itself, the it is only a few additional lines of code. I've wanted this feature for a while; if there is anything else I should do to help get it upstreamed do let me know and I'll see what I can do. - Daniel Thau -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index d40d825..1f96efb 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -733,6 +733,13 @@ matching end tag. These are ignored. The text objects are tolerant about mistakes. Stray end tags are ignored. + +Automatic text-objects *auto-text-objects* + +If |'autotextobject'| is set and an undefined text-object is entered, the +character provided will be used as bounds and act like |v_i"| or |v_a"|. See +|'autotextobject'|. + ============================================================================== 7. Marks *mark-motions* *E20* *E78* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index a515900..26fa05d 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -734,6 +734,22 @@ A jump table for the options with a short description can be found at |Q_op|. released with Sun ONE Studio 4 Enterprise Edition. Note: When this option is on some plugins may not work. + *'autotextobject'* *'ato'* *'noautotextobject'* + *'noato'* +'autotextobject' 'ato' boolean (default off) + global + {not in Vi} + {only available when compiled with it, use + exists("+textobjects") to check} + When on, if an undefined text-object is entered the character is + treated as the bounds for a text-object. This text-object will act + like |v_i"| or |v_a"| except with the provided character instead of a + quote. For example, "," is not defined as a text-object. If the user + enters "di," with this setting, the area between "," characters will + be deleted. + Note: New text-objects may be added in future versions of Vim which + will take precedence over text-objects provided with this setting. + *'arabic'* *'arab'* *'noarabic'* *'noarab'* 'arabic' 'arab' boolean (default off) local to window diff --git a/runtime/doc/tags b/runtime/doc/tags index 73475a9..1cfdc2f 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -53,11 +53,13 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME* 'ari' options.txt /*'ari'* 'arshape' options.txt /*'arshape'* 'as' todo.txt /*'as'* +'ato' options.txt /*'ato'* 'autochdir' options.txt /*'autochdir'* 'autoindent' options.txt /*'autoindent'* 'autoprint' vi_diff.txt /*'autoprint'* 'autoread' options.txt /*'autoread'* 'autosave' todo.txt /*'autosave'* +'autotextobject' options.txt /*'autotextobject'* 'autowrite' options.txt /*'autowrite'* 'autowriteall' options.txt /*'autowriteall'* 'aw' options.txt /*'aw'* @@ -2300,6 +2302,8 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME* :keepj motion.txt /*:keepj* :keepjumps motion.txt /*:keepjumps* :keepmarks motion.txt /*:keepmarks* +:keepp cmdline.txt /*:keepp* +:keeppatterns cmdline.txt /*:keeppatterns* :l various.txt /*:l* :lN quickfix.txt /*:lN* :lNext quickfix.txt /*:lNext* @@ -7791,6 +7795,7 @@ spell-affix-flags spell.txt /*spell-affix-flags* spell-affix-mbyte spell.txt /*spell-affix-mbyte* spell-affix-not-supported spell.txt /*spell-affix-not-supported* spell-affix-vim spell.txt /*spell-affix-vim* +spell-cjk spell.txt /*spell-cjk* spell-compound spell.txt /*spell-compound* spell-dic-format spell.txt /*spell-dic-format* spell-double-scoring spell.txt /*spell-double-scoring* diff --git a/src/normal.c b/src/normal.c index 9349be2..51a8df2 100644 --- a/src/normal.c +++ b/src/normal.c @@ -9315,7 +9315,14 @@ nv_object(cap) case 'u': /* "au" = a URL */ #endif default: - flag = FAIL; + /* if 'autotextobject' is set, and none of the above + * text-objects were utilized, try to treat cap->nchar like a + * quote */ + if (p_ato) + flag = current_quote(cap->oap, cap->count1, + include, cap->nchar); + else + flag = FAIL; break; } diff --git a/src/option.c b/src/option.c index 4e087a5..e2eeea2 100644 --- a/src/option.c +++ b/src/option.c @@ -555,6 +555,11 @@ static struct vimoption {"autoread", "ar", P_BOOL|P_VI_DEF, (char_u *)&p_ar, PV_AR, {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, +#ifdef FEAT_TEXTOBJ + {"autotextobject","ato",P_BOOL|P_VI_DEF, + (char_u *)&p_ato, PV_NONE, + {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, +#endif {"autowrite", "aw", P_BOOL|P_VI_DEF, (char_u *)&p_aw, PV_NONE, {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, diff --git a/src/option.h b/src/option.h index 737cbca..e43ae0c 100644 --- a/src/option.h +++ b/src/option.h @@ -320,6 +320,9 @@ EXTERN char_u *p_ambw; /* 'ambiwidth' */ EXTERN int *p_antialias; /* 'antialias' */ #endif EXTERN int p_ar; /* 'autoread' */ +#ifdef FEAT_TEXTOBJ +EXTERN int p_ato; /* 'autotextobject' */ +#endif EXTERN int p_aw; /* 'autowrite' */ EXTERN int p_awa; /* 'autowriteall' */ EXTERN char_u *p_bs; /* 'backspace' */