5 changed files with 953 additions and 0 deletions
@ -0,0 +1,414 @@
@@ -0,0 +1,414 @@
|
||||
" Color conversion functions. |
||||
|
||||
" Creation : 2015-04-04 |
||||
" Modification : 2015-04-04 |
||||
" Maintainer : Kabbaj Amine <amine.kabb@gmail.com> |
||||
" License : This file is placed in the public domain. |
||||
|
||||
fun! vcoolor#convert#HtmlBaseColName() " {{{1 |
||||
" Return a dictionnary of the 140 html base colors |
||||
" http://www.w3schools.com/tags/ref_colornames.asp |
||||
|
||||
return { |
||||
\ 'aliceblue': '#F0F8FF', |
||||
\ 'antiquewhite': '#FAEBD7', |
||||
\ 'aqua': '#00FFFF', |
||||
\ 'aquamarine': '#7FFFD4', |
||||
\ 'azure': '#F0FFFF', |
||||
\ 'beige': '#F5F5DC', |
||||
\ 'bisque': '#FFE4C4', |
||||
\ 'black': '#000000', |
||||
\ 'blanchedalmond': '#FFEBCD', |
||||
\ 'blue': '#0000FF', |
||||
\ 'blueviolet': '#8A2BE2', |
||||
\ 'brown': '#A52A2A', |
||||
\ 'burlywood': '#DEB887', |
||||
\ 'cadetblue': '#5F9EA0', |
||||
\ 'chartreuse': '#7FFF00', |
||||
\ 'chocolate': '#D2691E', |
||||
\ 'coral': '#FF7F50', |
||||
\ 'cornflowerblue': '#6495ED', |
||||
\ 'cornsilk': '#FFF8DC', |
||||
\ 'crimson': '#DC143C', |
||||
\ 'cyan': '#00FFFF', |
||||
\ 'darkblue': '#00008B', |
||||
\ 'darkcyan': '#008B8B', |
||||
\ 'darkgoldenrod': '#B8860B', |
||||
\ 'darkgray': '#A9A9A9', |
||||
\ 'darkgreen': '#006400', |
||||
\ 'darkkhaki': '#BDB76B', |
||||
\ 'darkmagenta': '#8B008B', |
||||
\ 'darkolivegreen': '#556B2F', |
||||
\ 'darkorange': '#FF8C00', |
||||
\ 'darkorchid': '#9932CC', |
||||
\ 'darkred': '#8B0000', |
||||
\ 'darksalmon': '#E9967A', |
||||
\ 'darkseagreen': '#8FBC8F', |
||||
\ 'darkslateblue': '#483D8B', |
||||
\ 'darkslategray': '#2F4F4F', |
||||
\ 'darkturquoise': '#00CED1', |
||||
\ 'darkviolet': '#9400D3', |
||||
\ 'deeppink': '#FF1493', |
||||
\ 'deepskyblue': '#00BFFF', |
||||
\ 'dimgray': '#696969', |
||||
\ 'dodgerblue': '#1E90FF', |
||||
\ 'firebrick': '#B22222', |
||||
\ 'floralwhite': '#FFFAF0', |
||||
\ 'forestgreen': '#228B22', |
||||
\ 'fuchsia': '#FF00FF', |
||||
\ 'gainsboro': '#DCDCDC', |
||||
\ 'ghostwhite': '#F8F8FF', |
||||
\ 'gold': '#FFD700', |
||||
\ 'goldenrod': '#DAA520', |
||||
\ 'gray': '#808080', |
||||
\ 'green': '#008000', |
||||
\ 'greenyellow': '#ADFF2F', |
||||
\ 'honeydew': '#F0FFF0', |
||||
\ 'hotpink': '#FF69B4', |
||||
\ 'indianred': '#CD5C5C', |
||||
\ 'indigo': '#4B0082', |
||||
\ 'ivory': '#FFFFF0', |
||||
\ 'khaki': '#F0E68C', |
||||
\ 'lavender': '#E6E6FA', |
||||
\ 'lavenderblush': '#FFF0F5', |
||||
\ 'lawngreen': '#7CFC00', |
||||
\ 'lemonchiffon': '#FFFACD', |
||||
\ 'lightblue': '#ADD8E6', |
||||
\ 'lightcoral': '#F08080', |
||||
\ 'lightcyan': '#E0FFFF', |
||||
\ 'lightgoldenrodyellow': '#FAFAD2', |
||||
\ 'lightgray': '#D3D3D3', |
||||
\ 'lightgreen': '#90EE90', |
||||
\ 'lightpink': '#FFB6C1', |
||||
\ 'lightsalmon': '#FFA07A', |
||||
\ 'lightseagreen': '#20B2AA', |
||||
\ 'lightskyblue': '#87CEFA', |
||||
\ 'lightslategray': '#778899', |
||||
\ 'lightsteelblue': '#B0C4DE', |
||||
\ 'lightyellow': '#FFFFE0', |
||||
\ 'lime': '#00FF00', |
||||
\ 'limegreen': '#32CD32', |
||||
\ 'linen': '#FAF0E6', |
||||
\ 'magenta': '#FF00FF', |
||||
\ 'maroon': '#800000', |
||||
\ 'mediumaquamarine': '#66CDAA', |
||||
\ 'mediumblue': '#0000CD', |
||||
\ 'mediumorchid': '#BA55D3', |
||||
\ 'mediumpurple': '#9370DB', |
||||
\ 'mediumseagreen': '#3CB371', |
||||
\ 'mediumslateblue': '#7B68EE', |
||||
\ 'mediumspringgreen': '#00FA9A', |
||||
\ 'mediumturquoise': '#48D1CC', |
||||
\ 'mediumvioletred': '#C71585', |
||||
\ 'midnightblue': '#191970', |
||||
\ 'mintcream': '#F5FFFA', |
||||
\ 'mistyrose': '#FFE4E1', |
||||
\ 'moccasin': '#FFE4B5', |
||||
\ 'navajowhite': '#FFDEAD', |
||||
\ 'navy': '#000080', |
||||
\ 'oldlace': '#FDF5E6', |
||||
\ 'olive': '#808000', |
||||
\ 'olivedrab': '#6B8E23', |
||||
\ 'orange': '#FFA500', |
||||
\ 'orangered': '#FF4500', |
||||
\ 'orchid': '#DA70D6', |
||||
\ 'palegoldenrod': '#EEE8AA', |
||||
\ 'palegreen': '#98FB98', |
||||
\ 'paleturquoise': '#AFEEEE', |
||||
\ 'palevioletred': '#DB7093', |
||||
\ 'papayawhip': '#FFEFD5', |
||||
\ 'peachpuff': '#FFDAB9', |
||||
\ 'peru': '#CD853F', |
||||
\ 'pink': '#FFC0CB', |
||||
\ 'plum': '#DDA0DD', |
||||
\ 'powderblue': '#B0E0E6', |
||||
\ 'purple': '#800080', |
||||
\ 'red': '#FF0000', |
||||
\ 'rosybrown': '#BC8F8F', |
||||
\ 'royalblue': '#4169E1', |
||||
\ 'saddlebrown': '#8B4513', |
||||
\ 'salmon': '#FA8072', |
||||
\ 'sandybrown': '#F4A460', |
||||
\ 'seagreen': '#2E8B57', |
||||
\ 'seashell': '#FFF5EE', |
||||
\ 'sienna': '#A0522D', |
||||
\ 'silver': '#C0C0C0', |
||||
\ 'skyblue': '#87CEEB', |
||||
\ 'slateblue': '#6A5ACD', |
||||
\ 'slategray': '#708090', |
||||
\ 'snow': '#FFFAFA', |
||||
\ 'springgreen': '#00FF7F', |
||||
\ 'steelblue': '#4682B4', |
||||
\ 'tan': '#D2B48C', |
||||
\ 'teal': '#008080', |
||||
\ 'thistle': '#D8BFD8', |
||||
\ 'tomato': '#FF6347', |
||||
\ 'turquoise': '#40E0D0', |
||||
\ 'violet': '#EE82EE', |
||||
\ 'wheat': '#F5DEB3', |
||||
\ 'white': '#FFFFFF', |
||||
\ 'whitesmoke': '#F5F5F5', |
||||
\ 'yellow': '#FFFF00', |
||||
\ 'yellowgreen': '#9ACD32' |
||||
\ } |
||||
endfun |
||||
" }}} |
||||
fun! vcoolor#convert#Rgb2Hex(rgbCol) " {{{1 |
||||
" Convert from rgb to hex: |
||||
" 255, 0, 255 => #FF00FF |
||||
|
||||
let l:rgbCol = substitute(a:rgbCol, " ", "", "g") " Remove spaces. |
||||
let l:rgbColL = split(l:rgbCol, ",") |
||||
|
||||
let l:color = "" |
||||
for l:element in copy(l:rgbColL) |
||||
let l:hexElem = printf('%02X', l:element) |
||||
let l:color = l:color.l:hexElem |
||||
endfor |
||||
|
||||
return "#".l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Rgb2RgbPerc(rgbCol) " {{{1 |
||||
" Convert from rgb to rgb (%): |
||||
" 255, 0, 255 => 100%, 0%, 100% |
||||
|
||||
let l:rgbCol = substitute(a:rgbCol, " ", "", "g") |
||||
let l:rgbColL = split(l:rgbCol, ",") |
||||
|
||||
let l:color = "" |
||||
for l:element in copy(l:rgbColL) |
||||
let l:rgbElem= (l:element * 100) / 255 |
||||
if len(l:color) == 0 |
||||
let l:color = l:rgbElem."%" |
||||
else |
||||
let l:color = l:color.", ".l:rgbElem."%" |
||||
endif |
||||
endfor |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#RgbPerc2Hex(rgbPercCol) " {{{1 |
||||
" Convert from rgb (%) to hex: |
||||
" 100%, 0%, 100% => #FF00FF |
||||
|
||||
let l:rgbCol = vcoolor#convert#RgbPerc2Rgb(a:rgbPercCol) |
||||
let l:color = vcoolor#convert#Rgb2Hex(l:rgbCol) |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#RgbPerc2Rgb(rgbPercCol) " {{{1 |
||||
" Convert from rgb (%) to rgb: |
||||
" 100%, 0%, 0% => 255, 0, 0 |
||||
|
||||
let l:rgbPercCol = substitute(a:rgbPercCol, " ", "", "g") |
||||
let l:rgbPercCol = substitute(l:rgbPercCol, "%", "", "g") " Remove %. |
||||
let l:rgbPercColL = split(l:rgbPercCol, ",") |
||||
|
||||
let l:color = "" |
||||
for l:element in copy(l:rgbPercColL) |
||||
let l:elementF = str2float(l:element) |
||||
let l:rgbElem = round(l:elementF * 2.55) |
||||
let l:rgbElem = float2nr(l:rgbElem) |
||||
if len(l:color) == 0 |
||||
let l:color = l:rgbElem |
||||
else |
||||
let l:color = l:color.", ".l:rgbElem |
||||
endif |
||||
endfor |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hex2Lit(hexCol) " {{{1 |
||||
" Convert from hex to literal name. |
||||
" #FF0000 => red |
||||
|
||||
let l:htmlBaseColors = vcoolor#convert#HtmlBaseColName() |
||||
let l:colIndex = index(values(l:htmlBaseColors), toupper(a:hexCol)) |
||||
|
||||
if l:colIndex != -1 |
||||
let s:color =get(keys(l:htmlBaseColors), l:colIndex) |
||||
else |
||||
let s:color = a:hexCol |
||||
endif |
||||
|
||||
return s:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hex2Rgb(hexCol) " {{{1 |
||||
" Convert from hex to rgb: |
||||
" #FF00FF => 255, 0, 255 |
||||
|
||||
let l:hexColL = matchlist(a:hexCol, '#\([0-9A-F]\{1,2}\)\([0-9A-F]\{1,2}\)\([0-9A-F]\{1,2}\)') |
||||
" Remove 1st and empty values. |
||||
call remove(l:hexColL, 0) |
||||
call remove(l:hexColL, 3, -1) |
||||
|
||||
let l:color = "" |
||||
for l:element in l:hexColL |
||||
let l:rgbElem = str2nr(l:element, 16) |
||||
let l:rgbElem = string(l:rgbElem) |
||||
if !empty(l:color) |
||||
let l:color = l:color.", ".l:rgbElem |
||||
else |
||||
let l:color = l:rgbElem |
||||
endif |
||||
endfor |
||||
|
||||
return l:color |
||||
endfun |
||||
fun! vcoolor#convert#Hex2RgbPerc(hexCol) " {{{1 |
||||
" Convert from hex to rgb (%): |
||||
" #FF00FF => 100%, 0, 100% |
||||
|
||||
let l:rgbCol = vcoolor#convert#Hex2Rgb(a:hexCol) |
||||
let l:color = vcoolor#convert#Rgb2RgbPerc(l:rgbCol) |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Rgb2Hsl(rgbCol) " {{{1 |
||||
" Convert from rgb to hsl: |
||||
" 255, 0, 255 => 300, 100%, 50% |
||||
" Algorithm from http://www.easyrgb.com/index.php?X=MATH&H=18#text18 |
||||
|
||||
let l:rgbCol = substitute(a:rgbCol, " ", "", "g") " Remove spaces. |
||||
let l:rgbColL = split(l:rgbCol, ",") |
||||
|
||||
let l:r = l:rgbColL[0] / 255.0 |
||||
let l:g = l:rgbColL[1] / 255.0 |
||||
let l:b = l:rgbColL[2] / 255.0 |
||||
|
||||
let l:min = vsl#type#list#GetMinVal([l:r,l:g,l:b]) |
||||
let l:max = vsl#type#list#GetMaxVal([l:r,l:g,l:b]) |
||||
let l:delta = l:max - l:min |
||||
|
||||
let l:l = (l:max + l:min) / 2.0 |
||||
|
||||
if (l:delta == 0) |
||||
" Achromatic. |
||||
let l:h = 0 |
||||
let l:s = 0 |
||||
else |
||||
if (l:l < 0.5) |
||||
let l:s = l:delta / (l:max + l:min) |
||||
else |
||||
let l:s = l:delta / (2 - l:max - l:min) |
||||
endif |
||||
|
||||
let l:deltaR = ( ( ( l:max - l:r ) / 6.0 ) + ( l:delta / 2.0 ) ) / l:delta |
||||
let l:deltaG = ( ( ( l:max - l:g ) / 6.0 ) + ( l:delta / 2.0 ) ) / l:delta |
||||
let l:deltaB = ( ( ( l:max - l:b ) / 6.0 ) + ( l:delta / 2.0 ) ) / l:delta |
||||
|
||||
if (l:r == l:max) |
||||
let l:h = l:deltaB - l:deltaG |
||||
elseif (l:g == l:max) |
||||
let l:h = (1/3.0) + l:deltaR - l:deltaB |
||||
elseif (l:b == l:max) |
||||
let l:h = (2/3.0) + l:deltaG - l:deltaR |
||||
endif |
||||
|
||||
if (l:h < 0) |
||||
let l:h = l:h + 1 |
||||
endif |
||||
if (l:h > 1) |
||||
let l:h = l:h - 1 |
||||
endif |
||||
endif |
||||
|
||||
let l:h = float2nr(abs(round(l:h * 360))) |
||||
let l:s = float2nr(abs(round(l:s * 100))) |
||||
let l:l = float2nr(abs(round(l:l * 100))) |
||||
|
||||
let l:color = l:h.", ".l:s."%, ".l:l."%" |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hsl2Rgb(hslCol) " {{{1 |
||||
" Convert from hsl to rgb: |
||||
" 300, 100%, 50% => 255, 0, 255 |
||||
" Algorithm from http://www.easyrgb.com/index.php?X=MATH&H=18#text18 |
||||
|
||||
let l:hslColL = matchlist(a:hslCol, '\([ ]*[0-9]\{1,3}[ ]*\),\([ ]*[0-9]\{1,3}%[ ]*\),\([ ]*[0-9]\{1,3}%[ ]*\)') |
||||
call remove(l:hslColL, 0) |
||||
call remove(l:hslColL, 3, -1) |
||||
|
||||
let l:h = str2float(l:hslColL[0]) / 360 |
||||
let l:s = str2float(l:hslColL[1]) / 100 |
||||
let l:l = str2float(l:hslColL[2]) / 100 |
||||
|
||||
if (l:s == 0) |
||||
let l:r2 = l:l * 256.0 |
||||
let l:g2 = l:l * 255.0 |
||||
let l:b2 = l:l * 255.0 |
||||
else |
||||
if (l:l < 0.5) |
||||
let l:varTp2 = l:l * (1 + l:s) |
||||
else |
||||
let l:varTp2 = (l:l + l:s) - (l:s * l:l) |
||||
endif |
||||
|
||||
let l:varTp1 = 2 * l:l - l:varTp2 |
||||
|
||||
let l:r2 = float2nr(round(255 * vcoolor#convert#Hue2Rgb(l:varTp1, l:varTp2, (l:h + (1/3.0))))) |
||||
let l:g2 = float2nr(round(255 * vcoolor#convert#Hue2Rgb(l:varTp1, l:varTp2, l:h))) |
||||
let l:b2 = float2nr(round(255 * vcoolor#convert#Hue2Rgb(l:varTp1, l:varTp2, (l:h - (1/3.0))))) |
||||
endif |
||||
|
||||
let l:color = string(l:r2) . ", " . string(l:g2) . ", " . string(l:b2) |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hue2Rgb(v1, v2, vH) " {{{1 |
||||
|
||||
let l:v1 = a:v1 |
||||
let l:v2 = a:v2 |
||||
let l:vH = a:vH |
||||
|
||||
if (l:vH < 0) |
||||
let l:vH = l:vH + 1 |
||||
endif |
||||
if (l:vH > 1) |
||||
let l:vH = l:vH - 1 |
||||
endif |
||||
if ((6.0 * l:vH) < 1) |
||||
return (l:v1 + (l:v2 - l:v1) * 6.0 * l:vH) |
||||
endif |
||||
if ((2.0 * l:vH) < 1) |
||||
return (l:v2) |
||||
endif |
||||
if ((3.0 * l:vH) < 2) |
||||
return (l:v1 + (l:v2 - l:v1) * ((2 / 3.0) - l:vH) * 6.0) |
||||
endif |
||||
|
||||
return l:v1 |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hsl2Hex(hslCol) " {{{1 |
||||
" Convert from hsl to hex: |
||||
" 300, 100%, 50% => #FF00FF |
||||
|
||||
let l:rgbCol = vcoolor#convert#Hsl2Rgb(a:hslCol) |
||||
let l:color = vcoolor#convert#Rgb2Hex(l:rgbCol) |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
fun! vcoolor#convert#Hex2Hsl(hexCol) " {{{1 |
||||
" Convert from hex to hsl: |
||||
" #FF00FF => 300, 100%, 50% |
||||
|
||||
let l:rgbCol = vcoolor#convert#Hex2Rgb(a:hexCol) |
||||
let l:color = vcoolor#convert#Rgb2Hsl(l:rgbCol) |
||||
|
||||
return l:color |
||||
|
||||
endfun |
||||
" }}} |
||||
|
||||
" vim:ft=vim:fdm=marker:fmr={{{,}}}: |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
" Miscellaneous functions. |
||||
|
||||
" Creation : 2015-04-04 |
||||
" Modification : 2015-04-04 |
||||
" Maintainer : Kabbaj Amine <amine.kabb@gmail.com> |
||||
" License : This file is placed in the public domain. |
||||
|
||||
function vcoolor#misc#GetMinVal(list) " {{{1 |
||||
" Return the minimum value of a list. |
||||
|
||||
let l:min = a:list[0] |
||||
if l:min > a:list[1] |
||||
let l:min = a:list[1] |
||||
endif |
||||
if l:min > a:list[2] |
||||
let l:min = a:list[2] |
||||
endif |
||||
|
||||
return l:min |
||||
|
||||
endfunction |
||||
function vcoolor#misc#GetMaxVal(list) " {{{1 |
||||
" Return the maximum value of a list. |
||||
|
||||
let l:max = a:list[0] |
||||
if l:max < a:list[1] |
||||
let l:max = a:list[1] |
||||
endif |
||||
if l:max < a:list[2] |
||||
let l:max = a:list[2] |
||||
endif |
||||
|
||||
return l:max |
||||
|
||||
endfunction |
||||
" }}} |
||||
|
||||
" vim:ft=vim:fdm=marker:fmr={{{,}}}: |
@ -0,0 +1,202 @@
@@ -0,0 +1,202 @@
|
||||
*vCoolor* Simple color selector/picker plugin. |
||||
|
||||
For Vim version 7.0 and above Last change: 2015-04-05 |
||||
|
||||
VCOOLOR - USE COLOR SELECTOR/PICKER FROM VIM~ |
||||
from Kabbaj Amine~ |
||||
|
||||
Mail : amine.kabb@gmail.com |
||||
Repo : https://github.com/KabbAmine/vCoolor.vim |
||||
License : This file is placed in the public domain. |
||||
|
||||
======================================================================== |
||||
|CONTENTS| *vcoolor-contents* |
||||
|
||||
1. DESCRIPTION |vcoolor-description| |
||||
2. INSTALLATION |vcoolor-installation| |
||||
2.1. Manual |vcoolor-installation:manual| |
||||
2.2. With Pathogen |vcoolor-installation:pathogen| |
||||
2.3. With a vim plugin manager |vcoolor-installation:vimplug| |
||||
3. USAGE |vcoolor-usage| |
||||
4. COMMANDS |vcoolor-command| |
||||
4.1. Main commands. |vcoolor-command:main| |
||||
4.2. Conversion commands. |vcoolor-command:conversion| |
||||
4.3. Various commands. |vcoolor-command:various| |
||||
5. MAPPING |vcoolor-mapping| |
||||
5.1. Default mapping. |vcoolor-mapping:default| |
||||
5.2. Custom mapping |vcoolor-mapping:custom| |
||||
6. CUSTOMIZATION |vcoolor-custom| |
||||
6.1. g:vcoolor_lowercase |vcoolor-custom:lowercase| |
||||
6.2. g:vcoolor_disable_mappings |vcoolor-custom:disable-maps| |
||||
7. NOTES |vcoolor-notes| |
||||
|
||||
======================================================================== |
||||
1. |DESCRIPTION| *vcoolor-description* |
||||
|
||||
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 GNU/Linux it uses a simple GTK+ dialog. |
||||
In windows it uses colorpicker-windows-commandline (https://github.com/jaxbot/colorpicker-windows-commandline) (The binary is included in the plugin). |
||||
In Mac OSX it uses a ruby script (https://github.com/KabbAmine/vCoolor.vim/tree/master/osx/color-picker) to trigger the system color trigger. |
||||
|
||||
======================================================================== |
||||
2. |INSTALLATION| |
||||
*vcoolor-installation* |
||||
|
||||
To use vCoolor in GNU/Linux, you need to have Zenity (Included in most distributions) or Yad (http://sourceforge.net/projects/yad-dialog/) (If you compile it manually, do it with GTK2 to avoid problem). |
||||
|
||||
------------------------------------------------------------------------ |
||||
2.1. Manual installation~ |
||||
*vcoolor-installation:manual* |
||||
|
||||
Install the distributed files into Vim runtime directory which is usually `~/.vim/`, or `$HOME/vimfiles` on Windows. |
||||
|
||||
------------------------------------------------------------------------ |
||||
2.2. Using Pathogen~ |
||||
*vcoolor-installation:pathogen* |
||||
|
||||
If you're using pathogen, extract the files into `bundle` directory. |
||||
|
||||
------------------------------------------------------------------------ |
||||
2.3. Using a vim plugin manager~ |
||||
*vcoolor-installation:vimplug* |
||||
|
||||
The best way to get the last version is to use a vim plugin manager (Vim-plug, Vundle, NeoBundle...). |
||||
|
||||
Add `KabbAmine/vCoolor.vim` to your plugins part in your vimrc then install it. |
||||
|
||||
======================================================================== |
||||
3. |USAGE| *vcoolor-usage* |
||||
|
||||
In both NORMAL and INSERT modes, only 1 shortcut is needed: `<Alt-C>` (I find it very convenient :D), but he may be not working on terminal. |
||||
|
||||
Use it: |
||||
* To insert a color anywhere. |
||||
* To modify the current hex, rgb, rgba or hsl color. |
||||
|
||||
And using: |
||||
* `<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). |
||||
|
||||
======================================================================== |
||||
4. |COMMANDS| *vcoolor-command* |
||||
|
||||
------------------------------------------------------------------------ |
||||
4.1. Main commands~ |
||||
*vcoolor-command:main* |
||||
|
||||
You can execute vCoolor with: > |
||||
:VCoolor |
||||
:VCoolIns r " Insert rgb color. |
||||
:VCoolIns h " Insert hsl color. |
||||
|
||||
------------------------------------------------------------------------ |
||||
4.2. Conversion commands~ |
||||
*vcoolor-command:conversion* |
||||
|
||||
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" |
||||
|
||||
------------------------------------------------------------------------ |
||||
4.3. Various commands~ |
||||
*vcoolor-command:various* |
||||
|
||||
You can toggle between lower/upper case for the returned hex color with: > |
||||
:VCase |
||||
|
||||
======================================================================== |
||||
5. |MAPPING| *vcoolor-mapping* |
||||
|
||||
------------------------------------------------------------------------ |
||||
5.1. Default mappings~ |
||||
*vcoolor-mapping:default* |
||||
|
||||
<A-c> |
||||
Execute the color picker and insert or modify the color (NORMAL and INSERT modes). |
||||
|
||||
<A-r> |
||||
Execute the color picker and insert rgb color (NORMAL and |
||||
INSERT modes). |
||||
|
||||
<A-v> |
||||
Execute the color picker and insert hsl color (NORMAL and |
||||
INSERT modes). |
||||
|
||||
<A-w> |
||||
Execute the color picker and insert rgba color with opacity 1 (NORMAL and INSERT modes). |
||||
|
||||
------------------------------------------------------------------------ |
||||
5.2. Custom mappings~ |
||||
*vcoolor-mapping:custom* |
||||
|
||||
To change the mapping by default: > |
||||
let g:vcoolor_map = '<NEW_MAPPING>' |
||||
|
||||
For rgb color insertion: > |
||||
let g:vcool_ins_rgb_map = '<NEW_MAPPING>' |
||||
|
||||
For hsl color insertion: > |
||||
let g:vcool_ins_hsl_map = '<NEW_MAPPING>' |
||||
|
||||
For rgba color insertion: > |
||||
let g:vcool_ins_rgba_map = '<NEW_MAPPING>' |
||||
|
||||
Each mapping works in both `NORMAL` and `INSERT` mode. |
||||
|
||||
======================================================================== |
||||
6. CUSTOMIZATION| *vcoolor-custom* |
||||
|
||||
------------------------------------------------------------------------ |
||||
6.1. g:vcoolor_lowercase~ |
||||
*vcoolor-custom:lowercase* |
||||
|
||||
To get hex colors in lower case, you can add to your vimrc: > |
||||
let g:vcoolor_lowercase = 1 |
||||
> |
||||
------------------------------------------------------------------------ |
||||
6.2. g:vcoolor_disable_mappings~ |
||||
*vcoolor-custom:disable-maps* |
||||
|
||||
To disable all default mappings and map only what you want: > |
||||
let g:vcoolor_disable_mappings = 1 |
||||
> |
||||
======================================================================== |
||||
7. |NOTES| |
||||
*vcoolor-notes* |
||||
|
||||
Thanks to Yad's author. |
||||
|
||||
Thanks to Bram Moolenaar for creating the best piece of software in the world :D |
||||
|
||||
To Jonathan Warner alias [jaxbot](https://github.com/jaxbot) for his contribution. |
||||
|
||||
Thanks to you if you're using vCoolor. |
||||
|
||||
======================================================================== |
||||
vim:tw=78:ts=8:ft=help:norl:noet |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/ruby |
||||
|
||||
color = ARGV[0] |
||||
if color == "" |
||||
color = "#FFAABB" |
||||
end |
||||
|
||||
red = color[1..2].to_i(16) * 257 |
||||
green = color[3..4].to_i(16) * 257 |
||||
blue = color[5..6].to_i(16) * 257 |
||||
|
||||
red = red.to_s |
||||
green = green.to_s |
||||
blue = blue.to_s |
||||
|
||||
out = IO.popen [ |
||||
'osascript', |
||||
'-e', 'property my_color : {' + red + ',' + green + ',' + blue + '}', |
||||
'-e', 'tell application "MacVim.app"', |
||||
'-e', ' activate', |
||||
'-e',%| set Applescript's text item delimiters to {"\n"}|, |
||||
'-e', ' try', |
||||
'-e', ' set col to (choose color default color my_color) as text', |
||||
'-e', ' on error number -128 --', |
||||
'-e', ' set col to my_color as text', |
||||
'-e', ' end try', |
||||
'-e', 'end tell', |
||||
] |
||||
|
||||
print ?#, *out.read.lines.map { |color| '%02x' % (color.to_i / 256) } |
||||
|
||||
# Credit: http://www.reddit.com/r/vim/comments/2crzey/finallly_we_have_a_color_picker_in_vim/cjiiga2 |
@ -0,0 +1,267 @@
@@ -0,0 +1,267 @@
|
||||
" Simple color selector/picker plugin. |
||||
" Version: 1.2.1 |
||||
|
||||
" Creation : 2014-07-26 |
||||
" Modification : 2015-04-12 |
||||
" Maintainer : Kabbaj Amine <amine.kabb@gmail.com> |
||||
" License : This file is placed in the public domain. |
||||
|
||||
|
||||
" Vim options {{{1 |
||||
if exists("g:vcoolor_loaded") |
||||
finish |
||||
endif |
||||
let g:vcoolor_loaded = 1 |
||||
|
||||
" To avoid conflict problems. |
||||
let s:saveCpoptions = &cpoptions |
||||
set cpoptions&vim |
||||
" }}} |
||||
|
||||
|
||||
" COMMANDS |
||||
" ===================================================================== |
||||
|
||||
" Main commands {{{1 |
||||
command! VCoolor call s:VCoolor() |
||||
command! -nargs=1 VCoolIns call s:VCoolIns(<f-args>) |
||||
command! VCase call s:SetCase() |
||||
" }}} |
||||
" For debug purpose. {{{1 |
||||
" if exists(":GetColor") != 2 |
||||
" command! GetColor :echo s:GetCurrCol() |
||||
" endif |
||||
" }}} |
||||
" Conversion commands. {{{1 |
||||
let s:commandNames = [ |
||||
\ "Rgb2Hex", "Rgb2RgbPerc", "Rgb2Hsl", |
||||
\ "RgbPerc2Hex", "RgbPerc2Rgb", |
||||
\ "Hex2Lit", "Hex2Rgb", "Hex2RgbPerc", "Hex2Hsl", |
||||
\ "Hsl2Rgb", "Hsl2Hex" |
||||
\ ] |
||||
for s:cn in s:commandNames |
||||
if exists(":".s:cn."") != 2 |
||||
execute "command! -nargs=1 ".s:cn." :echo vcoolor#convert#".s:cn."(<args>)" |
||||
endif |
||||
endfor |
||||
" }}} |
||||
|
||||
" MAPPINGS |
||||
" ===================================================================== |
||||
|
||||
" {{{1 |
||||
let s:vcoolorMap = exists('g:vcoolor_map') ? g:vcoolor_map : '<A-c>' |
||||
let s:vcoolInsRMap = exists('g:vcool_ins_rgb_map') ? g:vcool_ins_rgb_map : '<A-r>' |
||||
let s:vcoolInsHMap = exists('g:vcool_ins_hsl_map') ? g:vcool_ins_hsl_map : '<A-v>' |
||||
let s:vcoolInsRaMap = exists('g:vcool_ins_rgba_map') ? g:vcool_ins_rgba_map : '<A-w>' |
||||
|
||||
if !exists('g:vcoolor_disable_mappings') || exists('g:vcoolor_map') |
||||
execute "nmap <silent> ".s:vcoolorMap." :VCoolor<CR>" |
||||
execute "imap <silent> ".s:vcoolorMap." <Esc>:VCoolor<CR>a" |
||||
endif |
||||
|
||||
if !exists('g:vcoolor_disable_mappings') || exists('g:vcool_ins_rgb_map') |
||||
execute "nmap <silent> ".s:vcoolInsRMap." :VCoolIns r<CR>" |
||||
execute "imap <silent> ".s:vcoolInsRMap." <Esc>:VCoolIns r<CR>a" |
||||
endif |
||||
|
||||
if !exists('g:vcoolor_disable_mappings') || exists('g:vcool_ins_hsl_map') |
||||
execute "nmap <silent> ".s:vcoolInsHMap." :silent VCoolIns h<CR>" |
||||
execute "imap <silent> ".s:vcoolInsHMap." <Esc>:VCoolIns h<CR>a" |
||||
endif |
||||
|
||||
if !exists('g:vcoolor_disable_mappings') || exists('g:vcool_ins_rgba_map') |
||||
execute "nmap <silent> ".s:vcoolInsRaMap." :silent VCoolIns ra<CR>" |
||||
execute "imap <silent> ".s:vcoolInsRaMap." <Esc>:VCoolIns ra<CR>a" |
||||
endif |
||||
" }}} |
||||
|
||||
" VARIABLES |
||||
" ===================================================================== |
||||
|
||||
" Set new color in lowercase if the global variable is set to 1. " {{{1 |
||||
if !exists("g:vcoolor_lowercase") |
||||
let g:vcoolor_lowercase = 0 |
||||
endif |
||||
" }}} |
||||
" 140 html base colors. {{{1 |
||||
let s:colorNames = vcoolor#convert#HtmlBaseColName() |
||||
" }}} |
||||
" Keep track of current working directory of script {{{1 |
||||
let s:path = expand('<sfile>:p:h') |
||||
" }}} |
||||
|
||||
" FUNCTIONS |
||||
" ===================================================================== |
||||
|
||||
" Processing functions |
||||
" ************************ |
||||
function s:GetCurrCol() " {{{1 |
||||
" Get current color and return a list: |
||||
" [ |
||||
" currentColorName, |
||||
" currentHexColor, |
||||
" typeColor (l: literal, n:none, h:hex, r:rgb, rp:rgb(%), rgba:rgba, hs:hsl) |
||||
" ] |
||||
|
||||
let l:cWord = expand("<cWORD>") |
||||
let l:cword = expand("<cword>") |
||||
let l:getLine = getline(".") |
||||
|
||||
let l:regexHex = '^.*\(#[a-fA-F0-9]\{3,6}\).*$' |
||||
let l:regexRgb = '^.*\<rgb\>(\(\([ ]*[0-9]\{1,3}[ ]*,\)\{2}[ ]*[0-9]\{1,3}[ ]*\)).*$' |
||||
let l:regexRgba = '^.*\<rgba\>(\(\([ ]*[0-9]\{1,3}[ ]*,\)\{3}\)[ ]*\([01]\{1}\.\?[0-9]\?\)).*$' |
||||
let l:regexRgbPerc = '^.*\<rgb\>(\(\([ ]*[0-9]\{1,3}%[ ]*,\)\{2}[ ]*[0-9]\{1,3}%[ ]*\)).*$' |
||||
let l:regexHsl = '^.*\<hsl\>(\(\([ ]*[0-9]\{1,3}%\?[ ]*,\)\{2}[ ]*[0-9]\{1,3}%[ ]*\)).*$' |
||||
|
||||
let s:currColor = ["", "", ""] |
||||
" Nothing or special character under cursor fix. |
||||
if match(l:cWord, '[(, ]\+') == 0 |
||||
let s:currColor = ["","","n"] |
||||
elseif has_key(s:colorNames, tolower(l:cword)) |
||||
let s:currColor = [l:cword, s:colorNames[l:cword], "l"] |
||||
elseif match(l:getLine, l:regexRgb) != -1 |
||||
let s:currColor[0] = substitute(l:getLine, l:regexRgb, '\1', '') |
||||
let s:currColor[1] = vcoolor#convert#Rgb2Hex(s:currColor[0]) |
||||
let s:currColor[2] = "r" |
||||
elseif match(l:getLine, l:regexRgba) != -1 |
||||
let s:currColor[0] = substitute(l:getLine, l:regexRgba, '\1', '') |
||||
let s:currColor[1] = vcoolor#convert#Rgb2Hex(s:currColor[0]) |
||||
let s:currColor[2] = "rgba" |
||||
elseif match(l:getLine, l:regexRgbPerc) != -1 |
||||
let s:currColor[0] = substitute(l:getLine, l:regexRgbPerc, '\1', '') |
||||
let s:currColor[1] = vcoolor#convert#RgbPerc2Hex(s:currColor[0]) |
||||
let s:currColor[2] = "rp" |
||||
elseif match(l:getLine, l:regexHsl) != -1 |
||||
let s:currColor[0] = substitute(l:getLine, l:regexHsl, '\1', '') |
||||
let s:currColor[1] = vcoolor#convert#Hsl2Hex(s:currColor[0]) |
||||
let s:currColor[2] = "hs" |
||||
elseif match(l:cWord, l:regexHex) != -1 |
||||
let s:currColor[0] = substitute(l:cWord, l:regexHex, '\1', '') |
||||
let s:currColor[1] = s:currColor[0] |
||||
let s:currColor[2] = "h" |
||||
else |
||||
let s:currColor = ["","","n"] |
||||
endif |
||||
|
||||
let s:currColor[1] = toupper(s:currColor[1]) |
||||
|
||||
return s:currColor |
||||
|
||||
endfunction |
||||
function s:SetColorByType(oldColor, newCol) " {{{1 |
||||
" Set the correct color depending of the old color |
||||
" type (hex, rgb, literal, none ...). |
||||
|
||||
let l:oldCol = a:oldColor[0] |
||||
let l:newCol = strpart(a:newCol, 0, 7) " To remove the ******* annoying ^@. |
||||
|
||||
if a:oldColor[2] == 'r' |
||||
let l:newCol = vcoolor#convert#Hex2Rgb(l:newCol) |
||||
execute "silent: s/".l:oldCol."/".l:newCol |
||||
elseif a:oldColor[2] == 'rgba' |
||||
let l:newCol = vcoolor#convert#Hex2Rgb(l:newCol) |
||||
execute "silent: s/".l:oldCol."/".l:newCol."," |
||||
elseif a:oldColor[2] == 'rp' |
||||
let l:newCol = vcoolor#convert#Hex2RgbPerc(l:newCol) |
||||
execute "silent: s/".l:oldCol."/".l:newCol |
||||
elseif a:oldColor[2] == 'hs' |
||||
let l:newCol = vcoolor#convert#Hex2Hsl(l:newCol) |
||||
execute "silent: s/".l:oldCol."/".l:newCol |
||||
elseif a:oldColor[2] == 'l' |
||||
let l:newCol = vcoolor#convert#Hex2Lit(l:newCol) |
||||
execute "silent: s/".l:oldCol."/".l:newCol |
||||
elseif a:oldColor[2] == 'n' |
||||
if expand("<cword>") == '#' |
||||
:normal x |
||||
endif |
||||
execute ":normal a".l:newCol |
||||
let s:position = getpos(".") |
||||
else |
||||
let l:newCol = strpart(l:newCol, 0, 7) |
||||
execute "silent: .s/".l:oldCol."/".l:newCol |
||||
endif |
||||
|
||||
endfunction |
||||
function s:ExecPicker(hexColor) " {{{1 |
||||
" Execute the appropriate command for the color picker and |
||||
" return the new hexadecimal color. |
||||
|
||||
if has("win32") |
||||
let l:comm = s:path . "/../pickers/win32/cpicker.exe ".a:hexColor |
||||
elseif has("mac") |
||||
let l:comm = s:path . "/../pickers/osx/color-picker \"".a:hexColor."\"" |
||||
else |
||||
if executable("yad") |
||||
let l:comm = "yad --title=\"vCoolor\" --color --init-color=\"".a:hexColor."\" --on-top --skip-taskbar --center 2> /dev/null" |
||||
else |
||||
let l:comm = "zenity --title=\"vCoolor\" --color-selection --color=\"".a:hexColor."\" 2> /dev/null" |
||||
endif |
||||
endif |
||||
|
||||
let s:newCol = system(l:comm) |
||||
if strlen(s:newCol) >= 13 |
||||
let s:newCol = s:newCol[0:2].s:newCol[5:6].s:newCol[9:10] |
||||
endif |
||||
|
||||
let s:newCol = g:vcoolor_lowercase == 1 ? tolower(s:newCol) : toupper(s:newCol) |
||||
|
||||
return s:newCol |
||||
|
||||
endfunction |
||||
function s:SetCase() " {{{1 |
||||
" Set returned hex color case. |
||||
|
||||
if g:vcoolor_lowercase == 0 |
||||
let g:vcoolor_lowercase = 1 |
||||
echo "Hex color in lowercase" |
||||
else |
||||
let g:vcoolor_lowercase = 0 |
||||
echo "Hex color in uppercase" |
||||
endif |
||||
endfunction |
||||
" }}} |
||||
|
||||
" Main functions |
||||
" ************************ |
||||
function s:VCoolor() " {{{1 |
||||
|
||||
let s:position = getpos(".") |
||||
|
||||
let l:oldCol = s:GetCurrCol() |
||||
let l:newCol = s:ExecPicker(l:oldCol[1]) |
||||
|
||||
if !empty(l:oldCol) && !empty(l:newCol) |
||||
call s:SetColorByType(l:oldCol, l:newCol) |
||||
endif |
||||
|
||||
call setpos(".", s:position) |
||||
|
||||
endfunction |
||||
function s:VCoolIns(type) " {{{1 |
||||
" Insert color of type: |
||||
" - r: rgb mode. |
||||
" - h: hsl mode. |
||||
" - ra: rgba mode. |
||||
|
||||
let l:newCol = s:ExecPicker("") |
||||
if !empty(l:newCol) |
||||
if a:type == 'r' |
||||
execute ":normal argb(".vcoolor#convert#Hex2Rgb(l:newCol).")" |
||||
elseif a:type == 'h' |
||||
execute ":normal ahsl(".vcoolor#convert#Hex2Hsl(l:newCol).")" |
||||
elseif a:type == 'ra' |
||||
execute ":normal argba(".vcoolor#convert#Hex2Rgb(l:newCol).", 1)" |
||||
endif |
||||
endif |
||||
|
||||
endfunction |
||||
" }}} |
||||
|
||||
|
||||
" Restore default vim options {{{1 |
||||
let &cpoptions = s:saveCpoptions |
||||
unlet s:saveCpoptions |
||||
" }}} |
||||
|
||||
" vim:ft=vim:fdm=marker:fmr={{{,}}}: |
Loading…
Reference in new issue