Monday, December 3, 2018

Re: I need to fool vim to think buffer starts at column n

On 2018-12-03 17:40, Magnus Woldrich wrote:
> I'd like to stop vim from modifying the first n columns of a
> buffer, no matter what I do in it.
>
> Consider the following data, where the number isn't vims internal
> line numbers, but actual data:
>
> 50 ./bin/
> 51 ./cgi/
> 52 ./dev/
> 53 ./devlaleh/
> 54 ./emu/
> 55 ./etc/
>
> Now, I'd want to perform any action in this buffer, for example a
> simple:
>
> :%s/ /_/
>
> and I need vim to *think* that the buffer starts at column 9.

While I'm not sure there's any generic "protect this column", you can
tweak your substitute command to have it ignore the first nine
characters:

:%s/\%>9c /_/g

which you can read more about at

:help /\%c

(there are nuances regarding "/\%c" vs. "/\%v" depending on
virtual-column aspects)

Alternatively, if it's harder to do, you can enter visual block mode,
select all of columns 1-9, delete it to a named register, do whatever
modifications you need to, then paste it back in.

-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.

No comments:

Post a Comment