Monday, August 8, 2016

Re: VimScript tips needed

2016-08-08 20:44 GMT+03:00 Arun <aemails@gmail.com>:
> On Mon, Aug 8, 2016 at 12:11 AM, Marc Weber <marco-oweber@gmx.de> wrote:
>>
>> :h search() -> there is an option to not change cursor position or such
>> is an option as well
>>
>
> Just to add to the above point, to check if the pattern is in current line,
> you either do:
>
> let match_line = search('<patt>', 'cnW')

search() is affected by &ignorecase, &smartcase and (!)&magic. So it ought to be

let match_line = search('\C\m<patt>', 'cnW')

>
> and..
>
> if match_line == line('.')

`==#`, not `==`. Do not use such operators for string comparison.

> "Do something
> endif
>
>
> or can even form a complex search pattern, like
>
> let match_line = search('\%'.line('.').'l<patt>', 'c')
>
>
> ..where the cursor is placed at the match if "match_line" is non-zero.
> "\%<line-num>l" is a special pattern to look for a match on a specific line.
> There are other variants too, see
>
> :help \%l
>
>
> Another tip, almost always, you want to use ":normal!" (with a !) inside a
> function, instead of ":normal". The former would not use mappings (:map) for
> the characters following it.
>
> --Arun
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment