<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cat brain.stuff &#62; wordpress &#187; selection</title>
	<atom:link href="http://famvdploeg.com/blog/tag/selection/feed/" rel="self" type="application/rss+xml" />
	<link>http://famvdploeg.com/blog</link>
	<description>A simple look on things</description>
	<lastBuildDate>Fri, 03 Feb 2012 15:09:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Visual Studio copy selection macro</title>
		<link>http://famvdploeg.com/blog/2010/04/visual-studio-copy-selection-macro/</link>
		<comments>http://famvdploeg.com/blog/2010/04/visual-studio-copy-selection-macro/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 09:54:35 +0000</pubDate>
		<dc:creator>Wytze</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[copy line]]></category>
		<category><![CDATA[copy selection]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[selection]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://famvdploeg.com/blog/?p=160</guid>
		<description><![CDATA[I use the copy line / copy selection under cursor in NetBeans a lot. So I created this macro for use in Visual Studio that provides this functionality. If no line is selected the current line where the cursor is placed will be copied. When a selection is made the selection will be copied and [...]]]></description>
			<content:encoded><![CDATA[<p>I use the copy line / copy selection under cursor in NetBeans a lot. So I created this macro for use in Visual Studio that provides this functionality. If no line is selected the current line where the cursor is placed will be copied.<br />
When a selection is made the selection will be copied and pasted below the selection. Afterwards the selection will be remade so you can repeat the action immediately.</p>
<p>Below is the VB snippet.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
&nbsp;
<span style="color: #E56717; font-weight: bold;">Public</span> Module Famvdploeg
    <span style="color: #008000;">' Copy the current line or selection
</span>    <span style="color: #E56717; font-weight: bold;">Sub</span> CopySelection()
        <span style="color: #151B8D; font-weight: bold;">Dim</span> selection <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> lines <span style="color: #151B8D; font-weight: bold;">As</span> Array
&nbsp;
        <span style="color: #008000;">' Select current line if nothing is selected
</span>        <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #F660AB; font-weight: bold;">String</span>.IsNullOrEmpty(DTE.ActiveDocument.Selection.Text) <span style="color: #8D38C9; font-weight: bold;">Then</span>
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.EndOfLine(<span style="color: #00C2FF; font-weight: bold;">True</span>)
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #008000;">' Store some variables
</span>        selection = DTE.ActiveDocument.Selection.Text
        lines = Split(selection, vbCrLf)
&nbsp;
        <span style="color: #008000;">' Perform the copy+paste action depending on how selection is made
</span>        <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #F660AB; font-weight: bold;">String</span>.IsNullOrEmpty(lines(lines.Length - 1)) <span style="color: #8D38C9; font-weight: bold;">Then</span>
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.EndOfLine(0)
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.Paste()
        <span style="color: #8D38C9; font-weight: bold;">Else</span>            
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.NewLine()
            <span style="color: #008000;">' Sanitize any auto text insertion
</span>            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.EndOfLine(<span style="color: #00C2FF; font-weight: bold;">True</span>)
            <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> <span style="color: #F660AB; font-weight: bold;">String</span>.IsNullOrEmpty(DTE.ActiveDocument.Selection.Text()) <span style="color: #8D38C9; font-weight: bold;">Then</span>
                DTE.ActiveDocument.Selection.Delete()
            <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.Paste()
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #8D38C9; font-weight: bold;">If</span> lines.Length &gt; 1 <span style="color: #8D38C9; font-weight: bold;">Then</span>
            <span style="color: #008000;">' ReSelect the text so we can repeat the action immediately
</span>            DTE.ActiveDocument.Selection.LineUp(<span style="color: #00C2FF; font-weight: bold;">False</span>, lines.Length - 1)
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.LineDown(<span style="color: #00C2FF; font-weight: bold;">True</span>, lines.Length - 1)
            <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> <span style="color: #F660AB; font-weight: bold;">String</span>.IsNullOrEmpty(lines(lines.Length - 1)) <span style="color: #8D38C9; font-weight: bold;">Then</span>
                DTE.ActiveDocument.Selection.EndOfLine(<span style="color: #00C2FF; font-weight: bold;">True</span>)
            <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
        <span style="color: #8D38C9; font-weight: bold;">Else</span>
            DTE.ActiveDocument.Selection.StartOfLine(0)
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> Module</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://famvdploeg.com/blog/2010/04/visual-studio-copy-selection-macro/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

