[Download postscript version]
next up previous
Next: Entering frequent text Up: Emacs Previous: Emacs

 

Moving around

There are many possibilities to move the cursor position around. During programming, we need to move in a very special fashion and emacs provides support in many different ways. Some of the commands are also available through the cursor keys, such as up, left, page up, etc. Keeping in Mind that each time the hand leaves its keyboard position to search the cursor keys, the hand also needs to come back to its natural position, which is much slower than using the equivalent control sequences. It is also more natural to work in a way that keeps the hands on the same place.

Table 1 summarizes the most basic movement commands. These commands are not only useful in emacs, they are also valid in other programs such as the c-shell or in text entering boxes in Netscape.

A very quick way to move to a different position provide the search functions, especially the incremental search functions. If you want to be more fancy and you know for example, that the line you would like to jump to contains a printf statement and the variable Data_p, you can try the incremental regular expression searches, which are also explained in table 2. You can also set markers in your emacs buffers and jump around with the corresponding commands which are described in table 3.

 

Basic Movements
Key Action
C-p Up, previous line
C-n Down, next line
C-b Left, backward char
C-f Right, forward char
C-a Beginning of the line
C-e End of line
C-v Page down
M-v Page up
Table 1:  

 

Searches
Key Action Explanation
C-s or C-r Incremental search forward or backward The direction of the search can be changed continuously during the search by typing C-r or C-s. Further, if we want to skip to the next occurrence of the match, we can type C-s again (or C-r respectively). Typing C-s (or C-r) twice, repeats the last search.
MC-s or MC-r Regular expression incremental search forward or backward
Table 2:  

 

Jumps
Key Action Explanation
C-x / (key) Set mark (key) designates any key on the keyboard, including control sequences. The mark will be saved in an emacs register identified by the key enteredgif
C-x j (key) Jump to mark This command jumps to the place pointed to by register named (key). If the position is in a different buffer, the buffer is changed automatically. This function is very practical for programming. For instance, the position in the code that I currently work on is the c register, the position of the local variables in the l register, the global variables in the g register, etc. This allows very fast switching between points in large files.
M-. Jump to function See section 2.4 for more details on this and other etags commands.
C-x o Jump to other window If the screen is split in multiple windows, we can switch between the different windows with C-x o
C-x b Switch to buffer This exchanges the current buffer with a different loaded buffer
C-x C-x Exchange point with mark If we frequently move forth and back between two points in the same buffer, we can use this command to jump between two locations. It is very useful if we just briefly visit another portion of the code and we want to return back. This is accomplished by setting the mark at the current position (C-Space), visit the other location and return with C-x C-x.
C-u C-Space Cycle mark ring All the marks are saved in a mark ring. Repetitively calling this command lets you visit all the last positions you set a mark.
MC-n (MC-p) Jump forward (backward) to the matching parenthesis This jumps forward or backward to the next or previous matching parenthesis of the same level of indentation.
MC-u (MC-d) Move up (down) in the current list structure Jumps up or down to the next higher or deeper level of parenthesis. These list commands are extremely useful if you have deep nested block levels in your source code.
Table 3:  


next up previous
Next: Entering frequent text Up: Emacs Previous: Emacs

Adrian Perrig
Wed Jun 12 00:18:25 MET DST 1996