Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 11: Editing Utilities

Previous HourNext Hour

Sections in this Hour:

 

Transposing and Changing Case


Earlier in this section, I told you about my problem with writing teh when I intended to write the. In fact, a general problem that many people have is that they type keys in the wrong order. The people behind Emacs recognized this problem and made a solution that is accessible through one keystroke--C-t (transpose-chars). To be entirely accurate, you need two keystrokes, because you need to move point to the location between the two characters. In sams-lib an additional function exists called sams-transpose-prev-char that transposes the previous character and the one before it. This makes the problem solvable with one keypress. You can, for example, bind this function to Ctrl-Shift-t, which is done with the following:


(global-set-key [(control T)] 'sams-transpose-prev-char)

There are also commands for transposing words, lines, sentences, and paragraphs. Although transposing words is useful for keeping your mental state as described above, the second two are not, as you need to think anyway when you decide to transpose two lines or sentences. The commands are M-t (transpose-words), C-x C-t (transpose-lines), transpose-sentences, and transpose-paragraphs.

Changing Case

Three functions exist that make it easy for you to change the case of a word-- M-l (downcase-word), which lowercases the word; M-u (upcase-word), which uppercases the word; and M-c (capitalize-word), which sets the first character in uppercase, and the rest in lowercase.

It is important to note that the three functions work from point until the end of the word. Thus if point is before r in word, and you press M-u then it is translated to woRD. As a side effect, point is moved to the end of the word. Thus if you have a sequence of words that you want to uppercase, simply press M-u a number of times. An alternative is simply to mark all the words as a region, and then press M-u.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 11: Editing Utilities

Previous HourNext Hour

Sections in this Hour: