Ignore character in strings #20

cassava opened this Issue Jan 17, 2013 · 3 comments


None yet
3 participants

cassava commented Jan 17, 2013

It would be nice if there was a way for Tabular to ignore the search character when it is found in a string. For example

insert into my_table (there, are, four, commas, here)
values ('but if', 1, 'of my strings has the array type:', '{1,2,3,4,5,6,7,8,9}', 'then everything is messed up');

Or am I missing something? I imagine that this is not trivial...


godlygeek commented Jan 28, 2013

You're not missing something - Tabular definitely doesn't have this feature. And you're right, it's not trivial. The guts of Tabular are all structured with the assumption that it's a text processing engine - so, at the lower levels, it by design knows nothing about your vim buffers, or the syntax highlighting in them. The low-level guts of Tabular are in tabular#TabularizeStrings(), which is exposed for plugins to use for general text alignment, and it makes no assumption that the text even exists in a buffer.

There might be a way to do this, but it's definitely not too easy...

eric-hu commented Feb 23, 2013

Cassava, one hacky way to do that would involve running your Tabular command wrapped in an escape/unescape script.

You can escape the commas in that particular sequence, to some uncommon string, say __;__. The following ex command sort of does that: %s/\('{[^']*\)\zs,/__;__/g. The problem with this is that it must be run multiple times.

Explanation of \('{[^']*\)\zs,
\( Begin an atom (that we'll later discard)
'{ Match brackets in quotes
[^']* ...followed by any number of non-quotes (to ignore commas after the string ends)
\) finish the atom
\zs, Make this match begin at the end of the previous atom, Match a comma

reversing this would be easier, as you'd just want to look for your escape sequence, which should be uncommon, so it'd look something like this %s/__;__/,/g. I know this is a clunky solution, but hopefully it'll help you or someone else get started

cassava commented Mar 6, 2013

Thanks eric-hu.

It would probably be easier to write another program to escape them and then run it using :'<,'>!mynewcommand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment