how to search on the folded range in gvim? - vim

Here is the material to test the search function:
move cursor in the line 5
zfG to fold line 5 until the end of the file. (please see the
attachment1)
When I input ?case, I can get the attachment2
Now, let me add a line which contains only one word case in the first line, and fold line 6 until the end of the file too. When I input ?case, I can only get the line 1, can not search line7?
How can I search on the folded lines?
The following is the raw material to test:
Note the use of ( ) with the pipe symbol to specify the 'or' condition
/[0-9]*/MATches if there are zero or more numbers in the line
/^[^#]/ Matches if the first character is not a # in the line
Notes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specifiedYou can jump back to beginning of file by typing any one of the following command

Related

How to remove newlines from a group of n-consecutive lines in sublime text

I've a text file where each line contains a uuid within single quote followed by a comma. A sample of this file would look like the following:
'527a34922f3472506d93f393c1dd5cac',
'7bdce3215c3007ccfb3449702234a2b4',
'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce',
'b038091601beb11c00d28d8ea277cecb',
'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48',
'10d3d4c4aa0f162d5ab3a403010c2202',
'1103abf37755c8477f0177478a0f91cd',
...
I'm using Sublime Text 4, and I need to group every 3 lines and pull them into a single line. So, the output I'm expecting is:
'527a34922f3472506d93f393c1dd5cac', '7bdce3215c3007ccfb3449702234a2b4', 'b74d228b5c6dbfd95ac989eb7b4837ac',
'59c7694db4effe03984d05b43c46c1ce', 'b038091601beb11c00d28d8ea277cecb', 'c3b489c4b7526adb36b049c76c75835d',
'cfdf54d36262c474103fba5486f3fa48', '10d3d4c4aa0f162d5ab3a403010c2202', '1103abf37755c8477f0177478a0f91cd',
...
How do I achieve that? I could select every group of 3 lines using this command: ((.*\n){1, 3}), but not able to perform the grouping on each selection.
You can capture the body of every line and match the trailing newline of each, do this for 3 lines and replace them with the three lines separated by spaces instead, and end with another newline:
Find:
(.*)\n(.*)\n(.*)\n
Replace:
\1 \2 \3\n
Demo: https://regex101.com/r/lwmRCQ/1

Match on lines that have one string and NOT another

I am able to match strings in lines of a file like so:
re.search(r"\b10/100/1000\b", line) and re.search(r"notco*", line):
However, I need to be able to match lines that have one string, UNLESS they have another.
Example: Match pattern of '40G' unless the line also contains the pattern 'Po'
just negate the second search:
re.search("40G",line) and not re.search("Po",line)
if no need for regex, then ... no need for regex, use in:
"40G" in line and "Po" not in line

How to extract word from a sentence in Linux Shell?

I have a shell file with the below SQL statements in it:
SELECT distinct vpi.pin_id_e
FROM MSSINT.V_DSLAMS vd,
MSSINT.v_pin_inventory_old vpi
where vd.dslam like '%#%'
and vd.dslam_id = vpi.dslam_id ;
select pa.circuit_design_id,pa.node_address,c.exchange_carrier_circuit_id,c.type,c.rate_code,c.status
from ASAP.port_address pa,
asap.circuit c
where pa.equipment_id = 4561233 and pa.circuit_design_id is not null
and pa.circuit_design_id = c.circuit_design_id;
In the above content of my shell file, I have to extract the table or view names alone (those between from and where keywords).
I have seen a lot of suggestions to get words based on position, but I don't want those since they will not work like between operators.
awk 'toupper($0) ~ /^FROM/ { getline;flag=1 } toupper($0) ~ /^WHERE/ { flag=0 }flag' filename
With awk, convert the string to upper case and then pattern match against FROM at the beginning of the line. If this exists, read in the next line and set flag to one. When WHERE is encountered at the beginning of the line, set the flag equal to 0. The complete line will then only print when flag is set to one i.e. between the from and where lines

Substituting everything from = to end of the line in VIM

Let's say I have several lines like:
$repeat_on = $_REQUEST['repeat_on'];
$opt_days = $_REQUEST['opt_day'];
$opt_days = explode(",", $opt_days);
... and so on.
Let's say I use visual mode to select all the lines: how can I replace everything from = to the end of the line so it looks like:
$repeat_on = NULL;
$opt_days = NULL;
$opt_days = NULL;
With the block selected, use this substitute:
s/=.*$/= NULL;
The substitution regex changes each line by replacing anything between = and the end of the line, including the =, with = NULL;.
The first part of the command is the regex matching what is to be replaced: =.*$.
The = is taken literally.
The dot . means any character.
So .* means: 0 or more of any character.
This is terminated by $ for end of line, but this actually isn't necessary here: try it also without the $.
So the regex will match the region after the first = in each line, and replace that region with the replacement, which is = NULL;. We need to include the = in the replacement to add it back, since it's part of the match to be replaced.
When you have a block selected, and you hit : to enter a command, the command line will be automatically prefixed with a range for the visual selection that looks like this:
:'<,'>
Continue typing the command above, and your command-line will be:
:'<,'>s/=.*$/= NULL;
Which will apply the replacement to the selected visual block.
If you'll need to have multiple replacements on a single line, you'll need to add the g flag:
:'<,'>s/=.*$/= NULL;/g
Some alternatives:
Visual Block (fast)
On the first line/character do... Wl<C-v>jjCNULL;<Esc>bi<Space><Esc>
Macro (faster)
On the first line/character do... qqWllCNULL;<esc>+q2#q
:norm (fastest)
On the first line do... 3:no<S-tab> WllCNULL;<Enter>
Or if you've visually selected the lines leave the 3 off the beginning.

Add a number of '=' in a rest (reStructuredText) document that equals to characters from last line?

I want to use a shortcut to add needed = (from Section/Title reStructuredText syntax) according to the last line.
So, suppose (being | the cursor position)
Title
|
and pressing an specific mapping mapped to a function, add a number of = that equals to the last line (where Title is), becoming:
Title
=====|
This sequence will get you close:
kyyp:.s/./=/g
Duplicate the previous line, then in that line, change every character to an equals sign. Map that to a key sequence you like, and try it out.
Another way:
:execute "normal " . strlen(getline(line(".") - 1)) . "i="
strlen(getline(line(".") - 1)) returns the lenght of the line above the current position. The result is that the command Ni= is executed, inserting = N times.
For a mapping I would have used:
put=repeat('=', col('$')-1)
For something more interactive, I would have use the same solution as Ned's.
(I don't like my mappings to change the various registers like #" or #/)
My vim-rst-sections vim plugin will convert lines to section headings:
http://www.vim.org/scripts/script.php?script_id=4486
In your case, you'd put the cursor on the line, and type <leader><leader>d to get a top-level heading like this:
#####
Title
#####
A few repeats of <leader><leader>d will take you down to the standard hierarchy of Python ReST sections to the =.

Resources