How to set 4 space tab in bash

前端 未结 5 946
囚心锁ツ
囚心锁ツ 2021-02-01 16:11

It look like set tabstop=4 in VIM, but I don\'t know how to set it in bash

for example:

echo -e \"1234567890\\t321\\n1\\t2\         


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 16:35

    This works for me.

    ~/.bash_profile

    # Set the tab stops
    if [ -f ~/.bash_tab_stops ]; then
        . ~/.bash_tab_stops
    fi
    

    ~/.bash_tab_stops

    tab_width=4
    terminal_width=$( stty size | awk '{print $2}' )
    
    set_tab_stops() {
        local tab_width=$1 terminal_width=$2 tab_stops=''
        for (( i=1+$tab_width; $i<$terminal_width; i+=$tab_width )); do
            tab_stops+=$i','
        done
        tabs $tab_stops
    }
    
    set_tab_stops $tab_width $terminal_width
    

    GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
    PuTTY Release 0.73 Build platform: 64-bit x86 Windows
    Linux VPS 3.10.0-1127.18.2.el7.centos.plus.x86_64

提交回复
热议问题