Comments (28)
Well, I can only say this is done intentionally since v8.1.0690. The idea probably was that once you replace a line, all attached properties to it may no longer be valid, which I think makes sense.
from vim.
Although it was intentional, I can not see the advantage of it, but lots of disadvantages. Because I can not prevent the text properties defined by my plugin from being removed by others which use setline()
.
I don't think it make sense that the text property is removed after call setline(line('.'), getline('.'))
, the text is not changed in the user's view.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovim, where extmarks in neovim is equivalent to text property in vim.
from vim.
from vim.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovim, where extmarks in neovim is equivalent to text property in vim.
I don't see how this relates to Vim. We don't have this: nvim_buf_set_extmark()
.
from vim.
looks it make sense if the text was changed. but I am curious you said the by D then it would be remained?
…
-- shane.xb.qian
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
from vim.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovim, where extmarks in neovim is equivalent to text property in vim.
I don't see how this relates to Vim. We don't have this:
nvim_buf_set_extmark()
.
I mean in neovim's point of view, setline
should not remove text property just like setline
does not remove extmarks.
Another reason current behavior is thought to be buggy is : setline
also removes zero-width text property.
Lines 509 to 517 in c52a856
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
from vim.
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think this is essentially what setline does. It deletes the line and replaces it with a new one, even if it is empty.
from vim.
Maybe this can be made configurable as a flag of text properties? Similar to neovim/neovim#25767 but in the opposite way.
from vim.
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think this is essentially what setline does. It deletes the line and replaces it with a new one, even if it is empty.
Is it not the same with :
norm! 0D
then append some text ?
I think the whole line is deleted is like: norm! dd
. setline just need to replace the content of the specified line of buffer.
from vim.
I rather thought of making the behaviour of setline() configurable.
from vim.
I rather thought of making the behaviour of setline() configurable.
How it would solve the issue then? There still will be setline()
calls that would remove text properties:
Because I can not prevent the text properties defined by my plugin from being removed by others which use setline().
I think removal of text properties as of current implementation is expected.
from vim.
I think removal of text properties as of current implementation is expected.
Yes, that is also my expectation, see also:
Lines 534 to 538 in c52a856
it looks like even :move
drops the text properties.
There still will be setline() calls that would remove text properties
Well, would you expect the text-property to be still there after doing
:5d
:4put ='foobar'
? Once you remove the line and add a new line, how would do you know the attached text-property attached to that line is still valid?
from vim.
from vim.
looks it make sense if the text was changed. but I am curious you said the by D then it would be remained? > … > -- shane.xb.qian
vim call prop_type_add('aaa', {'highlight': 'Number'}) call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
not sure whyD
was special.. // if delete by :delete, then it was removed too.
…
-- shane.xb.qian
It is different.
:delete is the same as dd
, not D
from vim.
yes, it is different, but the answer maybe as @chrisbra commented above, to D
maybe it was intended to make it happy with instant edit. 🤷
from vim.
I think removal of text properties as of current implementation is expected.
Yes, that is also my expectation, see also:
Lines 534 to 538 in c52a856
it looks like even
:move
drops the text properties.There still will be setline() calls that would remove text properties
Well, would you expect the text-property to be still there after doing
:5d :4put ='foobar'
? Once you remove the line and add a new line, how would do you know the attached text-property attached to that line is still valid?
Actually, my expectation is :
for example,
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
call setline(line('.'), '')
has the same effect as norm! 0D
.
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 1, {'type':'aaa', 'length': 0})
call setline(line('.'), '')
has the same effect as norm! 0D
.
Because However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think setline is not delete line 3 and insert a new line after line 2, it is replacing line 3 with new text. Am I right?
from vim.
unless the whole line is deleted
it was said for D
😅
from vim.
unless the whole line is deleted
it was said forD
😅
I think it's dd
from vim.
i meant that statement was expressed why D
was special.
from vim.
I posted the link to the documentation already. It's simply not possible to retain the text property, because how should Vim know where you added some text?
call setline(1, 'You are a hero!')
cal prop_type_add('Highlight', #{highlight: 'Search'})
call prop_add(1, 11, {'end_col': 15, 'type': 'Highlight'})
" doesn't work, but would add an off by one error
call getline(1)->substitute('\<a\>', 'my', 'g')->setline(1)
from vim.
Notice that my example is special, one is virtual text, the column is 0, another is 0-width.
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 1, {'type':'aaa', 'length': 0})
:call setline(line('.'), '')
will remove the virtual text, :norm! 0D
won't.
Can we make their behavior the same?
from vim.
:call setline(line('.'), '') will remove the virtual text, :norm! 0D won't.
Can we make their behavior the same?
If properties wouldn't be removed, then a lot of things would need to be changed internally...
You have a text property, then you changed a line and now it is invalid.
from vim.
Now if the case is virtual text at the edges of the line -- it could be safe to preserve it, although I am not sure it worth the complexity it brings.
from vim.
from vim.
Can we make their behavior the same?
the 'question' had been answered above.
…
-- shane.xb.qian
I don't think so.
from vim.
I would also expect setline()
and setbufline()
to remove any text-properties.
I think what you want is something like subbufline()
that substitutes text in a line while preserving text-properties in that line, similar to the :substitute
command. There's already an open feature request for #5632. Bram wasn't opposed to this idea, it just needs to be implemented. 😄
from vim.
In my view, :call setline(line('.'), '')
and :norm! 0D
do the same thing, why :norm! 0D
don't remove the virtual-text column starts from 0 and the 0-width text property?
from vim.
The effect might be the same, but it is not the same, it's essentially a :d
followed by a :put
.
There is also listener_add()
not sure, if one can use it to save and restore text-properties.
The current behaviour is well documented, so let's close this as a duplicate of #5632 then.
from vim.
Related Issues (20)
- :Termdebug returns E1012: Type mismatch (expected string got list<string>) if g:termdebugger set HOT 8
- vim.vim: Outermost _foreign_ comments after :endfun _or_ :endef are not recognised HOT 1
- The execution result of enum variable in `==` is incorrect in vim9script HOT 6
- cursormovedc didnot work when c-w or c-u HOT 13
- let g:netrw_liststyle = 2 clobbers registers HOT 8
- Built in full vim syntax support for Podman Quadlet unit files
- [vim9class] `echo obj` puts vim into infinite loop requiring force kill
- [vim9class] incorrect type checking modifying list in class from outside class
- The `ps` output is truncated in the terminal HOT 4
- xxd.exe is detected by an awful lot of virus scanners HOT 5
- Fuzzy completion does not allow cycle back to original, wrong highlight, and Ctrl-P Ctrl-N issues HOT 1
- Add `get({func}, 'arity')` to determine the number of expected arguments to a funcref
- Termdebug: use conpty with Windows. HOT 3
- mousemodel=popup not working properly with many items on PopUp menu
- manpager.vim emits a "Changing a readonly file" error/warning
- foldexpr '<1' results in a level-3 fold HOT 2
- Clarification on expected behavior of <S-CR>
- A correction to the docs
- Clipboard and primary selection registers not working despite +clipboard HOT 7
- incsearch option to highlight matches without moving the cursor HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim.