sponsor Vim development Vim logo Vim Book Ad

SameSyntaxMotion : Motions to the borders of the same syntax highlighting.

 script karma  Rating 7/4, Downloaded by 360  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
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
same way.

- 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
                        individual keywords.
install details
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.
    vim SameSyntaxMotion*.vmb.gz
    :so %
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

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
SameSyntaxMotion-1.01.vmb.gz 1.01 2018-11-04 7.0 Ingo Karkat - CountJump 1.9 renames g:CountJump_Context to g:CountJump_TextObjectContext. *** You need to update to CountJump.vim (vimscript #3130) version 1.90! ***
SameSyntaxMotion-1.00.vmb.gz 1.00 2012-12-03 7.0 Ingo Karkat Initial upload
ip used for rating:

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.
OSDN.net Logo