Re: How to search a match on a line and then make a change on the next line?

2020-05-13 Thread Tony Mechelynck
On Thu, May 14, 2020 at 5:38 AM boB Stepp  wrote:
>
> I am relatively new to using regex pattern matching techniques to search for 
> and
> replace text.  Today I have been trying to get a better mastery of these
> techniques.  But I am currently stumped on the following text search and
> replace:
>
> # Home address fields:
> # field address STANDARD FIELD -- CANNOT EDIT!
> # field address2 STANDARD FIELD -- CANNOT EDIT!
> pobox = "PO Box", string
> # field city STANDARD FIELD -- CANNOT EDIT!
> # field state STANDARD FIELD -- CANNOT EDIT!
> # field zip STANDARD FIELD -- CANNOT EDIT!
> # field country STANDARD FIELD -- CANNOT EDIT!
>
> # Work address fields:
> field work_address = Address, string
> field work_address2 = Address2, string
> pobox = "PO Box", string
> field work_city = City, string
> field work_state = State, string
> field work_zip = Zipcode, string
> field work_country = Country, string
>
> # Other address fields:
> field other_address = Address, string
> field other_address2 = Address2, string
> pobox = "PO Box", string
> field other_city = City, string
> field other_state = State, string
> field other_zip = Zipcode, string
> field other_country = Country, string
>
> In the above I want to change the lines starting with "pobox" to match the
> format of the line above it, e.g., "field pobox", "field work_pobox" and
> "field other_pobox", respectively.  My best effort so far to do this is:
>
> :g/\(field [[:alnum:]_]*\)address2/+s/pobox/\1pobox/
>
> My current understanding (flawed though it is) feels that this command
> should do the trick, but it doesn't; instead, it highlights the three
> instances of "pobox" and says that it has made three changes without
> visibly changing anything.  It is as if "\1" is not storing anything.
> What I _think_ the above command is doing is:
>
> 1) Search globally and find each line that has the string "field  more alphanumeric characters or underline>address2".
>
> 2) Store the above strings in "\1" which I should be able to use in the
> replacement string to follow.
>
> 3) Advance to the next line with "+".
>
> 4) Search on this line for the string "pobox".
>
> 5) Replace that instance with "pobox".
>
> What am I misunderstanding?
>
> --
> Wishing you only the best,
>
> boB Stepp

I would do that with a macro, as follows (starting from Normal mode): (untested)
0. Go to top of file:
gg
1. Start recording into register q:
qq
2. Search for "pobox" as a full word starting in column 1:
/^pobox\>
(where ^ is a real spacing circumflex and  means "Hit Enter")
3. Go to previous line
k
4. Visually mark characterwise until but not including "addr"
v/.\zeaddr
5. Yank the current visual selection (cursor goes back to column 1)
y
6. Go to next line
j
7. Put before
P
8. End recording
q
9. Repeat what we just recorded until we cannot:
@q

(Use a higher count if you have more than 10,000 sections in the file.)


Best regards,
Tony.

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CAJkCKXtwrzjpy7nDFvPM7FW5BqoRb2ku7sah5CJuhr2Fsk5eDA%40mail.gmail.com.


How to search a match on a line and then make a change on the next line?

2020-05-13 Thread boB Stepp

I am relatively new to using regex pattern matching techniques to search for and
replace text.  Today I have been trying to get a better mastery of these
techniques.  But I am currently stumped on the following text search and
replace:

# Home address fields:
# field address STANDARD FIELD -- CANNOT EDIT!
# field address2 STANDARD FIELD -- CANNOT EDIT!
pobox = "PO Box", string
# field city STANDARD FIELD -- CANNOT EDIT!
# field state STANDARD FIELD -- CANNOT EDIT!
# field zip STANDARD FIELD -- CANNOT EDIT!
# field country STANDARD FIELD -- CANNOT EDIT!

# Work address fields:
field work_address = Address, string
field work_address2 = Address2, string
pobox = "PO Box", string
field work_city = City, string
field work_state = State, string
field work_zip = Zipcode, string
field work_country = Country, string

# Other address fields:
field other_address = Address, string
field other_address2 = Address2, string
pobox = "PO Box", string
field other_city = City, string
field other_state = State, string
field other_zip = Zipcode, string
field other_country = Country, string

In the above I want to change the lines starting with "pobox" to match the
format of the line above it, e.g., "field pobox", "field work_pobox" and
"field other_pobox", respectively.  My best effort so far to do this is:

:g/\(field [[:alnum:]_]*\)address2/+s/pobox/\1pobox/

My current understanding (flawed though it is) feels that this command
should do the trick, but it doesn't; instead, it highlights the three
instances of "pobox" and says that it has made three changes without
visibly changing anything.  It is as if "\1" is not storing anything.
What I _think_ the above command is doing is:

1) Search globally and find each line that has the string "field address2".

2) Store the above strings in "\1" which I should be able to use in the
replacement string to follow.

3) Advance to the next line with "+".

4) Search on this line for the string "pobox".

5) Replace that instance with "pobox".

What am I misunderstanding?

--
Wishing you only the best,

boB Stepp

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20200514033806.GD7019%40Dream-Machine1.


Re: Runtime of record/play feature

2020-05-13 Thread Manas
Hi, I was recently working on a large CSV file in Vim. I needed to do 
some changes in the file and I utilized the recording feature for it. 
Recording feature is really awesome and worked well for my use case.


However working on a file whenever applied on multiple lines, it is slow 
till the point where we can actually see the edit being done on every line.


I would like to know why is it so slow? Has it something to do with the 
design pattern?


Also, is there any consideration of making it faster (if possible)?

--
Manas
Computer Science Undergrad.
IIIT-Delhi 2022

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/24a4b266-2795-613f-0aa2-2745e2d4dd36%40iiitd.ac.in.


Re: Vim9 - Python/Lua interface

2020-05-13 Thread Andrey Butirsky

On 5/13/20 21:05, Bram Moolenaar wrote:

Clearly there are more plugin writers using Vim script than
anything else.

Maybe it's chicken and the egg problem? :)

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/a26dc414-b62e-55d7-4e4e-63d68339fde5%40gmail.com.


Re: executing gvim from within a C program

2020-05-13 Thread Tony Mechelynck
On Wed, May 13, 2020 at 10:28 PM Lucien Gentis  wrote:
>
> Hello,
>
> Distro : Debian 10 - 64bits
>
> I think it's the right list ; if not, please redirect me.

It is.
>
> In order to launch a command from within the C programme in attachment, I use 
> "fork - execve - wait" trio so that parent program waits until command has 
> finished
>
> Building the program : cc execve.c -o execve
>
> Program syntax : ./execve 
>
> Example : ./execve /usr/bin/gvim
>
> The problem :
>
> --- if I execute "./execve /usr/bin/gvim", gvim starts after a few seconds 
> but without executing .vimrc, and parent program doesn't wait for gvim to end.
>
> Output of "ps -auwx --forest" during the few wait seconds :
>
> lgentis   5216  0.0  0.0   7124  3812 pts/0Ss   14:47  0:00  \_ bash
> lgentis   9368  0.0  0.0   2144   752 pts/0S+   16:44  0:00  |   \_ 
> ./execve /usr/bin/gvim
> lgentis   9369  2.0  0.2  68916 16452 pts/0S+   16:44   0:00  |   \_ 
> gvim
> lgentis   9392  2.5  0.3  71620 22444 ?Ss   16:44  0:00  |
>\_ gvim
>
> Output of "ps -auwx --forest" once gvim started :
>
> lgentis   5212  0.1  0.7 426212 43880 ?Rl   14:470:07 
> xfce4-terminal
> lgentis   5216  0.0  0.0   7124  3812 pts/0Ss+  14:47   0:00  \_ bash
> lgentis   9093  1.3  0.4  75804 26700 ?Ss   16:36 0:00 gvim
>
> We can see that  gvim is not a child process of the parent program (which has 
> ended)

see :help -f

>
> --- if I execute "./execve /usr/bin/vim.gtk", vim starts in text mode in the 
> console ; however, parent program waits till vim is closed.
>
> Output of "ps -auwx --forest"  :
>
> lgentis   5212  0.0  0.7 426212 43880 ?Rl   14:47  0:06 
> xfce4-terminal
> lgentis   5216  0.0  0.0   7124  3812 pts/0Ss   14:47  0:00  \_ bash
> lgentis   9011  0.0  0.0   2144   748 pts/0S+   16:34  0:00  |   \_ 
> ./execve /usr/bin/vim.gtk
> lgentis   9012  0.8  0.2  68932 17232 pts/0S+   16:34   0:00  |   \_ 
> vim.gtk
>
>  We can see that  vim.gtk is a child process of the parent program
>
> --- I did the same test with gedit and audacious, and all works fine :  child 
> program is executed and parent program waits as expected.
>
> Output of "ps -auwx --forest" :
>
> lgentis   5212  0.0  0.7 425664 43548 ?Sl   14:47   0:05 
> xfce4-terminal
> lgentis   5216  0.0  0.0   7124  3812 pts/0Ss   14:47   0:00  \_ bash
> lgentis   8910  0.0  0.0   2144   748 pts/0S+   16:30   0:00  |   \_ 
> ./execve /usr/bin/gedit
> lgentis   8911  4.2  0.7 477720 47812 pts/0Sl+  16:30   0:00  |   \_ 
> gedit
>
> We can see that  gedit is a child process of the parent program



Best regards,
Tony.

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CAJkCKXt4s3BQ60Rj0byX8OpSEMVKm-d6r8Be0wGKmGzcP%2BKn7A%40mail.gmail.com.


Highlighting c-like for-loops in bash

2020-05-13 Thread Hakim Benoudjit


Hi,


I wasn't sure if this was a bug or not, so I've updated my Vim version to 
8.2 on Ubuntu 18.04.

And, as you can see below, the variables in the standard for-loop aren't 
highlighted as they are in the following for loop:


[image: screenshot.png] 


-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/90f2172a-314c-4155-9d58-fac57d3650d9%40googlegroups.com.


executing gvim from within a C program

2020-05-13 Thread Lucien Gentis

Hello,

Distro : Debian 10 - 64bits

I think it's the right list ; if not, please redirect me.

In order to launch a command from within the C programme in attachment, 
I use "fork - execve - wait" trio so that parent program waits until 
command has finished


Building the program : cc execve.c -o execve

Program syntax : ./execve 

Example : ./execve /usr/bin/gvim

*The problem* :

--- if I execute "./execve /usr/bin/gvim", gvim starts after a few 
seconds but without executing .vimrc, and parent program doesn't wait 
for gvim to end.


Output of "ps -auwx --forest" during the few wait seconds :

lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47 0:00  \_ bash
lgentis   9368  0.0  0.0   2144   752 pts/0    S+   16:44 0:00  |   \_ 
./execve /usr/bin/gvim
lgentis   9369  2.0  0.2  68916 16452 pts/0    S+   16:44   0:00 |   
\_ gvim
lgentis   9392  2.5  0.3  71620 22444 ?    Ss   16:44 0:00  
|   \_ gvim


Output of "ps -auwx --forest" once gvim started :

lgentis   5212  0.1  0.7 426212 43880 ?    Rl   14:47    0:07 
xfce4-terminal

lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss+  14:47   0:00  \_ bash
lgentis   9093  1.3  0.4  75804 26700 ?    Ss   16:36 0:00 gvim

We can see that  gvim is not a child process of the parent program 
(which has ended)


--- if I execute "./execve /usr/bin/vim.gtk", *vim* starts in text mode 
in the console ; however, parent program waits till vim is closed.


Output of "ps -auwx --forest"  :

lgentis   5212  0.0  0.7 426212 43880 ?    Rl   14:47 0:06 
xfce4-terminal

lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47 0:00  \_ bash
lgentis   9011  0.0  0.0   2144   748 pts/0    S+   16:34 0:00  |   \_ 
./execve /usr/bin/vim.gtk
lgentis   9012  0.8  0.2  68932 17232 pts/0    S+   16:34   0:00 |   
\_ vim.gtk


 We can see that  vim.gtk is a child process of the parent program

--- I did the same test with gedit and audacious, and all works fine :  
child program is executed and parent program waits as expected.


Output of "ps -auwx --forest" :

lgentis   5212  0.0  0.7 425664 43548 ?    Sl   14:47 0:05 
xfce4-terminal

lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47 0:00  \_ bash
lgentis   8910  0.0  0.0   2144   748 pts/0    S+   16:30 0:00  |   \_ 
./execve /usr/bin/gedit
lgentis   8911  4.2  0.7 477720 47812 pts/0    Sl+  16:30   0:00 |   
\_ gedit


We can see that  gedit is a child process of the parent program

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/33f1ec41-bcaa-c77c-408d-9d16643a6b5e%40waika9.com.
/* execve.c */

#include 
#include 
#include 
#include 
#include 

// argv[1] doit contenir le chemin complet du programme à lancer (/usr/bin/gvim par exemple)
int main(int argc, char *argv[]) {

	char *newargv[5];
	char *newenviron[5];
	newargv[0] = basename(argv[1]);
	newargv[1] = NULL;
	newenviron[0] = "DISPLAY=:0.0";
	newenviron[1] = NULL;
	pid_t  pid;

	// Clonage du parent
	pid = fork();

	if (pid == 0) {
		// On est dans le clone
		// Remplacement du clone par la commande shell ou le programme
		execve (argv[1],newargv,newenviron );
	} else {
		// On est dans le parent
		// On attend la fin du programme
		wait(NULL);
		puts ("This is a message from the parent");
	}
		
}



Re: Vim9 - Python/Lua interface

2020-05-13 Thread rameo
Thank you for your comment.
That is good news.
Glad to hear.

I read about the new features in vim9 here:
https://www.reddit.com/r/vim/comments/ey91bd/i_have_mixed_feelings_for_vim9_script_what_do_you/

and here:
https://github.com/brammool/vim9
(2. Phasing out Interfaces)

Would be great to use python regex in the command line. 
Hopefully it'll work out. I'm also thinking of a way to leave python 
functions just like in vimscript (return).

On Wednesday, May 13, 2020 at 12:54:19 PM UTC+2, rameo wrote:
>
> I first came into contact with Vim about 15 years ago.
> A few times I uninstalled it and reinstalled it a while later. After a few 
> months I was convinced it was the best text editor I had ever seen.
> I only noticed how much value it had when I wrote scripts in vimrc myself 
> and changed plugins/menu.
> Still, I had to get used to Vimscript. A whole new language, not something 
> similar I already knew.
> However, I got completely excited when I understood that I could write 
> scripts in Lua and Python.
> Why? Because it was not easy to get used to Vimscript and the help I asked 
> on internet sites was rarely answered.
> Anyway, I did benefit from the vim_use group but I noticed that I found 
> solutions faster writing in Python. 
> I knew the language better and there was a huge amount of information 
> online.
>
> Now I recently read on Reddit that there would be some changes in Vim9 and 
> not everyone thought it was a good idea.
> Vimscript is going to change in Vim9 to make Vim respond faster. That's a 
> good idea, although Vim is fast enough for me. The fastest editor I've ever 
> seen.
> Reading further I read that Vim9 will be without its Python/Lua interface.
> That is really a pity. 
> Instead of removing the Python and Lua interface, why not integrate them 
> even more?
> It would be great if we could search in Vim with python regex.
> Even if we could program the user input in python code.
> People often already know Python and Lua. I think it will bring a much 
> larger amount of users to Vim.
>
> Is it true that the Python and Lua interface will disappear?
>

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/714c7efa-bc1b-4b4d-b010-c742f4cb40e6%40googlegroups.com.


Re: Vim9 - Python/Lua interface

2020-05-13 Thread Bram Moolenaar


> I first came into contact with Vim about 15 years ago.
> A few times I uninstalled it and reinstalled it a while later. After a few 
> months I was convinced it was the best text editor I had ever seen.
> I only noticed how much value it had when I wrote scripts in vimrc myself 
> and changed plugins/menu.
> Still, I had to get used to Vimscript. A whole new language, not something 
> similar I already knew.
> However, I got completely excited when I understood that I could write 
> scripts in Lua and Python.
> Why? Because it was not easy to get used to Vimscript and the help I asked 
> on internet sites was rarely answered.
> Anyway, I did benefit from the vim_use group but I noticed that I found 
> solutions faster writing in Python. 
> I knew the language better and there was a huge amount of information 
> online.
> 
> Now I recently read on Reddit that there would be some changes in Vim9 and 
> not everyone thought it was a good idea.
> Vimscript is going to change in Vim9 to make Vim respond faster. That's a 
> good idea, although Vim is fast enough for me. The fastest editor I've ever 
> seen.
> Reading further I read that Vim9 will be without its Python/Lua interface.
> That is really a pity. 

Not sure what gave you that idea.  We don't plan to do much work on
these interfaces, but they are certainly not going away.  I suggested to
remove the least used one, Scheme, and immediately got objection from a
few people.  Python is widely used, and some people like Lua.  Might
also help for people who come from Neovim, which did some more Lua
stuff.  Otherwise Lua isn't widely used and it doesn't appear to grow:
https://trends.google.com/trends/explore?date=today%205-y=IT=%2Fm%2F0chpd,%2Fm%2F0n50hxv,%2Fm%2F05z1_

> Instead of removing the Python and Lua interface, why not integrate them 
> even more?
> It would be great if we could search in Vim with python regex.
> Even if we could program the user input in python code.
> People often already know Python and Lua. I think it will bring a much 
> larger amount of users to Vim.

This has existed as an idea for a long time, but nothing much has
happened.  Clearly there are more plugin writers using Vim script than
anything else.
 
> Is it true that the Python and Lua interface will disappear?

No.

-- 
I AM THANKFUL...
...for all the complaining I hear about the government
because it means we have freedom of speech.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/202005131805.04DI5CsL021855%40masaka.moolenaar.net.


Vim9 - Python/Lua interface

2020-05-13 Thread rameo
I first came into contact with Vim about 15 years ago.
A few times I uninstalled it and reinstalled it a while later. After a few 
months I was convinced it was the best text editor I had ever seen.
I only noticed how much value it had when I wrote scripts in vimrc myself 
and changed plugins/menu.
Still, I had to get used to Vimscript. A whole new language, not something 
similar I already knew.
However, I got completely excited when I understood that I could write 
scripts in Lua and Python.
Why? Because it was not easy to get used to Vimscript and the help I asked 
on internet sites was rarely answered.
Anyway, I did benefit from the vim_use group but I noticed that I found 
solutions faster writing in Python. 
I knew the language better and there was a huge amount of information 
online.

Now I recently read on Reddit that there would be some changes in Vim9 and 
not everyone thought it was a good idea.
Vimscript is going to change in Vim9 to make Vim respond faster. That's a 
good idea, although Vim is fast enough for me. The fastest editor I've ever 
seen.
Reading further I read that Vim9 will be without its Python/Lua interface.
That is really a pity. 
Instead of removing the Python and Lua interface, why not integrate them 
even more?
It would be great if we could search in Vim with python regex.
Even if we could program the user input in python code.
People often already know Python and Lua. I think it will bring a much 
larger amount of users to Vim.

Is it true that the Python and Lua interface will disappear?

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/a7593c48-e393-4f55-820e-83036c37b7fb%40googlegroups.com.