History
Article Edit this page Discussion

Using normal command in a script for searching

From Vim Tips Wiki

Jump to: navigation, search

Tip 316 Previous Next Created: August 19, 2002 Complexity: intermediate Author: David Brown Version: 6.0


There are a number of ways you can search for a pattern in a script. The search function is the typical way to search for a pattern. But, it has limited options. In particular, there are no options to control the position of the cursor after it matches the pattern.

Instead you can use :normal command. The secret is to add a <CR> (^M) on the end of the command. For example, to search for "pattern" and move the cursor to the end of the matching pattern issue the command:

:normal /pattern/e+1^M

where ^M is a real carriage return. It can be entered with <c-v><c-m>.

Another use is when you want to enter a bunch of normal commands together. For example, if you were looking to find a '{' to highlight and delete a C block. The '{' may not be on the same line so you can't use the "f" normal command.

:normal V/{/^M%d

A drawback to using the normal command is that if the pattern does not match then it is difficult to detect. Also, you can get in trouble with the wrapscan setting.

[edit] References

[edit] Comments

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Using normal command in a script for searching"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation