-1

How to remove spaces between much words in a single long line using vim?

Already tried tried :

s/ \+/ /

and examples of this.

Doesnt work.

I have a line kinda this:

""" http:// goo gle. com / ? script & GetReferen ce?login = LOGIN&notLogi n & and a lot if this buggy text witch should build relevant url string 

Using exaсtly code adviced in a first solution, it would just delete intendance (first 4 spaces I used to build my so-long string value in Python) and no spaces between words.

Visual Selection - I mean by hitting shift+v to select whole line at once. The same as ^v+$.

No matter with, or without v-s, I can't reach line completelly without spaces.

yolenoyer
  • 8,797
  • 2
  • 27
  • 61
kAldown
  • 610
  • 2
  • 8
  • 27
  • Do you mean "indentation" rather than "intendance"? I still don't know what "intendance" is. If it only deletes the first set of spaces on the line, then that implies either you *left off the g* at the end of the command in your first answer, or you have the 'gdefault' option set. But if 'gdefault' was set then your original command should work. So I'd guess you forgot the 'g'. – Ben Mar 03 '16 at 17:01
  • First 4 spaces?? I can't see 4 spaces in your string anywhere. And `shift+v` is linewise, it's different from using `v`. And `v+$` looks like a wrong key combination, you certainly mean `^v$` (which is still different from `shift+v`). I'd like to help you, but it's really not clear what you're asking. – yolenoyer Mar 03 '16 at 17:04
  • @Ben Yeap, I mean Indentation, sorry. https://asciinema.org/a/0ncm1vogegnyhcltmvaxo9jcc – kAldown Mar 03 '16 at 17:18
  • 2
    I think I see what's going on now. You want to remove ALL spaces between words, replacing them with NOTHING, right? Your command says "take as many spaces as you can and replace them *with one space*" which is, I guess, not what you actually want. Change your replacement to be empty and I think you'll get what you want. – Ben Mar 03 '16 at 18:04
  • @Ben omg, I so dumb!. Thank you. Write an answer please, I'll check it as an solution. – kAldown Mar 03 '16 at 18:12

1 Answers1

2

If you don't use the g flag, it will replace only the first occurence in the line. Try to add it like this:

:s/ \+/ /g
yolenoyer
  • 8,797
  • 2
  • 27
  • 61
  • Still nop, just removes intendance and thats all. P.S. be sure, I need to use it in visual select mode. – kAldown Mar 03 '16 at 16:05
  • I don't know select mode well, but it seems that you have to enter Ctrl-O before entering commands – yolenoyer Mar 03 '16 at 16:12
  • This should work. What does "removes intendance" mean? And why do you need to do it in "visual select mode"? What do you even mean by "visual select mode", are you just referring to highlighting text in *visual mode* using `v` and then moving the cursor? If you want it to act on a visual selection, what particularly are you looking for it to do in regard to the selection? – Ben Mar 03 '16 at 16:21
  • @Ben a lot of words. It doesn't work with or without visual selectn and even `/g`, what exactly do you want me to tell you more? – kAldown Mar 03 '16 at 16:31
  • @yolenoyer Nope, I'm not. Just `:` as always. – kAldown Mar 03 '16 at 16:32
  • I understand you have a lot of words you want to separate. I just listed what information you need to provide. "It doesn't work" means almost nothing. To answer you question we need to know what *exactly* did you try (you left out visual mode entirely in your question), what *exactly* you expected to happen, and what *exactly* happened instead. The command in this answer is exactly what ought to work to replace all sequences of 2 or more spaces in a line with a single space. If it doesn't work for you, then we guessed wrong at what you are actually doing. So don't make us guess. – Ben Mar 03 '16 at 16:34
  • @Ben Ok, I'll edit post to clerefy my needs. Just a second. – kAldown Mar 03 '16 at 16:43