On 2019-04-10 10:42, Igor Forca wrote:
> Hi,
>
> Sample data:
> aaa bbb:123:ccc ddd
>
> Desired result:
> aaa ddd
>
> What is the quickest way to replace second WORD with spaces?
>
> Now I use several keystrokes:
> fb - find letter b
> vaW - visual also WORD
> r<Space> - replace with space
>
> I know I can set a mapping like pressing minus key and do the task:
> noremap - vaWr<Space>
>
> but I am doing a lot of SSH, so don't want to mess with mappings on
> each of server.
>
> What is the quickest way to replace WORD with spaces in vanilla Vim
> settings?
It would depend on how manual the process is (is the "fb" portion
different every time? Is it always the 2nd column? Is it only the
2nd column on certain rows that a regex could identify?) and how many
you have to do.
If it's manually searching without any way to identify them by
row/pattern/column, then you're kinda stuck with pretty manual
solutions. It's not that hard to do something like at least
:noremap <space> vaWr<space>
and then hit <space> on germane matches.
If, however, you can identify them predictably, then you can
substitute with an expression:
s/\S\+/\=repeat(' ', strlen(submatch(0)))
So in your case you might have
%s/^\S*\s\+\zs\S*/\=repeat(' ', strlen(submatch(0)))
to nuke the 2nd column with spaces. Or do them on just certain lines
that match a pattern like "ddd":
:g/ddd/s/^\S*\s\+\zs\S*/\=repeat(' ', strlen(submatch(0)))
Hope this gives you some ideas,
-tim
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wednesday, April 10, 2019
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment