If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
regexp syntax to make two search-&-replace into one search-&-replace please!
May be you can help on gvim regexp syntax to get 1 command to work?
The problem is to convert 4 character in one regexp command! This is four character convert which is what I want to do in 1 command! convert open single quote d145 to straight single quote d39 (') convert close single quote d146 to straight single quote d39 (') convert open double quote d147 to straight double quote d34 (") convert close double quote d148 to straight double quote d34 (") The "digraph" percent sign (%) only work one at a time. open single quote (d145) to straight single quote (d39) - :%s/\%d145/'/g close single quote (d146) to straight single quote (d39) - :%s/\%d146/'/g open double quote (d147) to straight double quote (d34) - :%s/\%d147/"/g close double quote (d148) to straight double quote (d34) - :%s/\%d148/"/g I can not get the syntax correct to do all 4 conversion at once! The "\d" make the 4 command above to 2 command (nice!!!!!) open/close single quote to straight single quote - :%s/[\d145,\d146]/'/g open/close double quote to straight double quote - :%s/[\d147,\d148]/"/g But I can not understand yet syntax to make above to 1 command! May be you can help on gvim regexp syntax to get 1 command to work? |
Ads |
#2
|
|||
|
|||
regexp syntax to make two search-&-replace into one search-&-replace please!
On Sun, 9 Sep 2018 11:26:10 +0900, Doyun Jahng wrote:
May be you can help on gvim regexp syntax to get 1 command to work? The problem is to convert 4 character in one regexp command! This is four character convert which is what I want to do in 1 command! convert open single quote d145 to straight single quote d39 (') convert close single quote d146 to straight single quote d39 (') convert open double quote d147 to straight double quote d34 (") convert close double quote d148 to straight double quote d34 (") The "digraph" percent sign (%) only work one at a time. open single quote (d145) to straight single quote (d39) - :%s/\%d145/'/g close single quote (d146) to straight single quote (d39) - :%s/\%d146/'/g open double quote (d147) to straight double quote (d34) - :%s/\%d147/"/g close double quote (d148) to straight double quote (d34) - :%s/\%d148/"/g I can not get the syntax correct to do all 4 conversion at once! The "\d" make the 4 command above to 2 command (nice!!!!!) open/close single quote to straight single quote - :%s/[\d145,\d146]/'/g open/close double quote to straight double quote - :%s/[\d147,\d148]/"/g But I can not understand yet syntax to make above to 1 command! May be you can help on gvim regexp syntax to get 1 command to work? I'm not sure gvim can actually do a conditional replacement using a single regular expression. IME, only programming languages can do it. |
#3
|
|||
|
|||
regexp syntax to make two search-&-replace into one search-&-replace please!
Doyun Jahng wrote:
May be you can help on gvim regexp syntax to get 1 command to work? The problem is to convert 4 character in one regexp command! This is four character convert which is what I want to do in 1 command! convert open single quote d145 to straight single quote d39 (') convert close single quote d146 to straight single quote d39 (') convert open double quote d147 to straight double quote d34 (") convert close double quote d148 to straight double quote d34 (") The "digraph" percent sign (%) only work one at a time. open single quote (d145) to straight single quote (d39) - :%s/\%d145/'/g close single quote (d146) to straight single quote (d39) - :%s/\%d146/'/g open double quote (d147) to straight double quote (d34) - :%s/\%d147/"/g close double quote (d148) to straight double quote (d34) - :%s/\%d148/"/g I can not get the syntax correct to do all 4 conversion at once! The "\d" make the 4 command above to 2 command (nice!!!!!) open/close single quote to straight single quote - :%s/[\d145,\d146]/'/g open/close double quote to straight double quote - :%s/[\d147,\d148]/"/g But I can not understand yet syntax to make above to 1 command! May be you can help on gvim regexp syntax to get 1 command to work? This is a job for the Vim-script tr() function, not for regexp. http://vimdoc.sourceforge.net/htmldoc/usr_41.html#string-functions http://vimdoc.sourceforge.net/htmldoc/eval.html#tr() https://stackoverflow.com/questions/25665318/vim-equivalent-of-the-tr-command |
Thread Tools | |
Display Modes | |
|
|