vim: delete all blank space until next non-blank character

前端 未结 3 1705
时光说笑
时光说笑 2021-02-05 14:43

Say I have the following code:

Hello

And I want to make it

Hello

相关标签:
3条回答
  • 2021-02-05 14:54

    There's a tag text-object in vim:

    • put cursor within tag, press vat to select entire tag
    • press :, it becomes :'<,'>
    • type j, it becomes :'<,'>j
    • press Enter to join lines

    :help v_at
    
    at          "a tag block", select [count] tag blocks, from the
                [count]'th unmatched "<aaa>" backwards to the matching
                "</aaa>", including the "<aaa>" and "</aaa>".
                See |tag-blocks| about the details.
                When used in Visual mode it is made characterwise.
    
    0 讨论(0)
  • 2021-02-05 14:57

    One way when you won't need to repeat this action many times.

    JxJx
    

    Explanation:

    J           # Join current line with next one but substitute end of line with a space.
    x           # Remove the space.
    Jx          # Repeat same process for last line.
    
    0 讨论(0)
  • 2021-02-05 15:00

    When standing anywhere in the second line (the one that says Hello), press the following keys: ^d0vatgJ. Simply explained:

    1. ^ will go to the first non-whitespace character, H
    2. d0 will delete to the beginning of the line
    3. vat will select the entire tag
    4. gJ will join all the lines without inserting spaces

    If you start on the H, you can skip the ^ part.

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