Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctrl-x o backwards (opposite of other-window)?

Tags:

emacs

CTRL-x o - switch cursor to other window

I would like to have the ability to reverse what control-x o does. Something like control-x p that does exactly what control-x o does, but backwards. The reason for this request is that I often have two buffers open that are code and one buffer open that is a repl. I often have to move across one of the buffers to get to the other, that is annoying.

Say I have 3 buffers open (A, B, C), and I am on buffer B. The buffers are in alphabetical order in terms of control-x o. When I want to go to A, I want to just press control-x p, rather than having to press control-x o twice.

Any help is appreciated, Thank you.

like image 908
Stephen Cagle Avatar asked Nov 24 '12 22:11

Stephen Cagle


1 Answers

Call other-window with a negative count. This can be done interactively by pressing C-- C-x o. The "C--" is supplying a numeric argument of -1. You can supply any numeric (NUM) by pressing C-u num.

If you don't want to press the additional key cord, just write you own command command to hard code the "-1" argument:

Add this code to your .emacs file

(global-set-key "\C-xp" (lambda () 
                          (interactive)
                          (other-window -1)))

How does it work? "C-x o" calls the function other-window (to find that out use C-h k and then type the key combo).

In the code above we define an anonymous function, make it interactive and do what we want. Then we bind that function to the key combinaion C-x p.

like image 181
pmr Avatar answered Nov 18 '22 07:11

pmr