keyword to upper/lower case

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

keyword to upper/lower case

Jeri Raye
Hi,

Is it possible to search for a keyword and change the case of it?
I'm using vim for VHDL.
VHDL is not case sensitive.
I'm using keywords always in lower case, my collegue in upper case.

To get to the same style I want to search my text for keywords and
change it to upper case.

As Vim already knows it's VHDL, is it then possible to do:
- search for keyword
- replace it with the itself but then in upper case.

so
- end becomes END
- entity becomes ENTITY
- Architecture becomes ARCHITECTURE
- std_LOGIC_vector becoms STD_LOGIC_VECTOR


Rgds,
Jeri

--
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
Reply | Threaded
Open this post in threaded view
|

Re: keyword to upper/lower case

Nikolay Aleksandrovich Pavlov
Reply to message ¬ękeyword to upper/lower case¬Ľ,
sent 11:36:08 17 October 2010, Sunday
by Jeri Raye:

> Is it possible to search for a keyword and change the case of it?
> I'm using vim for VHDL.
> VHDL is not case sensitive.
> I'm using keywords always in lower case, my collegue in upper case.
>
> To get to the same style I want to search my text for keywords and
> change it to upper case.
You can try the following (not tested for VHDL):
    " place the cursor on the VHDL keyword before using this function
    function VHDLUpcaseKeywords()
        let kwsynname=synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), "name")
        let [sl, el]=[1, line('$')]
        for line in range(sl, el)
            execute line
            for col in range(1, col('$'))
                if synIDattr(synIDtrans(synID(line, col, 1)), "name")==?kwsynname
                    execute 'normal! '.virtcol([line, col]).'|gUl'
                endif
            endfor
        endfor
    endfunction
Usage (when cursor is placed on any keyword):
    call VHDLUpcaseKeywords()
It relies on syntax being on and using the same syntax group for all VHDL keywords.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: keyword to upper/lower case

Christian Brabandt
In reply to this post by Jeri Raye
Hi Jeri!

On So, 17 Okt 2010, Jeri Raye wrote:

> Hi,
>
> Is it possible to search for a keyword and change the case of it?
> I'm using vim for VHDL.
> VHDL is not case sensitive.
> I'm using keywords always in lower case, my collegue in upper case.
>
> To get to the same style I want to search my text for keywords and  
> change it to upper case.
>
> As Vim already knows it's VHDL, is it then possible to do:
> - search for keyword
> - replace it with the itself but then in upper case.
>
> so
> - end becomes END
> - entity becomes ENTITY
> - Architecture becomes ARCHITECTURE
> - std_LOGIC_vector becoms STD_LOGIC_VECTOR

:%s/\S\+/\=synIDattr(synID(line('.'),
col('.'),0),"name")=~'vhdlStatement\|vhdlType\|vhdlOperator)'?
toupper(submatch(0)) : submatch(0)/g

(1 line)

I tested it only barely. If you find out, that certain other types are
not converted, you need to find out the syntax name for it. I did that
on some items using the following command, I defined long ago in my
.vimrc and which I find really useful, every now and then:

command! -nargs=0 WhatSyntax echomsg
  \synIDattr(synID(line("."),col("."+), 0), "name")

And then typing :WhatSyntax on an unknown Syntax item.

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|

Re: keyword to upper/lower case

Christian Brabandt
Hi vim!

On So, 17 Okt 2010, Christian Brabandt wrote:

>   \synIDattr(synID(line("."),col("."+), 0), "name")

Grml, I hate auto wrapping. That should have been

   \synIDattr(synID(line("."),col("."), 0), "name")

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|

Re: keyword to upper/lower case

David Fishburn-2
In reply to this post by Jeri Raye
On Sun, Oct 17, 2010 at 3:36 AM, Jeri Raye <[hidden email]> wrote:
...

> Is it possible to search for a keyword and change the case of it?
> I'm using vim for VHDL.
> VHDL is not case sensitive.
> I'm using keywords always in lower case, my collegue in upper case.
>
> To get to the same style I want to search my text for keywords and change it
> to upper case.
>
> As Vim already knows it's VHDL, is it then possible to do:
> - search for keyword
> - replace it with the itself but then in upper case.
>
> so
> - end becomes END
> - entity becomes ENTITY
> - Architecture becomes ARCHITECTURE
> - std_LOGIC_vector becoms STD_LOGIC_VECTOR


Sure, that is what the Search and Replace Highlight Group plugin I
wrote is for.  It's default search and replace string will do exactly
as you ask, uppercase the group you choose.

SrchRplcHiGrp.vim : Search and/or replace based on a syntax highlight group
http://www.vim.org/scripts/script.php?script_id=848

Basically, you would place your cursor on 'Architecture'.
:SRChooseHiGrp

This will display the group chosen.

Then visually select a region (it supports v, V and CTRL-V or
characterwise, linewise or block visual selections), then run:
:'<,'>SRHiGrp

Allows you to enter your regex and regex for replacement (again the
defaults do what you ask).

If some values are missed, then undo and run:
:SRChooseHiGrp!

Which gets the parent or ancestor group and run SRHiGrp over again.

HTH,
Dave

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