How do I join two lines in vi?

后端 未结 9 1524
后悔当初
后悔当初 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:13

    Another way of joining two lines without placing cursor to that line is:

    :6,6s#\n##
    

    Here 6 is the line number to which another line will be join. To display the line number, use :set nu.

    If we are on the cursor where the next line should be joined, then:

    :s#\n##
    

    In both cases we don't need g like :s#\n##g, because on one line only one \n exist.

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

    Just replace the "\n" with "".

    In vi/Vim for every line in the document:

    %s/>\n_/>_/g
    

    If you want to confirm every replacement:

    %s/>\n_/>_/gc
    
    0 讨论(0)
  • 2020-12-07 09:14

    Press Shift + 4 ("$") on the first line, then Shift + j ("J").

    And if you want help, go into vi, and then press F1.

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

    Shift+J removes the line change character from the current line, so by pressing "J" at any place in the line you can combine the current line and the next line in the way you want.

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

    In Vim you can also use gJ.

    ََ

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

    In vi, J (that's Shift + J) or :join should do what you want, for the most part. Note that they adjust whitespace. In particular, you'll end up with a space between the two joined lines in many cases, and if the second line is indented that indentation will be removed prior to joining.

    In Vim you can also use gJ (G, then Shift + J) or :join!. These will join lines without doing any whitespace adjustments.

    In Vim, see :help J for more information.

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