Попробуйте это. Включите этот скрипт где-нибудь в вашем пути выполнения (см. :help runtimepath
). Простым вариантом было бы поместить его в ваш vimrc. Визуально выберите предмет, который вы хотите найти, и нажмите ,/
(ключ запятой, а затем клавишу прямой косой черты).
" Search for other instances of the current visual range
" This works by:
" <ESC> Cancel the visual range (it's location is remembered)
"/ Start the search
" <C-R>= Insert the result of an expression on
" the search line (see :help c_CTRL-R_=)
" GetVisualRange()<CR> Call the function created below
" <CR> Run the search
vmap ,/ <ESC>/<C-R>=GetVisualRange()<CR><CR>
" Create the function that extracts the contents of the visual range
function! GetVisualRange()
" Get the start and end positions of the current range
let StartPosition = getpos("'<")
let EndPosition = getpos("'>")
" Prefix the range with \V to disable "magic"
" See :help \V
let VisualRange = '\V'
" If the start and end of the range are on the same line
if StartPosition[1] == EndPosition[1]
" Just extract the relevant part of the line
let VisualRange .= getline(StartPosition[1])[StartPosition[2]-1:EndPosition[2]-1]
else
" Otherwise, get the end of the first line
let VisualRange .= getline(StartPosition[1])[StartPosition[2]-1:]
" Then the all of the intermediate lines
for LineNum in range(StartPosition[1]+1, EndPosition[1]-1)
let VisualRange .= '\n' . getline(LineNum)
endfor
" Then the start of the last line
let VisualRange .= '\n' . getline(EndPosition[1])[:EndPosition[2]-1]
endif
" Replace legitimate backslashes with double backslashes to prevent
" a literal \t being interpreted as a tab
let VisualRange = substitute(VisualRange, '\\[nV]\@!', '\\\\', "g")
" Return the result
return VisualRange
endfunction
А, я не знал об этом. Я бы сейчас не спасла меня от написания своего. Ах хорошо. Имеет большой смысл копировать визуальный выбор, а затем использовать Ctrl-R- "для доступа к нему. Я пытался (и, надеюсь, мне удалось) написать функцию, которая не зависит от сопоставления, но интересно посмотреть другой способ сделать это. – DrAl
+1 Это было приятное усилие. – LB40