I'm happy to announce a new plugin: vim-textobj-quotes - text objects for the closest pairs of quotes of any type.
https://github.com/beloglazov/vim-textobj-quotes
Using only `iq` or `aq` it allows you to operate on the content of single ('), double ("), or back (`) quotes that currently surround the cursor, are in front of the cursor, or behind (in that order of preference). In other words, it jumps forward or backwards when needed to reach the quotes.
It's easier to understand by looking at examples (the cursor is shown with |):
1. Before: foo '1, |2, 3' bar; after pressing diq: foo '|' bar
2. Before: foo| '1, 2, 3' bar; after pressing diq: foo '|' bar
3. Before: foo '1, 2, 3' |bar; after pressing diq: foo '|' bar
4. Before: foo '1, |2, 3' bar; after pressing daq: foo | bar
5. Before: foo| '1, 2, 3' bar; after pressing daq: foo | bar
6. Before: foo '1, 2, 3' |bar; after pressing daq: foo | bar
The examples above are given for single quotes, the plugin works exactly the same way for double (") and back (`) quotes.
Please let me know if you find any bugs :)
Cheers,
Anton Beloglazov
Another difference is that this plugin supports multiple lines, for example:
Before:
some |text "this is
a multiline
string"
After diq:
some text "|"
And you are right, as in examples 3 and 6 it can jump back, which the built-in text objects don't support. Please let me know if you think there are other interesting use cases :)
Cheers,
Anton
What happens if the cursor is between two different quotes on the same line
'like' in| this example with a far away "quote"
Will it always jump to the double quote to the right or is there a cutoff point where the quote to the right is considered too far away?
In a case when both pairs of quotes are on the same line with the cursor, it will always jump forward regardless of the distance. However, if the front quotes are on the next line, it will jump back to the quotes on the same line. If both pairs of quotes are not on the same line with the cursor, it will jump forward to the quotes on the next line.
Cheers,
Anton
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/OfxZwm88uRI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.