• Get the Flash Player to see the slideshow.
  • Categories

  • Authors

  • Great Quotes

    Everything should be as simple as possible, but not simpler. — Albert Einstein

Get in touch...

To have a chat about
your CMS needs...

Call us 0207 193 2014
or
Email us on

Archive for the ‘Vim’ Category

Remove Single Line HTML Comments using VIM

Friday, August 8th, 2008

If you want to remove all HTML style comments (ones that span a single line), use the following VIM commands :

Check for all single line HTML comments in VIM :-

:g/<!– .\{-}–>/p

Typing the above displays all lines that contain HTML style comments

To remove all the comments use the following VIM command :-

:%s/<!– .\{-}–>//g

 

VIM Functions and Menu Items for Writing XSL

Thursday, July 31st, 2008

Add the following lines to a myxsl.vim file and place it in your VIM plugins directory.

The next time you start VIM, you will have a menu called “lf” appear with the following items

listed that allow you to create more xsl code with less typing.

Note that you must also add the VIM utility functions listed in a previous blog article, found here:

http://www.littleforest.co.uk/vim-unix/vim-toolkit-functions/ 

amenu lf.xsl:template\ w\ name :call XslTemplateWithName()<CR><ESC>
amenu lf.xsl:call-template :call XslCallTemplate()<CR><ESC>
amenu lf.xsl:param :call XslParam()<CR><ESC>
amenu lf.xsl:with-param :call XslWithParam()<CR><ESC>
amenu lf.xsl:if :call XslIf()<CR><ESC>
amenu lf.xsl:choose :call XslChoose()<CR><ESC>
amenu lf.xsl:when :call XslWhen()<CR><ESC>
amenu lf.xsl:otherwise :call XslOtherwise()<CR><ESC>
amenu lf.xsl:variable :call XslVariable()<CR><ESC>
amenu lf.xsl:value-of :call XslValueOf()<CR><ESC>
amenu lf.xsl:text :call XslText()<CR><ESC>
amenu lf.xsl:for-each :call XslForEach()<CR><ESC>
amenu lf.xsl:sort :call XslSort()<CR><ESC>

func! XslTemplateWithName()
        let n=inputdialog(”Template Name”)
        call P(”<xsl:template name=\”" . n . “\”>”)
        call P(”</xsl:template>”)
        call Up()
endf

func! XslForEach()
        let n=inputdialog(”Select Expression”)
        call P(”<xsl:for-each select=\”" . n . “\”>”)
        call P(”</xsl:for-each>”)
        call Up()
endf

func! XslCallTemplate()
        let n=inputdialog(”Template Name”)
        call P(”<xsl:call-template name=\”" . n . “\”>”)
        call P(”</xsl:call-template>”)
        call Up()
endf

func! XslSort()
        let n=inputdialog(”Sort Select Expression”)
        call P(”<xsl:sort select=\”" . n . “\”/>”)
endf

func! XslParam()
        let n=inputdialog(”Param Name”)
        call P(”<xsl:param name=\”" . n . “\”/>”)
endf

func! XslWithParam()
        let n=inputdialog(”Param Name”)
        let v=inputdialog(”Param Value”)
        call P(”<xsl:with-param name=\”" . n . “\”>” . v . “</xsl:with-param>”)
endf

func! XslIf()
        let n=inputdialog(”Test Expression”)
        call P(”<xsl:if test=\”" . n . “\”>”)
        call P(”</xsl:if>”)
        call Up()
endf

func! XslChoose()
        call P(”<xsl:choose>”)
        call P(”</xsl:choose>”)
        call Up()
endf

func! XslAttribute()
        let n=inputdialog(”Attribute Name”)
        call P(”<xsl:attribute name=\”" . n . “\”>”)
        call P(”</xsl:attribute>”)
        call Up()
endf

func! XslText()
        call P(”<xsl:text></xsl:text>”)
endf

func! XslWhen()
        let n=inputdialog(”Test Expression”)
        call P(”<xsl:when test=\”" . n . “\”>”)
        call P(”</xsl:when>”)
        call Up()
endf

func! XslOtherwise()
        call P(”<xsl:otherwise>”)
        call P(”</xsl:otherwise>”)
        call Up()
endf

func! XslVariable()
        let n=inputdialog(”Variable Name”)
        let v=inputdialog(”Variable Value”)
        call P(”<xsl:variable name=\”" . n . “\”>” . v . “</xsl:variable>”)
        call Up()
endf

func! XslValueOf()
        let n=inputdialog(”Variable Name”)
        call P(”<xsl:value-of select=\”" . n . “\”/>”)
endf

 

VIM Toolkit Functions

Thursday, July 24th, 2008

General-purpose functions for building up more useful VIM scripts.

” Move the cursor up a line

func Up()
exe “normal k”
endf

” Move the cursor down a line
func Down()
exe “normal j”
endf

” Cut the selected buffer text to the windows clipboard
func! Cut()
exe “normal \”+x”
endf

” Copy the selected buffer text to the windows clipboard

func! Copy()
exe “normal \”+y”
endf

” Paste windows clipboard data to the current buffer

func! Paste()
exe “normal \”+gP”
endf

” Select all text in the editor’s current buffer
func! SelectAll()
exe “normal ggVG”
endf

” Wrapper function to write a string to the buffer

func! Print(str)
exe “normal o” . a:str . “”
endf

” Wrapper function to write a string to the buffer

func! P(str)
call Print(a:str)
endf

” Write a newline character to the buffer

func! NL()
call P(”")
endf
” Write a newline character to the buffer

func! CR()
call NL()
endf

Split Up XML or HTML Elements in VIM

Thursday, July 24th, 2008

If there are multiple HTML or XML tags on one line, use the following command to split that data over several lines instead & make it more readable :-

:%s/></>\r</g

Remove DOS EOL Chars in VIM

Thursday, July 24th, 2008

Use the following command :-

:%s/\r//g