SameSyntaxMotion : Motions to the borders of the same syntax highlighting.
| script karma
Downloaded by 1327
Comments, bugs, improvements
script versions (upload new version)
Vim offers many different powerful motions to position the cursor, but none
leverages the syntactic analysis of the built-in syntax highlighting.
This plugin provides mappings to jump to the borders and next [count]
occurrences of text highlighted in the same way as under the cursor. So when
you're in a large block of comments, a quick [y will take you to the
beginning of the comment. The ay and iy text objects will select the
surrounding text that belongs to the same syntax group, or is highlighted the
- The SyntaxMotion plugin (vimscript #2965) by Dominique Pellé provides very
similar motions for normal and visual mode, but no operator-pending and text
objects. It does not skip over contained sub-syntax items and uses same
color as the distinguishing property.
- textobj-syntax (vimscript #2716) provides similar ay and iy text objects,
but doesn't support a [count] to select multiple.
"Same syntax" in the context of the mappings and text objects means:
1. The same highlight group is used to highlight the text. Transparent syntax
groups are ignored, highlight links are followed. Depending on the
colorscheme, this usually means if it has the same color and attributes,
it's the same, though (especially in low-color terminals) multiple
highlight groups may have the same visual appearance, but are _not_
2. The same syntax group as under the cursor. When this group contains other
syntax groups (possibly with different highlighting), these are included.
So when you have escape sequences in a string ("foo\<CR>bar"), quoted words
in a comment (# a "foo" piece), or keywords in a docstring (@author Ernie),
the entire text is treated as one syntax area, even though there are
different-colored pieces inside.
3. Unhighlighted whitespace between the same syntax items is skipped. So when
there are multiple keywords in a row (FOO BAR BAZ), they are treated as one
area, even though the whitespace between them is not covered by the syntax.
]y Go to [count] next start of the same syntax.
]Y Go to [count] next end of the same syntax.
[y Go to [count] previous start of the same syntax.
[Y Go to [count] previous end of the same syntax.
The 'wrapscan' setting applies.
ay "a syntax" text object, select [count] same syntax
iy "inner syntax" text object, select [count] same syntax
areas within the same line. Whitespace around the
syntax area is not included. Unhighlighted whitespace
delimits same syntax items here, so this selects
The code is hosted in a Git repo at
You can use your favorite plugin manager, or "git clone" into a directory used
for Vim packages. Releases are on the "stable" branch, the latest unstable
development snapshot on "master".
This script is also packaged as a vimball. If you have the "gunzip"
decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise,
decompress the archive first, e.g. using WinZip. Inside Vim, install by
sourcing the vimball or via the :UseVimball command.
To uninstall, use the :RmVimball command.
- Requires Vim 7.0 or higher.
- Requires the CountJump plugin (vimscript #3130), version 1.90 or higher.
For a permanent configuration, put the following commands into your vimrc:
To change the default motion mappings, use:
let g:SameSyntaxMotion_BeginMapping = 'y'
let g:SameSyntaxMotion_EndMapping = 'Y'
To also change the [ / ] prefix to something else, follow the instructions for
To change the default text object mappings, use:
let g:SameSyntaxMotion_TextObjectMapping = 'y'
To also change the a prefix to something else, follow the instructions for
Click on the package to download.
ip used for rating: 22.214.171.124