Dumping webforms views

Want to switch from using the Webforms ViewEngine to the Razor ViewEngine?
Got a lot of Webforms views? I know they can be used side by side, but if you feel like converting and are comfortable with vi then these substitutions can help you along your way

Replace <% if and <% foreach (or anything but <% { really) with @if and @foreach
:%s/<% \([^}]\)/@\1

Replace any <%= followed by a space with @
:%s/<%= /@

Same as above but omit the space
:%s/<%=/@

Get rid of any remaining <%
:%s/<%//

Get rid of any %>
:%s/%>//

This won’t be perfect, but will get you close with very little effort.

Update:
Add this to your .vimrc file and do it with one command

 

function! DumpWebforms()
  %s/<% \([^}]\)/@\1
  %s/<%= /@
  %s/<%=/@
  %s/<%//
  %s/%>//
endfunction
Then invoke using :call DumpWebForms()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s