sponsor Vim development Vim logo Vim Book Ad

SelX : A Rainbow of Vim selection/highlighting & search

 script karma  Rating 5/5, Downloaded by 1120  Comments, bugs, improvements  Vim wiki

created by
Richard Bentley-Green
script type


SelX provides additional selection/highlighting/search functions that operate in a very similar way to the standard '*' (and similar) key mappings and the standard '/' (and similar) command line search operations; the difference is that multiple, multi-coloured highlights are supported, operating on a per-tab basis

The selection/highlight selections can also (optionally) be saved as part of a vim session. This is also supported by my SessX plugin - vimscript #5874

SelX is intended to complement rather then replace the standard vim selection/search highlight facility

NOTE: I really have no idea what the minimum vim version requirement is to run SelX and I don't know of a practical way of finding out (I've only used it on v8.2). The best I can suggest is to try it; it will probably work and if it doesn't then let me know and I'll see if I can sort it

*** If you have any suggestions for improving this, then please let me know. If you think it's rubbish then PLEASE let me know why - it's far more useful than just 'voting it down' (which really doesn't help at all). Contact details are in the top of the README file ***


In order to keep track of which selections/highlights are set, a Highlight Usage Map is automatically displayed on the in-focus window's status line. This Highlight Usage Map looks something like the following;-

  [ 1 | 2 | 3 |   |   | 6 |^  |   |   ]

The Map has an entry for each of the available SelX highlight colours (in reality, the map entries are appropriately coloured)

If a particular highlight is not set then it is shown with just its colour (for example, numbers 4 and 5)

If a particular highlight is set then it is shown with its number (for example, numbers 1, 2 and 3)

The '^' is always displayed and points to the next highlight that will be used when the auto-selection command is used

Markers are also placed (not shown in the above drawing - see the README) to show whether a selection/highlight is a whole word or arbitrary, and whether or not it is case-sensitive. The case-sensitivity can be set prior to the selection and both of these attributes can be toggled after a selection has been made


There are several mappings/commands for selecting/highlighting and searching for a specific selection which mirror the normal '*' (and other) mappings and command line '/' and '?' commands

There are also some optional mappings that enhance (depending on your point of view) the standard vim highlight/search operation
install details
Un-tar into ~/.vim/bundle/ as usual and read the README file for setup and config options

Note that there is some initial setup required to integrate this into your vim installation

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
selx.tar.gz 14/01/2023 2023-01-15 7.0 Richard Bentley-Green I discovered that defining the dummy version of selx#Statusline() - see change on 26/04/2020 above - actually has the effect of bringing-in and parsing the SelX autoload code! I think this is a bug in vim but is (apparently) expected behaviour. So I have now removed this dummy function and replaced it with the function g:SelxStatusline(). Using this wrapper function will ensure that the autoload code is not brought in/parsed unnecessarily. The README has been updated to reflect the change when using this for the vim buffer status bar
selx.tar.gz 02/08/2022 2022-08-15 7.0 Richard Bentley-Green - The search index (used by (`<M-n`/`<Leader>n` and `<M-N>`/`<Leader>N`) now operates per-tab (the auto-selection index has always done)
- The auto-selection index, and the search index are now transposed to a new tab opened with the `tt` mapping
- Added facility to (optionally) copy the auto-selection index and the search index between tabs (via the 'SelXPaseteAll` command)
- Added g:SelxPasteNextIdx and g:SelxPasteSearchIdx options to support (switching on/off) this functionality
- The usage map and output from the `SelXList` function now displays which highlight (if any) is the target of the search operations (`<M-n`/`<Leader>n` and `<M-N>`/`<Leader>N`)
- Added new command; `<M->>'/`<Leader>>` to set search to last defined highlight (per tab) - surprisingly useful!
- The auto-selection index, and the search index are now saved to the session (if the appropriate config is set up, of course)
- Added `g:SelxStripDecor` option to allow the output of some commands/mappings to produce cleaner output
- Some of the command line output showing the highlight colours did not include the highlight attributes. This has now been added
selx.tar.gz 02/05/2022 2022-05-03 7.0 Richard Bentley-Green - Added g:SelxDispMapNextCol option to allow further possibilities with configuring the highlight usage map
selx.tar.gz 29/04/2022 2022-04-30 7.0 Richard Bentley-Green - Expanded the maximum number of highlight colours from 9 to 99
- Added g:SelxExtKeyMap to support additional colours (> 10)
- Added g:SelxDispMapMarks option to allow small reduction in map size
selx.tar.gz 24/04/2022 2022-04-27 7.0 Richard Bentley-Green - Corrected a minor but annoying bug whereby if a 'normal' vim highlight was active (displayed) and a 'SelX' highlight was created in visual selection mode, the 'SelX' highlight would be created ok, but the original 'normal' highlight would get re-assigned to the same as the 'SelX' highlight. The correction means that the 'normal' highlight is left as-is now
- Improved the `<leader><leader>n` mapping so that it now visually selects the next located text. This makes repeated use of this mapping much more usable
- Corrected some comparisons which should be case-sensitive but may not be in some vim configurations
selx.tar.gz 15/06/21 2021-06-15 7.0 Richard Bentley-Green - Oops! Fixed incorrect command-line feedback/reporting of case toggle mapping
  '<Leader>cH' (the actual operation is/was correct)
selx.tar.gz 04/06/21 2021-06-04 7.0 Richard Bentley-Green - Added commands to copy and paste highlight config between tabs
- Improved feedback text on command line for some commands/mappings
selx.tar.gz 01/03/21 2021-03-02 7.0 Richard Bentley-Green - README/help text improvements
- Changed the characters displayed in the Unicode version of the 'whole word' and 'case-insensitive' markers to something a bit more subtle (smaller)
selx.tar.gz 27/02/21 2021-02-28 7.0 Richard Bentley-Green - Some minor improvements to this README and documentation
- Added support for case selection/toggling, inc new mappings toggling case-sensitivity, both default and per-selection - see the new mappings <Leader>C and <Leader>cH
- Highlight Selection Map now shows markers to indicate word/arbitrary selection and case-sensitivity for each highlight - see README for details
selx.tar.gz 24/11/20 2020-11-25 7.0 Richard Bentley-Green - Improved feedback for 'full word/arbitrary' selection toggle operation
- Added search success/failure feedback; printed to command line
- Minor comment corrections
selx.tar.gz 27/10/2020 2020-11-21 7.0 Richard Bentley-Green - Modified visual selection version of '*' so that it does not immediately jump to next occurrence; ie - works like the 'normal' version
- Modified list of suggested highlight colours
selx.tar.gz 01/05/20 2020-05-01 7.0 Richard Bentley-Green Added :SelXList command to print details of active selections/highlights
selx.tar.gz 27/04/20 2020-04-28 7.0 Richard Bentley-Green Added 'default' to setting StatusMsg colour. Without this, colour override would be hit-and-miss
Removed a stray mapping for '*' from autoload/selx.vim - oops!
selx.tar.gz 26/04/20 2020-04-27 7.0 Richard Bentley-Green Documentation improvements.
Minor functional changes - nothing serious, but worth having
See version information at bottom of README for full details
selx.tar.gz 25/04/20 2020-04-25 7.0 Richard Bentley-Green Documentation improvements. Improved control over mappings. Corrected one use of 'normal' to 'normal!'
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.