vCoolor - Simple color selector/picker for Vim (v1.2.3)
vCoolor is a Vim plugin that allows using a color picker/selector directly from the editor.
What this plugin do:
- Insert hex, rgb, rgba (With 1 in opacity) or hsl color anywhere.
- Modify hex color even if there are many colors in 1 line.
- Modify a rgb color with 0-255 values or % (Only one by line).
- Modify a rgba color but don't change the opacity (Only one by line).
- Modify a hsl color (Only one by line).
What this plugin doesn't do:
- Insert or modify hsla colors.
In windows it uses colorpicker-windows-commandline (The binary is included in the plugin).
In Mac OSX it uses a ruby script to trigger the system color picker.
And if you want, you can even use your own color picker.
Install the distributed files into Vim runtime directory which is usually
$HOME/vimfiles on Windows.
If you're using pathogen, extract the files into
Using a plugin manager
And this is the recommended way, use a vim plugin manager:
|Plugin manager||In vimrc||Installation command|
In both NORMAL and INSERT modes, only 1 shortcut is needed:
<Alt-C> (I find it very convenient
- To insert a color anywhere.
- To modify the current hex, rgb, rgba or hsl color.
<Alt-R>you can insert a rgb color anywhere (NORMAL and INSERT modes).
<Alt-V>you can insert a hsl color anywhere (NORMAL and INSERT modes).
<Alt-W>you can insert a rgba color anywhere (NORMAL and INSERT modes).
Click on the image for a short screencast of the v0.1.
You can execute vCoolor with:
:VCoolor :VCoolIns r " For rgb color insertion :VCoolIns h " For hsl color insertion :VCoolIns ra " For rgba color insertion
You can toggle between lower/upper case for the returned hex color with:
Also, I've used some color conversion commands for debug purpose but I finally decided to keep them in the plugin, they may be useful.
Here they are with exemples to understand how they work:
:Rgb2Hex "255, 0, 255" " Gives "#FF00FF" :Rgb2RgbPerc "255, 0, 255" " Gives "100%, 0%, 100%" :Rgb2Hsl "255, 0, 255" " Gives "300, 100%, 50%" :RgbPerc2Hex "100%, 0%, 100%" " Gives "#FF00FF" :RgbPerc2Rgb "100%, 0%, 100%" " Gives "255, 0, 255" :Hex2Lit "#FF00FF" " Gives "magenta" :Hex2Rgb "#FF00FF" " Gives "255, 0, 255" :Hex2RgbPerc "#FF00FF" " Gives "100%, 0%, 100%" :Hex2Hsl "#FF00FF" " Gives "300, 100%, 50%" :Hsl2Rgb "300, 100%, 50%" " Gives "255, 0, 255" :Hsl2Hex "300, 100%, 50%" " Gives "#FF00FF"
To change the mapping by default, add to your vimrc.
let g:vcoolor_map = '<NEW_MAPPING>' let g:vcool_ins_rgb_map = '<NEW_MAPPING>' " Insert rgb color. let g:vcool_ins_hsl_map = '<NEW_MAPPING>' " Insert hsl color. let g:vcool_ins_rgba_map = '<NEW_MAPPING>' " Insert rgba color.
Each mapping works in both
INSERT mode (You can disable all of them if you want).
Hex colors in lowercase
To get hex colors in lower case by default, add to your vimrc:
let g:vcoolor_lowercase = 1
To disable all default mappings and map only what you want:
let g:vcoolor_disable_mappings = 1
Any color picker who take/return a hexcolor in standard I/O can be defined as the one used in the plugin:
let g:vcoolor_custom_picker = 'path/to/picker --option '
As an example with zenity in GNU/Linux:
let g:vcoolor_custom_picker = 'zenity --title "custom" --color-selection --show-palette --color '
Please note that the hex color will be added in the end of the string above, so add a space if needed.
Example of configuration
let g:vcoolor_lowercase = 1 let g:vcoolor_disable_mappings = 1 let g:vcoolor_map = '<leader>g'
- A better regex patterns.
- Handle rgba colors.
- Handle hsla colors.
- Add possibility to modify 2 or more rgb colors in a line.
- Option to abbreviate colors.
To Yad's author.
To Bram Moolenaar for creating the best piece of software in the world :D
To Jonathan Warner alias jaxbot for his contribution.
To you if you're using vCoolor.