codecompleting
codecompleting

Reputation: 9621

Replace all spaces with an underscore in the selected block

I want to replace all spaces with an underscore, in the currently highlighted block i.e. not to apply it on the entire page.

How can I do this?

Upvotes: 8

Views: 5839

Answers (2)

Ifthikhan
Ifthikhan

Reputation: 1474

You could go into visual mode (by typing v while in command mode) and then select the required text and thereafter enter the command mode (by typing ":"). This will automatically insert the selection range and then you could perform the necessary substitution.

  • Go to visual mode by typing v
  • Select the necessary text.
  • Type : to enter command mode. You would find in the prompt below :'<,'>
  • The final command would look like this :'<,'>s/ /_/g

Upvotes: 1

topek
topek

Reputation: 18979

When in visual mode type:

:s/\%V /_/g

see http://vim.wikia.com/wiki/VimTip438

Upvotes: 14

Related Questions