Avatar of naseeam
Flag for United States of America asked on

How to convert indentation to space in Vim ?

I typed following command in vim to show white space characters, such as eol, tab, and space.
:set listchars=eol:$,nbsp:_,tab:>-,trail:~,extends:>,precedes:<

The file was cloned from git repository.  Indentation is setup for tabs.  How do I convert indentation to space?

 50 addtask listtasks$
 51 do_listtasks[nostamp] = "1"$
 52 python do_listtasks() {$
 53 >-import sys$
 54   print('Hello World')$
 55 >-for e in bb.data.keys(d):$
 56 >->-if d.getVarFlag(e, 'task', False):$
 57 >->->-bb.plain("%s" % e)$
 58 }$
Editors IDEsLinux Distributions* Text Editor* editors

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

:%s/\t/    /g
This worked!  Could you please explain each character in this command?

: command mode
% probably means to apply the command to the whole file. not sure : i hardly ever use vi
s replace command
/ delimiter ... meaning s/X/Y/ replaces all instances of X with Y. "/" can be replaced with a different ascii character

% is all lines (1,$) as a line selector.
the final g on the command means to replace ALL items matching on a line not just the first one.
\t is  a visible way to type TAB   (one can also use TAB character in that spot.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Thank you for solving the problem.