Reputation: 174
I want to delete 5 characters starting from column 11 in the whole file. When I type
11|5x
it works for the line the cursor is on. But when I type
:g/.*/11|5x
the editor closes.
How should I use the g command properly?
Upvotes: 2
Views: 399
Reputation: 1716
The normal |
motion bring the cursor to a screen column, which may not be expected when you have multi-column characters like <Tab>
in a line.
Substitution globally like below can avoid this problem:
%s/\%10c.\{5}/
, in which \%10c
matches the column position of the 10th character.
Upvotes: 0
Reputation: 172510
Understanding Vi(m) modes is key to mastering it.
The |
command to jump to a screen column is a normal mode command, but the :global
command takes Ex commands. The :normal
Ex commands interprets following arguments as normal mode commands (with !
: without considering mappings (which is safer)):
:g/.*/normal! 11|5x
PS: A shorter "match anywhere" pattern for :g
is ^
instead of .*
.
Upvotes: 7