Sunday, December 25, 2011

How to search from inside a function

Merry Christmas to all!

Hopefully anyone of you can help me with my latest problem:

I want to write a function that extends the behaviour of t.T.f and F,
so that the character-search does not stop at the end of the current line.

I just could not get it to work with the built in function search(),
because in order to emulate t<char> and T<char>,
I need to call /char/e-1, which I cant do using search().

So far I tried:

function! ExtendT(searchChar)
     " search does not accept the 'e-1':
     " search('/'.a:searchChar.'/e-1')
     " can't be passed as "flag" to search:
     " search(a:searchChar, "/e-1")
     " eval does not work:
     " eval '/'.a:searchChar.'/e-1'
     " exe doesn't work either:
     " execute '/'.a:searchChar.'/e-1'
endfunction

Anyway, I am unsure, if getting the above function to work and mapping it to e.g. t,
this will work as a movement-command in Vim?
So will I be able to do ct#
on the following (cursor-position is indicated by *):

This is l*ine one
and I want to change until here #.

Help will be much appreciated.
Santa Claus says, he provides the one presenting a solution
to this problem with a chocolate Vim-Statuette.
;-)

Have a nice Christmas and a Happy new year!
Kind regards!
Asis

--
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:

Post a Comment