Thursday, April 9, 2015

norm in a global command not working in script

Hi,

A global command that executes a normal command doesn't seem to work always as expected when executed from a script but works fine when executed on the current buffer.

In this example I would like to execute a global command to take the multiline text that is returned on next lines and bring it back on the same line as the MyMultilineTextField

So instead of having:

MyMultilineTextField = alsdfjlasdjflksdjlf
asldjflaskdfjasdjflasjkdf
asdlkflaskdfjasdjfjasdkfjklsd
alsdflkasdfjksdjklf

I would have

MyMultilineTextField = alsdfjlasdjflksdjlf asldjflaskdfjasdjflasjkdf asdlkflaskdfjasdjfjasdkfjklsd alsdflkasdfjksdjklf

So for each line that are multitext lines that are not on the MyMultilineTextField line, do norm kJ to bring it back to the field's line, using a command line:

g!/ = /norm kJ

MySingleLineTextField = testalsdkflkasdf
MyMultilineTextField = alsdfjlasdjflksdjlf
asldjflaskdfjasdjflasjkdf
asdlkflaskdfjasdjfjasdkfjklsd
alsdflkasdfjksdjklf

MySingleLineTextField = 2308230982309weofsf
MyMultilineTextField = asljf9u3f92jfj23fio32jfio3j2iojf23
asdfisdjafjs09fjsdf09sdj0f
as0dfj0asdj0fasd0j9fas09dfj09sdj0f9sdjf

So to test the differences, create these functions below and paste the same test text above to a new buffer and save it as test.txt.

fu! g:Gn()
g!, = ,norm kJ
endfu

fu! g:Gon()
exe 'split test.txt'
g!, = ,norm kJ
endfu

Then to open the test.txt file using the command 'edit test.txt', and call the function g:Gn() like this 'call g:Gn()', the text should be formatted correctly and multiline text should be all on the same field.

The don't save the file and close it and run the function g:Gon() like this 'call g:Gon()', now the lines will not be formatted correctly and some multiline text will still be on their line.

I have found another way of accomplishing my task, but I find it unfortunate that the norm command cannot be use reliably inside the global command in a script, such a command in scripts would be very powerful and make text processing very easy.

If somebody could help to understand how to make this work or to confirm this is a bug and could file it this would be great, I would appreciate.

Thank you very much,

Alexandre

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