Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to edit XML or HTML with the xmledit plugin of Vim

1. Introduction

The Vim is a powerful text editor “it is a
DSL  for text manipulation”.

In this tutorial we will see how we can Edit Xml, HTML or in general any markup language, thanks to the xmledit  plugin from Vim.

2. Environment

The tutorial is written using the following environment:

  • Hardware: Portable MacBook Pro 17 ‘(2.8 GHz Intel i7, 8GB DDR3 SDRAM, 256GB Solid State Drive).
  • NVIDIA GeForce GT 330M with 512MB
  • Operating System: Mac OS X Snow Leopard 10.6.6
  • MacVim 7.3 (although it also works for the Vim that comes installed by default on the Mac, which is version 7.2)
  • xmledit 1.9.1

3. Installation

The latest version of Xmledit (the 1.9.1 at the time I write these lines) is designed to install with a vimball compatible with pathogen.

We’re going to assume that we have the Vim or the MacVim fresh out of the factory, so first of all we’re going to install the vimball and the pathogen.

3.1. Installation of vimball

Vimball  is a plugin that allows you to make compressed files with the vim. These compressed files are Vim packages that we can distribute.

To install it we downloaded the latest version of the web. It will be a .tar.gz file that we will copy inside~/.vim/

Now we unzip it with:

$ cd ~/.vim

$ tar -xzf vimball.tar.gz

$ rm vimball.tar.gz

With the last step what we are doing is to erase the tar.gz since once decompressed is not necessary.

3.2. Installation of pathogen

Pathogen  is a plugin that allows you to manipulate the path options. This will
allow us to have the plugins installed in their own directory, instead of having them all together in~/.vim/plugin

To install it we downloaded the latest version of the web. It will be a .vim file that we will copy inside~/.vim/autoload/

Now we add the following line in the file~/.vimrc (it is convenient that we add it at the beginning)

call pathogen#runtime_append_all_bundles()

3.3. Installation of xmledit

Xmledit is the plugin that gives  us a little life when we work with XML or HTML. It will allow us, for example, to jump from a label to its corresponding closing, that automatically writes us the closing label as soon as we write the opening one, and some more things that we will detail later.

To install it we downloaded the latest version of the web. It will be a .vba file that we will copy inside~/.vim/

Now we unzip it with:

$ cd ~/.vim

$ vim xmledit-1.9.1.vba(that is, we are editing the file with the vim)

:so %

:q (salimos del vim)

$ rm xmledit-1.9.1.vba

With the last step what we are doing is to erase the .vba since once decompressed is not necessary.

4. Functionality of xmledit

Now that we have it correctly installed we can start playing with it. The plugin is automatically activated as soon as we open an XML style file, and we have the following functionalities at our disposal:

  • %– in normal mode it allows us to jump between the of a label.
  • %or5– in normal or visual mode it allows us to jump between the opening
    tag and the closing tag.
  • >– In insert mode what it does is to write automatically the closing tag and leave the cursor between both to continue inserting text.
  • >>– in insert mode it does the same as> but it adds a line break, so that we have each the opening and closing label each on a line and
    we are inserting text on a line between both labels.
  • x– in visual mode what it does is to surround the text marked with a label. A dialogue will appear asking us the label we want to use, as well as its attributes.
  • d– In normal mode what it does is eliminate the labels that surround the marked text.

It also integrates with the Vim’s tag system.

5. Conclusions

The Vim is a powerful editor by itself, but we also have to remember that there are many plugins to increase their capabilities. In this tutorial we have seen a small plugin that can be very useful if we edit XML or HTML files.

And always remember that a good artisan knows the tools he handles. Do not settle for the tools as they come “from the factory”. Search, investigate, try, experiment how to get the most out of your tools and your
environment, so that your day-to-day work is more comfortable and you increase your productivity.

The post How to edit XML or HTML with the xmledit plugin of Vim appeared first on Target Veb.



This post first appeared on Targetveb, please read the originial post: here

Share the post

How to edit XML or HTML with the xmledit plugin of Vim

×

Subscribe to Targetveb

Get updates delivered right to your inbox!

Thank you for your subscription

×