Find Tab Characters in emacs

Emacs

Emacs Problem Overview


How do I find a tab character in emacs?

Emacs Solutions


Solution 1 - Emacs

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.

Solution 2 - Emacs

Just do the combination of keys as follows:

C-s TAB

Solution 3 - Emacs

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)

Solution 4 - Emacs

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))
     )
   )
)

Solution 5 - Emacs

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchernevikView Question on Stackoverflow
Solution 1 - EmacsNathaniel FlathView Answer on Stackoverflow
Solution 2 - EmacsjustinhjView Answer on Stackoverflow
Solution 3 - EmacsAlex BView Answer on Stackoverflow
Solution 4 - EmacsAdam RosenfieldView Answer on Stackoverflow
Solution 5 - EmacsdinosaurView Answer on Stackoverflow