How can I switch colors using keyboard shortcuts in GIMP?

In my case (which brought me to your question) D for resetting and X for swapping colors is sufficient. Combined with O you can maybe set up some nice workarounds.

Default Colors

By default, GIMP sets the foreground color to black and the background color to white and it can be surprising how often you want to use these two colors. To reset these colors quickly, just press the D key. Also you can easily swap the foreground and background colors by pressing the X key.

Source: http://graphicssoft.about.com/od/gimptutorials/a/useful-keyboard-shortcuts.htm


As far as I know, no such functionality exists in GIMP. As you probably already know, GIMP was neither designed for art nor screencasting, and, as such, would have little need for such a feature.

However, assuming that you don't need to see the entire screen (your screen recorder just uses the part of GIMP that is the canvas), you could set up several colors using the Pencil or Paintbrush tool outside the visible area to create an actual virtual "palette." It would then be as simple as pressing the O key to get the eyedropper tool, then clicking on one of the colors you put out.


I wanted something similar so I've written a short script. This is my first effort with a lisp like language so I'm sure the example below could be improved, but it works for me on gimp 2.8.

;; script-fu to cycle between a set of foreground colours
;; edit the variable colours to modify the set
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License.

(define (script-fu-cycle-foreground-colour)

 ;add to or edit the list of colours to cycle here:   
 (define colours (list '(255 255 255) '(255 0 0) '(0 255 0) '(0 0 255) '(100 100 100)))

 (define list-index
  (lambda (e lst)
  (if (null? lst)
   -1
   (if (equal? (car lst) e)
     0
     (if (= (list-index e (cdr lst)) -1)
      -1
      (+ 1 (list-index e (cdr lst)))
     )
    )
   )
  )
 )


 (gimp-context-set-foreground (list-ref colours (modulo (+ 1 (list-index (car (gimp-context-get-foreground)) colours)) (length colours))))

 (gimp-displays-flush)
)

(script-fu-register "script-fu-cycle-foreground-colour"
         _"<Image>/Colors/Cycle FG"
         _"Cycles foreground colour"
         "Jan Marchant"
         "Jan Marchant"
         "January 2015"
         "*"
)

If you just want to assign individual shortcuts for specific colours, I guess something really simple like this would work (not tested):

;; script-fu to cycle between foreground colours
;; 
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License.

(define (script-fu-foreground-red)

 (gimp-context-set-foreground '(255 0 0))

 (gimp-displays-flush)
)

(script-fu-register "script-fu-foreground-red"
         _"<Image>/Colors/Foreground/Red"
         _"Sets foreground to red"
         "Jan Marchant"
         "Jan Marchant"
         "January 2015"
         "*"
)

For Linux save your finished scripts in your $HOME/gimp-x.y/scripts directory edit: you must use the extension .scm (similar for other OSes I guess) and then navigate to "Filters - Script-Fu - Refresh Scripts" in gimp. You should find new menu items "Colors - Cycle FG" and "Colors - Foreground - Red", and you can assign keyboard shortcuts to them (under plug-ins but easiest if you use the search box).

Of course you can extend to as many colours as you like.

Cheers, Jan