Text::Editor::Vip::Buffer::Plugins::FindReplace- Find and replace functionality plugin for Vip::Buffer
is_deeply([$buffer->FindOccurence('1', 0, 0)], [0, 5, '1'], 'Found occurence 1') ; is($buffer->GetText(), $text, 'Text still the same') ; is($buffer->GetSelectionText(), '', 'GetSelectionText empty') ; #FindNextOccurence $buffer->SetModificationPosition(0, 0) ; is_deeply([$buffer->FindNextOccurence()], [0, 5, '1'], 'FindNextOccurence') ; $buffer->SetModificationPosition(0, 5) ; is_deeply([$buffer->FindNextOccurence()], [0, 9, '1'], 'FindNextOccurence') ; # FindNextOccurenceForCurrentWord $buffer->SetModificationPosition(0, 0) ; is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [1, 0, 'line'], 'FindNextOccurenceForCurrentWord') ; $buffer->SetModificationPosition(1, 0) ; is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [2, 0, 'line'], 'FindNextOccurenceForCurrentWord') ; $buffer->SetModificationPosition(4, 0) ; is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [undef, undef, undef], 'FindNextOccurenceForCurrentWord') ; # Regex search is_deeply([$buffer->FindOccurence(qr/..n[a-z]/, 0, 0)], [0, 0, 'line'], 'Found occurence with regex') ;
Find and replace functionality plugin for Vip::Buffer
Finds the text matching the regex argument starting at the line and character arguments. If no line argument is passed, the modification position is used.
This sub returns an array containing: ($match_line, $match_position, $match_word)
The Selection is not modified by this sub. To set the modification at the match position:
my ($match_line, $match_position, $match_word) = $buffer->FindOccurence($regex, $line, $character) ; if(defined $match_line) { $buffer->SetModificationPosition($match_line, $match_position + length($match_word)) ; $buffer->{SELECTION}->Set($match_line, $match_position,$match_line, $match_position + length($match_word)) ; }
Finds the text matching the regex argument within tha passed boundaries starting at the line and character arguments. If no line argument is passed, the modification position is used.
Arguments:
search regex, a perl qr or a string
start_line (boundary)
start_character (boundary)
end_line (boundary)
end_character (boundary)
line, where to start looking
character, where to start looking
This sub returns an array containing: ($match_line, $match_character, $match_word)
The Selection an the current modification position are not modified by this sub.
$buffer->FindOccurenceWithinBoundaries('line', @boundaries) ;
Find the next occurence matching the search regex.
Finds the next occurence for the word at the modification position.
Searches for the regex going backwards in the buffer. Intricate regexes might not work.
Searches for the next occurence going backwards in the buffer
Finds the previous occurence for the word at the modification position.
Finds a match for the search_regex argument and replaces it with the replacement.
replacement, a regex, a string or a sub reference (see bellow)
line, where to start looking, optional
character, where to start looking, optional
If line or character are undefined or invalid, the current modification position is used.
Valid boudaries must be passed to this sub or it will return undef. No replacement is done if the searched regex doesn't match within the boudaries.
This sub returns an array containing: ($match_line, $match_position, $match_word, $replacement)
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'replacement') ;
if the replacement is a regex, parenthesis can be be used to assign $1, $2, ..
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'xx$1', @boundaries) ;
the buffer
matching line
matching character
the match
the sub returns a string which will be be inserted at the matching position.
sub replacement_sub { my($buffer, $match_line, $match_character, $match_word) = @_ ; join(', ', ref($buffer), $match_line, $match_character, $match_word, "\n") ; } $buffer->ReplaceOccurenceWithinBoundaries('match_this', \&sub_reference, @boundaries)
replacement, a regex, string or sub reference
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'xx$1') ;
sub replacement_sub { my($buffer, $match_line, $match_character, $match_word) = @_ ; join(', ', ref($buffer), $match_line, $match_character, $match_word, "\n") ; } $buffer->ReplaceOccurenceWithinBoundaries('match_this', \&sub_reference)
Khemir Nadim ibn Hamouda CPAN ID: NKH mailto:nadim@khemir.net http:// no web site
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install Text::Editor::Vip, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Editor::Vip
CPAN shell
perl -MCPAN -e shell install Text::Editor::Vip
For more information on module installation, please visit the detailed CPAN module installation guide.