0

A great answer I read as to all the different type of tab-related settings in vim is in the answer here: Redefine tab as 4 spaces. However, is there a way to actually see how those settings apply and affect a file? I have used something like:

:set list

But it doesn't really show me anything more than a bunch of $ (linebreaks), and I don't see anything for spaces or tabs in my file. Is there a way to view all the space-like characters in vim so that I can play around with, for example, how tabstop might work and how softtabstop might work, and how they may all work together, etc.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 3
    `:set list` should show you tabs. Have a look at `:help 'listchars'` if it doesn't – OhleC Apr 15 '20 at 05:50
  • 2
    David, just wanted to mention you’ve been asking a lot of qs about vim, and we do have a dedicated site with lots of experts at [vi.se]. Hope to see you there. – D. Ben Knoble Apr 15 '20 at 12:52

2 Answers2

0

There are four things in vim related to tabs:

  1. tabstop
  2. expandtab
  3. shiftwidth
  4. softtabstop

Refer to useful reference of tab stops in vim

tabstop Set tabstop to tell vim how many columns a tab counts for. Linux kernel code expects each tab to be eight columns wide. Visual Studio expects each tab to be four columns wide. This is the only command here that will affect how existing text displays.

expandtab When expandtab is set, hitting Tab in insert mode will produce the appropriate number of spaces.

shiftwidth Set shiftwidth to control how many columns text is indented with the reindent operations (<< and >>) and automatic C-style indentation.

softtabstop Set softtabstop to control how many columns vim uses when you hit Tab in insert mode. If softtabstop is less than tabstop and expandtab is not set, vim will use a combination of tabs and spaces to make up the desired spacing. If softtabstop equals tabstop and expandtab is not set, vim will always use tabs. When expandtab is set, vim will always use the appropriate number of spaces.

You can see current settings in vim by using below commands, in command mode:

:set tabstop?   
:set expandtab?  
:set shiftwidth?   
:set softtabstop?   

You can set values for current session by using commands below, in command mode:

:set tabstop=4   
:set expandtab #if you want to remove expand tab, set noexpandtab
:set shiftwidth=4
:set softtabstop=4 

Alternatively, if you want to make the changes permanent, you can make changes to vimrc file:

It is located in the below path:

~/.vimrc on Unix;  
$HOME/_vimrc on Windows

For gvim, you can go to Edit -> startup settings to see current vimrc settings and edit them.

You need to add a line to vimrc like given below:

set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
  • right, I get that part, I mean how do I actually visualize what those four things are doing -- i.e., show a space or a tab or a newline or whatever in the file itself. – David542 Apr 15 '20 at 07:04
  • 1
    In vim,You can highlight space or tab, by searching for `\\s\|\t` – Venkataraman R Apr 15 '20 at 07:27
0

This should work:

:set lcs=space:_,tab:>~ list
hustnzj
  • 525
  • 6
  • 13