sponsor Vim development Vim logo Vim Book Ad

SyntaxMotion.vim : Cursor motion & visual selection by syntax highlighting group

 script karma  Rating 3/3, Downloaded by 713    Comments, bugs, improvements  Vim wiki

created by
Dominique Pellé
 
script type
utility
 
description
This plugin provides cursor motion by syntax highlighting groups in normal
and visual mode:

- type  \<right>  (actually <Leader><right>) to move the cursor forward to
  the end of the syntax group where cursor is located.

- type  \<left>  (actually <Leader><right>) to move the cursor forward to
  the beginning of the syntax group where cursor is located.

For example, when inside a string, pressing  \<right>  moves to the end of
the string.  When inside a comment, pressing  \<left>  moves to the
beginning of the comment.  You can extrapolate this behavior to any kind
of syntax group.

Repeating the motion multiple times will move to the next syntax
highlighting group (forward or backward). A repeat count number can also be
given before typing  \<left>  or  \<right>.  For example, typing  3\<left>
moves the cursor to the left by 3 syntax elements.

Strictly speaking, motion actually moves to the start or end of the text
which has the same "color" (rather than same "syntax group") as the color
of the text where cursor is originally located. So if your color scheme
defines the same colors for multiple syntax groups, motion may actually span
multiple consecutive syntax groups if they have the same colors.  Motion is
based on syntax highlighting colors rather than syntax highlighting groups
to make behavior more intuitive (what you see is what you get) since users
see colors on the screen but may not be aware of different syntax highlight
groups.

Plugin also provides a way to select the text visually around the position
of the cursor with the same syntax group as where cursor is located:

- type  va<right>  to visually select the text with the same syntax as
  where cursor is located, and move the cursor to the end of the selected
  text.

- type  va<left>  to visually select the text with the same syntax as
  where cursor is located, and move the cursor to the beginning of the
  selected text.

Syntax highlighting must be enabled for the plugin to work.

License: The VIM LICENSE applies to SyntaxMotion.vim (see ":help copyright"
except use "SyntaxMotion.vim" instead of "Vim").

ToDo:
- write a proper help page
- provide mapping in operator pending mode
 
install details
Drop SyntaxMotion.vim into your favorite plugin directory: ~/.vim/plugin/ on Unix, $HOME/vimfiles/plugin or $VIM/vimfiles/plugin on Windows).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
SyntaxMotion.vim 0.5 2010-02-12 7.0 Dominique Pellé Bug fix in Visual Selection when cursor was at beginning or end of syntax block
SyntaxMotion.vim 0.4 2010-02-11 7.0 Dominique Pellé Added mappings to perform visual selection of text which has same syntax as where cursor is located. Use  va<left>  and   va<right>
SyntaxMotion.vim 0.3 2010-02-07 7.0 Dominique Pellé now work with repeat count  (example: 3\<right>)
SyntaxMotion.vim 0.2 2010-02-07 7.0 Dominique Pellé now also works in visual mode
SyntaxMotion.vim 0.1 2010-02-07 7.0 Dominique Pellé Initial upload
ip used for rating: 54.81.75.69

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo