How can I use ${var//Pattern/Replacement}
to replace tab with space?
${var//\t/ }
doesn't work for me.
Instead of changing tabs to spaces one by one, the Word's Find and Replace function is commonly used to convert tabs to spaces. Step 3: Enter a space character (press space button on your keyboard) in the Replace With field; Step 4: Click Replace All.
With 'expandtab' on, Vim replaces all tabs with the appropriate number of spaces. Note that the command accepts a range, so you can make a visual selection and then just :retab the selected lines. Save this answer.
To convert tabs in a text file to spaces, you can use the expand command. To convert each tab to a single space character, use the -t 1 option.
Adding here since typing an actual tab character through PuTTY into a bash shell is not so simple. CTRL
V
TAB
doesn't work since CTRL
V
is captured in windows as paste.
Instead I use:
${var//$'\t'/ }
Example:
$ var="te"$'\t'"st"
$ echo $var
te st
$ echo ${var//$'\t'/i}
teist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With