9

I have a file that is made up of two vertical parts. On the left side, the data is already formatted and I don't want to change it. I only want to format the data on the right side. Say I have a file with lines like

foo=bar baz     # Neato       Junk
quux=xyzzy      # Bilbo Baggins Ring

with many more lines like that. I only want to modify the text to the right of the '#' character. I selected the text I want with the following expressions:

gg
/#
ctrl-v
G
$

but if I then try to modify it (say, with :'<,'>!column -t), it actually modifies the entirety of every line. What is the correct expression to use to only modify the visually selected parts?

  • 2
    You could try the vis plugin from Dr. Chip or my NrrwRgn plugin. Both should handle it just fine. – Christian Brabandt Mar 16 '16 at 18:45
6

You can also try:

gg
^V
G
t#
d
:%!column -t
gg
P

From :h :visual_example:

Currently the ":" command works on whole lines only. When you select part of a line, doing something like ":!date" will replace the whole line. If you want only part of the line to be replaced you will have to make a mapping for it. In a future release ":" may work on partial lines.

See also :h visual-operators for details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.