Better caret movement by words

Macros for better word right/left caret movement within the IDE.

Currently the word right/left caret movement in the IDE moves alternately from beginning to ending of "words." Therefore it now takes more keystrokes to navigate through a line. These macros separate the beginning to beginning and end to end movement. Providing faster and more predictable movement.

There are 8 macros:

  1. NewWordRight Moves the caret to beginning of next word to the right
  2. NewWordRightExt As above with selection
  3. NewWordLeft Moves caret to beginning of next word to the left
  4. NewWordLeftExt As above with selection
  5. NewEndWordRight Moves the caret to the end of next word to the right
  6. NewEndWordRightExt As above with selection
  7. NewEndWordLeft Moves the caret to the end of next word to the Left
  8. NewEndWordLeftExt As above with selection

I have attached the NewWord macros to the ctrl/ctrl-shift arrow keys. The NewEndWord's I have attached to corresponding alt/alt-shift arrow keys.

Flaws: I have had occasion when the macro gets into an infinite loop when I press the arrow keys in a fast and "random" pattern. At which time its necessary to double click on the macro icon in the tray to terminate the macro. Other than this I have seen no other side effects.


Sub NewWordRight()
'DESCRIPTION: Does a real word right
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	if len(ActiveDocument.Selection) <> 0 then
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
	End if
	ActiveDocument.Selection.CharRight dsExtend
	while InStr ( VarLtr, ActiveDocument.Selection ) <> 0
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharRight dsExtend
	wend
	while InStr ( VarLtr, ActiveDocument.Selection ) = 0
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharRight dsExtend
	wend
	ActiveDocument.Selection.CharLeft
End Sub

Sub NewWordLeft()
'DESCRIPTION: Does a real word left
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	if len(ActiveDocument.Selection) <> 0 then
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
	End if
	ActiveDocument.Selection.CharLeft dsExtend
	while InStr ( VarLtr, ActiveDocument.Selection ) = 0
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharLeft dsExtend
	wend
	while InStr ( VarLtr, ActiveDocument.Selection ) <> 0
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharLeft dsExtend
	wend
	ActiveDocument.Selection.CharRight
End Sub

Sub NewWordRightExt()
'DESCRIPTION: Does a real word right extend select
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	dir = len(ActiveDocument.Selection)
	ActiveDocument.Selection.CharRight dsExtend
	if dir <> 0 then
		if len(ActiveDocument.Selection) > dir then dir = 1 else dir = 0
	else
		dir = 1
	End if
	if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	while InStr ( VarLtr, test ) <> 0
		ActiveDocument.Selection.CharRight dsExtend
		if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	wend
	while InStr ( VarLtr, test ) = 0
		ActiveDocument.Selection.CharRight dsExtend
		if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	wend
	if dir then ActiveDocument.Selection.CharLeft dsExtend
End Sub

Sub NewWordLeftExt()
'DESCRIPTION: Does a real word left extend select
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	dir = len(ActiveDocument.Selection)
	ActiveDocument.Selection.CharLeft dsExtend
	if dir <> 0 then
		if len(ActiveDocument.Selection) > dir then dir = 1 else dir = 0
	else
		dir = 1
	End if
	if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	while InStr ( VarLtr, test ) = 0
		ActiveDocument.Selection.CharLeft dsExtend
		if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	wend
	while InStr ( VarLtr, test ) <> 0
		ActiveDocument.Selection.CharLeft dsExtend
		if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	wend
	if dir then ActiveDocument.Selection.CharRight dsExtend
End Sub

Sub NewEndWordRight()
'DESCRIPTION: Does an end of word right
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	if len(ActiveDocument.Selection) <> 0 then
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
	End if
	ActiveDocument.Selection.CharRight dsExtend
	while InStr ( VarLtr, ActiveDocument.Selection ) = 0
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharRight dsExtend
	wend
	while InStr ( VarLtr, ActiveDocument.Selection ) <> 0
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharRight dsExtend
	wend
	ActiveDocument.Selection.CharLeft
End Sub

Sub NewEndWordLeft()
'DESCRIPTION: Does an end of word left
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	if len(ActiveDocument.Selection) <> 0 then
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharRight
	End if
	ActiveDocument.Selection.CharLeft dsExtend
	while InStr ( VarLtr, ActiveDocument.Selection ) <> 0
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharLeft dsExtend
	wend
	while InStr ( VarLtr, ActiveDocument.Selection ) = 0
		ActiveDocument.Selection.CharRight
		ActiveDocument.Selection.CharLeft
		ActiveDocument.Selection.CharLeft dsExtend
	wend
	ActiveDocument.Selection.CharRight
End Sub

Sub NewEndWordRightExt()
'DESCRIPTION: Does an end of word right extend select
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	dir = len(ActiveDocument.Selection)
	ActiveDocument.Selection.CharRight dsExtend
	if dir <> 0 then
		if len(ActiveDocument.Selection) > dir then dir = 1 else dir = 0
	else
		dir = 1
	End if
	if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	while InStr ( VarLtr, test ) = 0
		ActiveDocument.Selection.CharRight dsExtend
		if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	wend
	while InStr ( VarLtr, test ) <> 0
		ActiveDocument.Selection.CharRight dsExtend
		if dir then test = Right(ActiveDocument.Selection,1) else test = Left(ActiveDocument.Selection,1)
	wend
	if dir then ActiveDocument.Selection.CharLeft dsExtend
End Sub

Sub NewEndWordLeftExt()
'DESCRIPTION: Does an end of word left extend select
	VarLtr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

	dir = len(ActiveDocument.Selection)
	ActiveDocument.Selection.CharLeft dsExtend
	if dir <> 0 then
		if len(ActiveDocument.Selection) > dir then dir = 1 else dir = 0
	else
		dir = 1
	End if
	if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	while InStr ( VarLtr, test ) <> 0
		ActiveDocument.Selection.CharLeft dsExtend
		if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	wend
	while InStr ( VarLtr, test ) = 0
		ActiveDocument.Selection.CharLeft dsExtend
		if dir then test = Left(ActiveDocument.Selection,1) else test = Right(ActiveDocument.Selection,1)
	wend
	if dir then ActiveDocument.Selection.CharRight dsExtend
End Sub


Comments

  • MsDev was stuck at the End of file & Begin

    Posted by Legacy on 01/28/2002 12:00am

    Originally posted by: Wolfhawkfield

    when there was no more words,
    MsDev was stuck finding another word....
    i try to settle this problem....

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: January 7, 2015 The Flash Visionary Chat series of webinars brings together IT and business leaders as well as thought leading industry analysts to discuss how the flash revolution is eradicating inefficiency, unleashing innovation, and accelerating businesses. Join us for this episode where we are excited to host not only the 451 Research, who share their recent industry research, but also one of our top customers, who will share their perspective on the disruptive power of flash …

  • The 3rd Platform of computing, based around the four pillars of mobile computing, social media, big data and analytics, and cloud, is redefining what IT infrastructure needs to provide. Endpoint solutions must meet not only traditional data protection requirements, but also a new set of requirements driven by the explosion in mobile computing. This IDC white paper explores the customer challenges associated with safeguarding data residing on various endpoint devices, including laptops, tablets, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date