Tuesday, September 14, 2010

Re: Finding Text In Specific Columns

On 09/14/10 17:36, Stephen Rasku wrote:
> Is there a way in vim to search for text in specific columns? I want
> to find all instances where every 8th column (i.e 8, 16, 32, etc.) is
> not '0'. Is this possible?

Short answer: yes.

Longer answer: the "how" depends on whether they're delimited
columns (such as a comma-delimited or tab-delimited file) or if
they're just raw character-count-from-beginning-of-line. The
latter is the simple case, where you can use the \%8c atom
(there's a similar \%v for virtual columns, which take tabs into
consideration)

:help /\%c
:help /\%v

So you can do your search something like

/\%8c0

(I might have a fenceposting error there, but you can adjust the
"8" for whichever column you want)


For the more complex case of a simple tab/comma delimited file
(not with quotable delimiters), you can do something like

/^\%([^\t]*\t\)\{7}0\t " tab delim
/^\%([^,]*,\)\{7}0, " comma delim

For quotable-delimiters such as

col1,"col2,col2,col2",col3, ...

it's a bit more complex. Doable, but more complex (if this is
your case, let me know and I'll expound).

-tim


--
You received this message from the "vim_use" 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

No comments: