Wednesday, March 3, 2010

Re: Change case of text not identified by a syntax item?

On Mar 3, 12:59 pm, KevM <vekl...@gmail.com> wrote:
> I would like to change the case of all the text in a file that isn't
> identifed by any current syntax item.
>
> Text not identified by "syntax/fortran.vim" is for the most part
> variables, program unit names, etc..
>
> So this would simply allow me change the case of all my variable
> names.
>
> I've been racking my brain to figure out how this could be done to no
> avail.
>
> I could probably just write a perl script with some big hairy regex to
> accomplish this but vim syntax highlighting already does such a good
> job of identifying everything but variables it would be nice if I
> could make use of it.
>
> Any suggestions or nudges in the right direction would be appreciated.

You'd need to do a little bit of Vim scripting, but the "synstack" and
"synIDattr" functions are useful for this.

I have the following in one of my vim config files, I've never gotten
around to it because I don't use it very often:

" TODO: support something like the following in a simple function or
command:
" %s/foo/\=(match(map(synstack(line('.'),col('.')),
'synIDattr(v:val, "name")'), '\([Cc]omment\)\|\([sS]tring\)') >= 0 ?
"foo" : "bar")/g

It looks like this command would do a substitute, but only inside
comments and strings. Or only outside. One or the other :-)

--
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:

Post a Comment