67

How do I find a tab character in emacs?

chernevik
  • 3,922
  • 9
  • 41
  • 55

5 Answers5

83
C-s C-q <TAB>

C-s starts an incremental search, and then C-q runs quoted-insert, which inserts the next character you type literally. Then, pressing the TAB key will insert a tab character. Continue hitting C-s to go to the next tab character.

Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94
24

Just do the combination of keys as follows:

C-s TAB
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
justinhj
  • 11,147
  • 11
  • 58
  • 104
  • 4
    Why the downvote? I just tested this in various modes in Windows emacs v22.3.1 and linux v 23.0.92.1 You don't need the C-q – justinhj Jun 01 '09 at 17:18
  • I'm speculating (and didn't downvote), but maybe because people didn't think it would work, or that they figured that if chernevik were having problems, then the unquoted TAB wasn't working for him? – Blair Conrad Jun 01 '09 at 17:38
  • 5
    All of C-s TAB, C-s C-q TAB, and C-s C-q C-i work for me. Maybe somebody could explain when/why C-s TAB doesn't work? – Chris Conway Jun 01 '09 at 18:42
  • Downvotes may also happen because it only answers the specific problem, without helping the asker with the general understanding of what does differently in search mode and typing mode. (It works for me, even though I would have suspected it not to.) – Nikana Reklawyks Jul 23 '14 at 23:13
9

I use whitespace mode to highlight all tabs with the following in my .emacs file:

;whitespace http://www.emacswiki.org/emacs/WhiteSpace 
(require 'whitespace)
(setq whitespace-style '(tabs tab-mark)) ;turns on white space mode only for tabs
(global-whitespace-mode 1)
Alex B
  • 24,678
  • 14
  • 64
  • 87
8

Hit C-s to start an incremental search, then type C-q C-i to search for a literal tab character.

If you want to visualize tab characters, you can add the following to your ~/.emacs file to colorize tabs:

; Draw tabs with the same color as trailing whitespace
(add-hook 'font-lock-mode-hook
  '(lambda ()
     (font-lock-add-keywords
       nil
        '(("\t" 0 'trailing-whitespace prepend))
     )
   )
)
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
3

In some versions of emacs, you can simply do

C-s <TAB>

where <TAB> is a stroke of the tab key.

If that doesn't work, C-i is a synonym for <TAB>, so to search for tabs, do

C-s C-i

In addition, C-q <TAB> means the same thing as C-i, so you could also search for tabs with

C-s C-q <TAB>

Furthermore, C-i or C-q <TAB> can be used to insert a tab character in other situations where the tab key does not. For example, if you have emacs set to auto-expand tabs into spaces, you can still use C-i to insert the tab character while editing.

dinosaur
  • 3,164
  • 4
  • 28
  • 40