Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for other delimiter? #7

Open
caneff opened this issue Dec 5, 2013 · 5 comments
Open

Allow for other delimiter? #7

caneff opened this issue Dec 5, 2013 · 5 comments

Comments

@caneff
Copy link

caneff commented Dec 5, 2013

Maybe this is too much to do, but for instance, in R the style guide I follow dictates that multi word variables be written as

multi.word.var

I would love to be able to add '.' to the list of delimiters so that this works. Currently doing dav when the cursor is on m' just deletes the whole word. I'd like it to leave word.var instead

@Julian
Copy link
Owner

Julian commented Dec 5, 2013

This is a great suggestion.

The delimiter variables should probably be globals (or some other variable should exist), which would allow adding new ones.

Suggestions welcome, otherwise I'll try to think of a nice interface to expose this as.

@caneff
Copy link
Author

caneff commented Dec 5, 2013

That sounds perfectly reasonable. A global flag with "_" as the only default, and then you could add to them in the vimrc. This also allows for people to turn off _ as a delimiter if they wanted to.

@killphi
Copy link

killphi commented Dec 5, 2013

👍

@Julian
Copy link
Owner

Julian commented Dec 12, 2013

I think I'd like a method to do this, since it involves touching two parts – a left delimiter and a right delimiter, and theoretically those could be different.

E.g. textobj#variable_segment#add_delimiter(".") for two-sided and another arg for left and right.

I'd do this now, I just forget when for left delimiter for e.g. _ (i.e. snake case), you need a \i to not grab the _ on both sides. So I have to think that through a bit.

Patches welcome if anyone has some clarity.

@raine
Copy link

raine commented Jul 3, 2018

Is there an easy way to add support for -, even if it was just in my local copy? Thanks.

Update:

This patch adds support for -:

diff --git i/autoload/textobj/variable_segment.vim w/autoload/textobj/variable_segment.vim
index 5c2995f..ff0ea00 100644
--- i/autoload/textobj/variable_segment.vim
+++ w/autoload/textobj/variable_segment.vim
@@ -1,5 +1,5 @@
 function! s:select(object_type, right_boundary)
-    let left_boundaries = ['_\+\i', '\<', '\l\u', '\u\u\ze\l', '\a\d', '\d\a']
+    let left_boundaries = ['-\+\i', '_\+\i', '\<', '\l\u', '\u\u\ze\l', '\a\d', '\d\a']
     call search(join(left_boundaries, '\|'), 'bce')
     let start_position = getpos('.')
 
@@ -19,7 +19,7 @@ function! s:select(object_type, right_boundary)
 endfunction
 
 function! s:select_a()
-    let right_boundaries = ['_', '\l\u', '\u\u\l', '\a\d', '\d\a', '\i\>']
+    let right_boundaries = ['-', '_', '\l\u', '\u\u\l', '\a\d', '\d\a', '\i\>']
     let right_boundary = join(right_boundaries, '\|')
     let [type, start_position, end_position] = s:select('a', right_boundary)
     let [_, start_line, start_column, _] = start_position
@@ -46,7 +46,7 @@ function! s:select_a()
 endfunction
 
 function! s:select_i()
-    let right_boundaries = ['\i_', '\l\u', '\u\u\l', '\a\d', '\d\a', '\i\>']
+    let right_boundaries = ['\i-', '\i_', '\l\u', '\u\u\l', '\a\d', '\d\a', '\i\>']
     return s:select('i', join(right_boundaries, '\|'))
 endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants