(This is an adaptation of an answer I gave to another question. It was suggested to move the answer elsewhere, since the asker had marked their question as closed, and this explanation would otherwise be lost in the ether. I'm placing it here, because this question is the closest I could find to what was asked there.)
This answer provides an explanation of the error:
(error Key sequence g l starts with non-prefix key g)
With your code, Emacs thinks you want to use g as a prefix-key in the global-map. In other words, that you want to bind the l key underneath the g key, which requires g to be bound to some keymap. That's allowed, but it assumes that g is already available for use as a prefix-key.
When you first open Emacs, g is bound in global-map to self-insert-command. But you are free to bind it to something else: a keymap, command, or a keyboard macro. That's what you would be doing if you had instead written (global-set-key (kbd "g") 'evil-end-of-line). You would simply be replacing the binding of g with the evil-end-of-line command.
- How to bind
g l to evil-end-of-line?
(keymap-global-unset "g") (keymap-global-set "g l" 'evil-end-of-line)
Or, using the older keybinding functions...
(global-unset-key (kbd "g")) (global-set-key (kbd "g l") 'evil-end-of-line
- Why does the initial attempt in the question fail?
The reason that (global-set-key (kbd "g l") 'evil-end-of-line) doesn't work without first unsetting g is explained in the error message:
(Key sequence g l starts with non-prefix key g)
When you bind to a sequence of keys (like g l), you're really telling Emacs to create a keybinding for l in whatever keymap is bound to the g key, or if g has no binding, bind it to a blank keymap and then add l to that keymap. But as Emacs advises you, g is already bound to something else, which is not a keymap.
If there were no binding at all for g, Emacs would happily bind an empty keymap to it and then bind l in that keymap. So we solve this by first un-binding g and then binding l underneath it.
If you wanted to be more explicit about what you were doing, you could actually create the keymap first, then bind your keymap to g. In that case, you could also bind the same keymap to other keys.
(defvar-keymap my/prefix-map "l" 'evil-end-of-line) (keymap-global-set "g" my/prefix-map) ;; same keymap on another prefix (keymap-global-set "C-c m" my/prefix-map)
gto both (1) perform navigation as soon as you hit it and (2) wait for you to hitland then invokeevil-end-of-lineinstead? You could perhaps usesit-forand after that delay (i.e., if no user input) then use the usualgcommand, else, iflis hit within that delay use your eol command.gis the start of navigation for many commands inevil. So I want to use the combination that isn't bound to any other command:g l. But becausegis the prefix for other evil commands, I'm unable to use it with another combo. I still want to keep otherg ...commands likeggwithout a delay.