Sort line (horizontally) in VIM [duplicate] - vim

This question already has answers here:
Sorting words (not lines) in VIM
(6 answers)
Closed 8 years ago.
I know that it's very easy to do sort operations in vim through build in command sort.
But how to sort just one line and text within that line horizontally?
e.g. from this point (aaa ccc bbb)
to this (aaa bbb ccc)
I tried vi(:sort but it doesn't helped me. Any suggestions?

:s/\s\+/\r/g " break the line into multiple ones
:'[,sort " sort them
:,']j " join them

Related

Adjusting all line to Left side of the file in gvim [duplicate]

This question already has answers here:
Remove all arbitary spaces before a line in Vim
(9 answers)
Closed 5 years ago.
I'm new to the vim editor.
How can I adjust all lines to the left? I have many lines which are indented and I want to arrange them so they all abut the left side of the file (no spacing at the start of the lines).
Select all line in visual mode and then type :left . Hope this helped.
keerthan
The simple key sequence :%left will do the trick, it basically applies the left command to all lines in the file.

How to filter text with multiple keyword in vim [duplicate]

This question already has answers here:
Is there a decent Vim regexp OR command? What is the best way to find mismatched if else's?
(3 answers)
Closed 8 years ago.
Question is:
To display only lines contains keyword1 or keyword2,how to do that?
I know there's command like :g/pattern but that can work only for one keyword.
It's not duplicate question as it is to search instead of search replace case
Use alternation:
:g/foo\|bar\|baz/#

Negative numeric argument in Vim [duplicate]

This question already has answers here:
Delete n lines in the up direction in vim
(5 answers)
Closed 9 years ago.
Is there a way to apply a vim command backward? For example, I want to kill 5 lines backward, instead of 5dd, is there something like -5dd?
From :he d:
["x]d{motion} Delete text that {motion} moves over [into
register
x]. See below for exceptions.
How about 5dk 4dk (k being the motion for upwards)?
Edit: changed count to 4 as this results in 5 lines being deleted apparently...

Using listchars to show leading whitespace in Vim [duplicate]

This question already has answers here:
Make Vim show ALL white spaces as a character
(23 answers)
Closed 9 years ago.
I use spaces over tabs. In Sublime Text 2, I would have leading spaces show like so:
I have my .vimrc setup to show tabs, line endings, etc. But I'm not sure how to replicate what I have in Sublime. It was handy as I could still see indentation much more easily when just using spaces.
Here's my line for it now:
set listchars=eol:¬,tab:→→,extends:>,precedes:<
The list+listchars combo can show trailing spaces but not leading spaces.
You could try vim-indent-guide.

How can I delete a new line in Vim? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I join two lines in vi?
I have the following text:
the bunny
is very cute
How can I quickly delete the \n\t between bunny and is?
Type J (capital J) to join lines.

Resources