The Stack Overflow podcast is back! Listen to an interview with our new CEO.
119

Yes, use listchars: set list set listchars=tab:>- If you put these two lines in your .vimrc, tabs will be shown as > for the start position and - through the rest of the tab. (Sidenote: listchars can also show trailing spaces with trail:x (replace x with the character you want to use for a trailing space), which can be useful as well.)


98

You can use the :retab command. From :help :retab Replace all sequences of white-space containing a <Tab> with new strings of white-space using the new tabstop value given. If you do not specify a new tabstop size or it is zero, Vim uses the current value of 'tabstop'. [...] With 'expandtab' on, Vim replaces all tabs with the appropriate ...


58

The basic answer is :set list, which causes tabs to display as ^I. However, I recommend going beyond that. Just :set list is problematic in that it fails to preserve visual alignment on screen. For example: %.o: %.cpp ^Ig++ -c $< doesn't look good, especially when you expect the g of g++ to appear under the first p of cpp (assuming tabstop=8). ...


24

Instead of just pressing Tab, first press Ctrl-V and then press Tab. This can be used to insert a variety of special chars. See :help i_CTRL-V for details. Ctrl-V also works in command-line mode (:help c-CTRL-V), and even in some other programs entirely. (e.g. bash, mutt.) If you have Ctrl-V mapped to something else, try Ctrl-Q. This has the same effect ...


23

You can use :retab, as stated, however, this will change all tabs to spaces, not only tabs at the start of the line So this (where ⇥ is a tab character): if :; do ⇥echo "⇥hello" end gets changed to (where ␣ is a space character): if :; do ␣␣echo "␣␣hello" end This can produce unexpected side-effects in some scenarios, and it's even more of an issue when ...


20

'listchars' takes two characters for tab so you can simply use two regular spaces: set listchars=tab:\ \ ,trail:·,eol:¬,nbsp:_


20

As the softtabstop documention mentions, it's useful if you want to keep the default tab stop size of 8, but edit a file as if the tab stop size was some other value. For example, if you wanted an indentation level of 4 while editing code, but some comments had tab-indented text such as a table that depended on a tab stop of 8, you could set sts to 4. One ...


18

As far as I can tell there is no reasonable way to accomplish this in a plugin. There is a patch for it, but it's hard to predict when / if the patch will get merged.


14

Highlighting tabs Temporary Tab highlighting For occasional use, one can simply highlight all tabs in a document using the following search / command: /\t To remove the highlighting, simply type :noh which is short for :nohlsearch —no high lighting. Permanent Tab highlighting " Highlight tabs as errors. " https://vi.stackexchange.com/a/9353/3168 match ...


13

Rather than change your behavior (which is error prone). I would set up vim to behave differently for this file type. So in my normal editing I expand tabs. But specifically for make files I set the noexpandtab so that tabs are retained. Add the following to your ~/.vimrc file: " Normal action set expandtab if has("autocmd") " If the filetype is ...


11

Vim provides !retab command which will replace all sequences of <Tab> with new strings of white-space using the new tabstop (e.g. :set tabstop=2) value given, but all tabs inside of strings can be modified (e.g. in a C program, you should use \t to avoid this)! So alternatively you can change all tabs into spaces using the following command: :%s/\t/ ...


9

I personally like the use of the plugin indentLine, which displays a vertical line at indentation levels. It is of great help especially in python, where the indentation is important. Among other things, it provides a toggle command, that can be mapped to a key combination, so that you can turn it off, when you don't need it.


9

It's only a clumsy workaround, but if you :set list the cursor will be positioned on the other "side" of the tab.


9

It gets reset by the Python filetype plugin; from /usr/share/vim/vim74/ftplugin/python.vim: " As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 This file is loaded every time a Python file is loaded. Personally I find adding indentation settings here a bit surprising though. At any rate, to override this use this in your vimrc: ...


9

If you want to do that in vim you can use the following macro: qa^V3j$d"_4dd^V3jI<tab><Esc>Pq Which can be decomposed like this: qa Record the macro in the register a ^V Enter visual block mode (use ctrl-v) 3j$ Select the lines you want to put in a column d Delete them "_4dd Delete the lines which ...


8

From the comments: since version 8.1.105, vim has +vartabs compile-time feature, thanks to Christian Brabandt ! As far as I can see, this allows implementing elastic tabstops. See the actual pull request.


8

First possibility Add the following line to your .vimrc: autocmd FileType gitcommit setlocal expandtab Second possibility Create a file ~/.vim/after/ftplugin/gitcommit.vim and in there put: :setlocal expandtab See the faq: How do I configure Vim to automatically set the 'textwidth' option to a particular value when I edit mails How do I extend an ...


6

A tab advances to the next column whose position is a multiple of the tab stop. So, with tabstop=4, if your cursor is in column 7 and you press Tab, the cursor will advance only one column to column 8, as in the first tab in your example. Tabs are not constant width. You can visualize it thus—each ↓ is a tab stop, a column that is a multiple of 4: ↓ ↓...


6

The cursor in normal mode is on the character not to either side. So you can do i and a to go to insert mode to the left or right of the tab respectively.


5

You may want to show tabs differently in a regular terminal and gvim. set list! if has('gui_running') set listchars=tab:▶\ ,trail:·,extends:\#,nbsp:. else set listchars=tab:>.,trail:.,extends:\#,nbsp:. endif (Adding for completeness, in case others find it useful).


5

Put this in your .vimrc file: autocmd BufRead,BufNewFile *.htm,*.html setlocal tabstop=2 shiftwidth=2 softtabstop=2 Briefly, autocmds get processed when the specified events occur for the specified file name patterns. Here we just set the tab values for the current buffer to the desired value in the event of reading or creating a file with .htm or .html ...


5

Have you sourced your .vimrc since making these changes? When having vim open just type source ~/.vimrc (assuming it is in it's default location) EDIT: This could help too


4

This command will remove all whitespaces on both sides of one or more tabs in every line of the current buffer: :%s/ *\([\t]\+\) */\1/g


4

You chose to have them displayed that way by adding the uhex setting to the 'display' option. You can :set display-=uhex to restore the default behavior of displaying them as ^I. Getting :reg to display them differently would require a Vim patch, but some plugins provide displays of the registers in a scratch buffer, which may help. Lord of the Regs ...


4

Easiest method is to do :set list, which will show tabs as ^I and end of line as $. I like to use a mapping that calls :set invlist to toggle between regular display and list display. For example: :nmap <leader>l :set invlist<cr> This allows me to quickly check if there are tab vs space problems and then go back to a regular display.


4

Are you trying to remove the unnecessary spaces or are you just trying to format your code correctly. Because there are different solutions to the problem. Do correct formatting: You can get vim to correctly indent your code by using ={motion} command The easiest way to use this is to use visual mode. Go to the start of the section you want correctly ...


4

Think of 'softtabstop' as an additional control over 'tabstop', allowing you to reach indents "in between" tab stops. With your indent setting, you don't actually need that, so the value of 'softtabstop' doesn't really matter: You can set it to 0, turning this off, set this equal to 'tabstop', in which case the effect is the same as off, or :set softtabstop=...


4

As mentioned in :h softtabstop, the softtabstop indicates how many columns vim uses when you enter <Tab> in insert mode. Although it performs like <Tab> inserted, in fact, the vim mixes <BS> or <Tab> for that. If you hit <Tab> in insert mode, the vim will act like: if set expandtab always uses <BS> else if ...


3

To delete white spaces after tabs, use the following substitution command: :%s/^I \+/^I/g where ^I is a special character which appears when you press Tab. To delete all whitespaces between non-whitespace characters, use the command: :%s/\(\S\) \+\(\S\)/\1\2/g To double-check if all middle spaces are gone, use: /^I \+ command to find them. If there are ...


3

Try using: expand -t 4 input_filename output_filename expand is a command-line tool to convert tabs to spaces, which you can run from a shell or with :!expand. It's in POSIX so it should be available on most systems. unexpand will do the reverse, by the way.


Only top voted, non community-wiki answers of a minimum length are eligible