Questions tagged [tab-characters]

Question about how to handle white spaces tab characters with vim, insert them, remove them, convert them to space characters, etc...

Filter by
Sorted by
Tagged with
164
votes
8answers
185k views

Displaying tabs as characters

When I work on files in python, I sometimes mistake tabs for spaces and vice versa. Is there a way I can get Vim to display a character for a tab instead of a tab?
114
votes
5answers
119k views

How to replace tabs with spaces?

Is it possible to convert tabs to spaces, while maintaining text alignment? Simply replacing only works usefully when there are no leading characters.
40
votes
1answer
76k views

Setting TAB to 2 spaces

I've looked through various answers which imply that setting the following in .vimrc would be appropriate to force tab insertions to become spaces. filetype plugin indent on " On pressing tab, ...
28
votes
4answers
28k views

What is `softtabstop` used for?

I've been aware of these tab related settings in Vim: ts sw expandtab smarttab sts My normal setting is set ts=4 sw=4 expandtab smarttab. But according to sts documentation, if expandtab is not ...
27
votes
2answers
3k views

Elastic Tabstops in Vim?

Is there a plugin or a built-in feature in Vim that allows for elastic tabstops? I've searched a bit, and I found some references saying it was not possible in Vim, but those were quite old. Is ...
20
votes
3answers
2k views

How can I make Vim position the cursor at the start of a tab character instead of the end?

Open an empty buffer and insert a tab character then exit to normal mode. When you place the cursor (normal mode) on the tab it will be at the right side of the whitespace. I'm looking for a way so ...
18
votes
3answers
1k views

Tabs for indentation, spaces for alignment

I am trying to make vim auto indent with tabs, and align with whitespaces, but actually, vim indent with tabs and fill the alignment with tabs + white spaces. Vim does it : (each block is a tab) { &...
17
votes
2answers
20k views

Insert tabs in INSERT mode when expandtab is set

I have set expandtab in my .vimrc file to convert tab to multiple space characters. However some files (like Makefile) need actual the tab character inserted. Is there an easy way to force the ...
14
votes
2answers
10k views

Show listchars tab as spaces

I use list and listchars to show my whitespace, but the code style I adhere to uses tabs. Seeing > or ^I for all of my tabs is nauseating. How would I keep all of my existing list characters but ...
8
votes
2answers
6k views

Vim doesn't use the correct indentation in Python files

I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
8
votes
3answers
1k views

Shift left or right (with `noet`) without converting existing spaces to tabs

Foreword I'm using the "indent with tabs, align with spaces" ideology for indentation. This means that each line in a file can be prefixed with an arbitrary amount of tabs and spaces (as opposed to "...
6
votes
1answer
71 views

Why are tabs adjacent to concealed tabs displayed wider than a single tabstop?

I just wrote the following code in an answer to another question: syntax match HideTwoIndents /\v^\t(\t)?/ conceal set conceallevel=2 This works great if 'list' is set and if 'listchars' does not ...
5
votes
1answer
3k views

Expand <TAB> into 2 spaces when and only when editing HTML

My current configuration makes vim automatically expand TAB to 4 spaces for me: " Define tab as 4 spaces " Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces set tabstop=4 ...
5
votes
1answer
643 views

vimrc tab behavior when noexpandtab and softtabstop is less than tabstop

Questions In the following example: Why in the first line, a \t is inserted but only 4-col blank is displayed? Shouldn't it be 8 according to tabstop? Why the two <TAB> hits in the first line ...
4
votes
2answers
2k views

softtabstop == tabstop VS softtabstop=0

Are this: set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=0 ..and this: set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=4 ..exactly the same? I thought that if ...
4
votes
1answer
459 views

How can I set expandtab but only for git commit messages?

Most of the time I'd like noexpandtab on because our corporate formatting uses tabs instead of spaces, so in my .vimrc I have this: " Set tab width stuff set tabstop=4 softtabstop=0 noexpandtab ...
4
votes
4answers
2k views

Delete indenting spaces one at a time

I want to be able to delete indenting spaces one at a time. If I set shiftwidth to 4, it deletes 4 spaces at a time if vim counts them as indentation. Setting shiftwidth to 1 fixes the problem, but ...
4
votes
2answers
191 views

<C-v> <C-i> not working to print literal tab!

I'm trying to set a custom breakat for plain text files. Aiming for a very small set of characters -- just hyphens, slashes, and whitespace. That means I need to add tabs, which I do by setting ...
3
votes
3answers
651 views

Avoid spaces getting converted to tabs automatically during shift(>>)

I use 2 spaces as indentation. So I set shiftwidth using :set sw=2. However when I do the shift operator(>>) on a line twice, the indentation converts the 4 spaces automatically to a tab. So to ...
2
votes
2answers
984 views

Transforming a long table into multiple columns

Suppose I have the following table: E 12.02 T 9.10 A 8.12 O 7.68 I 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 C 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 ...
2
votes
3answers
5k views

How can I remove additional whitespace in the middle of line?

I know how to remove trailing white spaces at the end of lines. Does anyone know how to remove white spaces in the middle of a line? The white space I mean is before tab and after tab characters. For ...
2
votes
2answers
974 views

Show leading whitespaces, but not including tabs

I am a tabs kind of guy, I do not like when my code contains leading whitespaces instead of leading tabs. I often exchange codes with colleagues and I first have to convert the leading whitespaces to ...
2
votes
1answer
89 views

Don't show tab characters as ^I or <09> in the output of :registers

If I type :registers, I see a lot of <09>: "1 <09><09><09>d = self / i.to_f^J<09><09><09>r = d.to_s^J<09><09><09>p r =~ /0$/^J "2 <...
2
votes
1answer
91 views

escape, ctrl-w through citrix lite in browser

I need to be able to run vi on a machine that I access through Citrix lite in the browser. However I've come across a number of problems because of conflicts around esc and ctrl+w. Specifically, ...
2
votes
1answer
149 views

Why can't I use a literal Tab as the {commands} for :normal?

I'd like to write the following code: function Normal(command) execute "normal!" a:command endfunction call Normal("\<C-O>") call Normal("\<C-I>") The first call to Normal succeeds, ...
2
votes
1answer
206 views

How to view tabs as conventional whitespace, not as control character ^I (caret I) in VIm?

I've somehow managed to have all tabs show up as the control character ^I in VIm, specifically gvim 8.1.1 on Windows 10. All I have related to tabs in vimrc is this: set tabstop=2 I do also have ...
2
votes
1answer
34 views

On the length of tabs after an initial character

Length of tabs after initial char Start gvim with the --clean option, to get a clean slate, and then do: :set noet ts=5 sts=3 sw=2 Then enter the following 1234567890 and on the next line, press ...
1
vote
3answers
1k views

Why are <tab> characters variable width?

I have the following settings in my vimrc: set listchars=tab:►-,eol:¬,trail:● When I display unprintable characters in my makefile, I get something that looks like the following for one of the ...
1
vote
1answer
56 views

Stop vim from deleting expanded tab as a block of spaces

I am on CentOS 8.1 and using vim 8.0.1763. When I open a python file, e.g. vim tmp.py, I type tab and it inserts 4 spaces (see .vimrc below). When I type delete, it deletes all 4 spaces. I want it ...
1
vote
1answer
42 views

Make pipe behave like `col('.')`

So when I go to the first character in a line, the first character in that line is a tab character, and I execute echo col('.'), I will get 1. However when I type 2| I won't go to the next character, ...
1
vote
1answer
86 views

How to trigger file type specific settings after they they have been executed in vimrc?

I have the following setting in my vimrc autocmd FileType * setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab This is just so that every file I open looks consistent. I also have another ...
1
vote
2answers
85 views

Shouldn't `softtabstop` be set, when using option 2 in `:h tabstop` to configure Vim to use spaces for `<Tab>`s?

I want to configure Vim to use spaces for <Tab>s everywhere. Therefore, I've had a look at :h tabstop to figure out how to perform the configuration. Looking at the help text, option 2. seems ...
1
vote
2answers
395 views

Pressing Enter removes indentation

If I have a file a.js like this: let a1 = [ ]; and I press Enter at the end of the first line, a Tab is inserted. I do not want this, so I added a setting: filetype indent off but then if I have ...
1
vote
1answer
563 views

Auto-indent with spaces, but insert TAB when I press the TAB key

I like to indent my shell scripts with two spaces instead of a TAB. So, I set setlocal shiftwidth=2 in ~/.vim/after/ftplugin/sh.vim. It works, but I noticed that when the indentation level gets ...
1
vote
1answer
303 views

Tab size fixed to 8 in spite of polyglot.

I am using Vim 8. Since I installed vim-polyglot to handle syntax highlighting and indentation of different languages without going crazy, whatever file I open has a tab size of 8 automatically. I ...
1
vote
2answers
269 views

How can I highlight misuse of tabs and spaces according to current configuration?

I'm looking for a way that will highlight lines (or part of lines) that don't adhere to current tabs settings. Say for instance, I have the following configuration in my .vimrc tabstop=8 ...
1
vote
1answer
88 views

How to write literal for Tab key to use for motion?

I've the following dummy file created via: echo -e "a a\tb b\tc c" > file Is there any literal for space which I can use for motion argument? For example this works (which removes the 1st a a ...
1
vote
1answer
252 views

tabs after pastetoggle instead of spaces

Using following .vimrc " Just to see tab/spaces/endline clearly: set encoding=utf-8 set list set listchars=tab:▸\ ,eol:¬ nnoremap <F5> :set list!<cr> " Tab to spaces settings set tabstop=...
1
vote
1answer
439 views

How to show 2 spaces as tabs in listchar?

I like to see my indentation level with listchars=tab:\|\ But one project uses two spaces instead. Is there any way to show indentation level lines then? This question seems to the opposite of Show ...
1
vote
0answers
149 views

The tab adds 8 spaces even though `set tabstop?` returns 4

For some reasons when I'm editing my ~/.config/nvim/init.vim, it adds 8 spaces even though I set set tabstop=4 on the file. Actually, :verbose set tabstop returns 4, so it should be 4 spaces. I ...
1
vote
1answer
133 views

Tab multiple lines [duplicate]

I have my tab set to 4 spaces with :set tabstop=4. Now I want to highlight multiple lines and tab them, or indent all them 4 spaces. If I highlight the lines and do >, it seems to indent them more ...
1
vote
0answers
410 views

Set tab width according to file [duplicate]

I have the following in my .vimrc: set expandtab "Use soft tabs (spaces) set shiftwidth=2 "Set tab width = 2 set softtabstop=2 "Set tab width = 2 set autoindent "Set indent of previous line Now if I ...
1
vote
0answers
103 views

Files with tabs are length 8 even with set tabstop=4 in vimrc [duplicate]

I have most of the usual tab commands in ~/.vimrc: set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab set breakindent set autoindent set smartindent. There are no problems when I open a ...
1
vote
0answers
762 views

expandtab / noexpandtab toggles by itself in Neovim

I have this issue where noexpandtab turns itself on after a while. Tried to describe it here and in the Github Issue because I am not 100% sure this is a legit bug. For a long time, I have ...
0
votes
1answer
127 views

How to check if the character under the cursor is a tab?

I am using the code getline(".")[col(".")-1] to get the character under the cursor. How can I check if the character under the cursor is a tab ?
0
votes
1answer
377 views

How to change the size of the indent that's created using “>” (forward arrow)?

If I want to change the tab size, I can do that with set tabstop=<number>. I have that in my .vimrc to make it 4 instead of 8. However, when I indent/deindent text by highlighting it then using ...
0
votes
1answer
253 views

Search for 2 but not for 3 tab characters

I want to search in Vi for two tabs but not for three or more tabs. I tried several things like this: /\t\t\(\t\)@! But nothing works. Any idea?
0
votes
1answer
49 views

Neovim keeps reverting shiftwidth size after `after/ftplugin`

I like to code with 4 spaces as a tab. I added this to after/ftplugin/sass.vim: echom "before sass file settings" set shiftwidth=4 " <---- Problem setting, keeps changing back to 2 ...
0
votes
1answer
2k views

Fixing tab and space inconsistency

I used < in visual model to do a shift+tab reverse for a code inside loop after I removed the try/except phrase. Now, I get an error: $ python clean_captions.py File "clean_captions.py"...
0
votes
1answer
179 views

Tabs and only tabs for any file type

I would like vim to only ever insert a space character when I touch the space bar. Instead vim decides that sometimes tabs should be 4 spaces. How do I force vim to always and forever use tabs ...