Wednesday, March 3, 2010

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

Hi KevM!

On Mi, 03 Mär 2010, KevM 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.

This sounds similar to a question that was posted recently on this list
with the subject "mass delete words based on spell"
http://groups.google.com/group/vim_use/browse_frm/thread/9bb6e3360a55d46a#

Since I don't know fortran, I can't directly help, the following should
get you working. I would try to reveal the syntax item for each non
Space and depending on whether the result is empty, you could do
something with your match or simply return it. This is a simple stub:

:%s/\S\+/\=empty(synIDattr(synID(line('.'), col('.'), 1),
"name"))?tolower(submatch(0)[0]).toupper(submatch(0)[1:]) :
submatch(0)/g

(this is one line) and does the following (I hope):
:%s/ " globally replace
\S\+ " search for non-whitespace
/ " and replace by
\= " evaluating the following function
empty(synIDattr(synID(line('.'), col('.'), 1)
" check whether the effective syntax item at the match position
" is empty
? " and if it is return
(tolower(submatch(0)[0].toupper(submatch(0)[1:])
" the match with the first letter lowercase and the rest of the
" match capitalized
: " else
submatch(0) " return the match
/g " and replace for each match in each line


regards,
Christian
--
Die wahre Vermittlerin ist die Kunst. Über Kunst sprechen heißt
die Vermittlerin vermitteln wollen, und doch ist uns daher viel
Köstliches erfolgt.
-- Goethe, Maximen und Reflektionen, Nr. 23

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