Thursday, August 4, 2011

Re: How to find visually selected string in different file

* Ashwin V [2011.08.04 00:20]:
> Hi,
> I am trying to
> In a open file sim.log.
> 1) Visually select a string ( with white space)
> 2) Split open ~/project/string_file_list and Search this string in
> this new open file.
> 3) map this operation to some key binding.
>
> I could not find any help on web related to this.

function! SearchInOtherFile()
let l:other_file="string_file_list"
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let @/ = l:pattern
let @" = l:saved_reg
exe "split " . l:other_file
normal n
endfunction

vnoremap <silent> <F8> :call SearchInOtherFile()<cr>

Adjust to taste.

HTH,

--
JR

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: