[email protected] schrieb:
> Hi,
>
> with CTRL-* one can search and jump to the next occurrence of what is
> under the cursor.
>
> When I have two windows (in my case often of the same buffer) can I do
> the same but let the execution happen in the other window? With other
> words: In the current window the cursor's position shall be kept, in
> the other window it is moved to the occurrence of the searched word?
>
> Thank You for hints!
> Felix
" search word under cursor in other window
nmap <C-W>* <Plug>StarAltWin
" " uncomment this whole block for the (basic) version without tinymode
"
" nn <silent> <Plug>StarAltWin :<C-U>call StarAltWin()<bar>set hls<lt><CR>
"
" func! StarAltWin()
" let word = expand("<cword>")
" let @/ = escape(word, '\.*$^~[')
" if winnr("$") < 2
" echohl ErrorMsg
" echo "StarAltWin: no other window"
" echohl None
" return
" elseif winnr("#")<1 || winnr("#")==winnr()
" noa wincmd w
" else
" noa wincmd p
" endif
" try
" normal! nzv
" catch /:E486:/
" " pattern not found
" echohl ErrorMsg
" echo printf("StarAltWin: Pattern not found in window %d: %s",
" \ winnr(), @/)
" echohl None
" endtry
" noa wincmd p
" endfunc
"
" finish
" Tinymode Version
" http://vim.sf.net/scripts/script.php?script_id=2223
"
" - Within the mode, you can press "n" and "N" to search for the
" next/previous match in the alternate window, possibly with count.
" - match positions are made visible with 'cul' and 'cuc'
" - no ModeMsg() to not overwrite the cmdline area
" - highlighting vanishes automatically afterwards
call tinymode#EnterMap("staraltwin", "<Plug>StarAltWin", "n")
call tinymode#ModeArg("staraltwin", "entercmd", 'call StarAltWin("init")')
call tinymode#Map("staraltwin", "n", 'call StarAltWin("next", [N])|redraw')
call tinymode#Map("staraltwin", "N", 'call StarAltWin("prev", [N])|redraw')
call tinymode#ModeArg("staraltwin", "leavecmd", 'call StarAltWin("leave")')
call tinymode#ModeArg("staraltwin", "owncount", 1)
call tinymode#ModeArg("staraltwin", "timeoutlen", 10000)
call tinymode#ModeArg("staraltwin", "timeoutonce", 1)
func! StarAltWin(cmd, ...)
let nextcmd = "n"
let cnt = ""
if a:cmd == "init"
let word = expand("<cword>")
let @/ = escape(word, '\.*$^~[')
let s:did_other_win_err = 0
elseif a:cmd == "leave"
else
if a:cmd == "prev"
let nextcmd = "N"
endif
if a:0 >= 1
let cnt = a:1
endif
endif
if winnr("$") < 2
if !s:did_other_win_err
echohl ErrorMsg
echo "StarAltWin: no other window"
echohl None
endif
let s:did_other_win_err = 1
return
elseif winnr("#")<1 || winnr("#")==winnr()
noa wincmd w
else
noa wincmd p
endif
try
if a:cmd == "init"
setl cursorline cursorcolumn
elseif a:cmd == "leave"
setl nocursorline nocursorcolumn
else
exec "normal!" cnt. nextcmd. "zv"
endif
catch /:E486:/
" pattern not found
echohl ErrorMsg
echo printf("StarAltWin: Pattern not found in window %d: %s",
\ winnr(), @/)
echohl None
endtry
noa wincmd p
endfunc
" "AltWin" for alternate window
" :h ctrl-w_p
" help talks about the "previous" window, but the shortcut "PrevWin" can
" be misinterpreted as "preview window".
" TODO
" - save/restore 'cursorline', 'cursorcolumn'
" - cleanup, don't switch windows two times on "init"
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---