How do I join two lines in vi?

后端 未结 9 1525
后悔当初
后悔当初 2020-12-07 08:41

I have two lines in a text file like below:

S_F
_ID_T_O.DAT


        
相关标签:
9条回答
  • 2020-12-07 09:29

    This should do it:

    J

    0 讨论(0)
  • 2020-12-07 09:29

    If you want to join the selected lines (you are in visual mode), then just press gJ to join your lines with no spaces whatsoever.

    This is described in greater detail on the vi/Vim Stack Exchange site.

    0 讨论(0)
  • 2020-12-07 09:39

    Vi or Vim?

    Anyway, the following command works for Vim in 'nocompatible' mode. That is, I suppose, almost pure vi.

    :join!
    

    If you want to do it from normal command use

    gJ
    

    With 'gJ' you join lines as is -- without adding or removing whitespaces:

    S<Switch_ID>_F<File type>
    _ID<ID number>_T<date+time>_O<Original File name>.DAT
    

    Result:

    S<Switch_ID>_F<File type>_ID<ID number>_T<date+time>_O<Original File name>.DAT
    

    With 'J' command you will have:

    S<Switch_ID>_F<File type> _ID<ID number>_T<date+time>_O<Original File name>.DAT
    

    Note space between type> and _ID.

    0 讨论(0)
提交回复
热议问题