После того как Вы завершили обработку с помощью StringBuilder, используйте метод ToString для возврата конечного результата.
Из MSDN:
using System;
using System.Text;
public sealed class App
{
static void Main()
{
// Create a StringBuilder that expects to hold 50 characters.
// Initialize the StringBuilder with "ABC".
StringBuilder sb = new StringBuilder("ABC", 50);
// Append three characters (D, E, and F) to the end of the StringBuilder.
sb.Append(new char[] { 'D', 'E', 'F' });
// Append a format string to the end of the StringBuilder.
sb.AppendFormat("GHI{0}{1}", 'J', 'k');
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
// Insert a string at the beginning of the StringBuilder.
sb.Insert(0, "Alphabet: ");
// Replace all lowercase k's with uppercase K's.
sb.Replace('k', 'K');
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
}
}
// This code produces the following output.
//
// 11 chars: ABCDEFGHIJk
// 21 chars: Alphabet: ABCDEFGHIJK
As an ex one-liner:
:syn clear Repeat | g/^\(.*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' | nohlsearch
This uses the Repeat
group to highlight the repeated lines.
Breaking it down:
syn clear Repeat
:: remove any previously found repeatsg/^\(.*\)\n\ze\%(.*\n\)*\1$/
:: for any line that is repeated later in the file
^\(.*\)\n
:: a full line\ze
:: end of match - verify the rest of the pattern, but don't consume the matched text (positive lookahead)\%(.*\n\)*
:: any number of full lines\1$
:: a full line repeat of the matched full lineexe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"'
:: add full lines that match this to the Repeat
syntax group
exe
:: выполнить заданную строку как команду ex getline ('.')
:: содержимое текущей строки, совпадающее с g //
escape ( ..., '". \ ^ $ * []')
:: экранировать заданные символы с помощью обратной косой черты, чтобы обеспечить правильное совпадение регулярного выражения syn. Повторить" ^ ... $ "
:: add заданную строку в синтаксическую группу Repeat
nohlsearch
:: удалить выделение из поиска, выполненного для g //
Метод Джастина без регулярных выражений, вероятно, быстрее:
function! HighlightRepeats() range
let lineCounts = {}
let lineNum = a:firstline
while lineNum <= a:lastline
let lineText = getline(lineNum)
if lineText != ""
let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
endif
let lineNum = lineNum + 1
endwhile
exe 'syn clear Repeat'
for lineText in keys(lineCounts)
if lineCounts[lineText] >= 2
exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
endif
endfor
endfunction
command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
Почему бы не использовать:
V*
в нормальном режиме.
Он просто ищет все совпадения в текущей строке, выделяя их, таким образом, выделяя их (если параметр включен, что, я думаю, это значение по умолчанию) Кроме того, вы можете затем использовать
n
для навигации по совпадениям
Просмотрите список один раз, составьте карту каждой строки и того, сколько раз она встречается. Прокрутите его снова и добавьте * к любой строке, которая имеет значение более одного на карте.
Попробуйте:
:%s:^\(.\+\)\n\1:\1*\r\1:
Надеюсь, это сработает.
Обновление: следующая попытка.
:%s:^\(.\+\)$\(\_.\+\)^\1$:\1\r\2\r\1*: