2016-08-08 17:01 GMT+03:00 Tumbler Terrall <kingdombound13@gmail.com>:
>
>> if ( line ) {
>> if ( line =~ a:pattern ) {
>> # do something
>> }
>> else {
>> # do something else
>> }
>> }
>> }
>> endfun
>>
>> FindPattern( '=>\\s?{' )
>
>
> I feel like I'm breaking some rule by posting here without my name being some form of Mark. :)
>
> No offence, but this code is riddled with syntax errors. You're using c like syntax instead of vimscript. Here's a cleaned up version:
>
> function FindPattern( pattern )
> let line = getline('.')
>
> if ( line =~ a:pattern )
Never use `=~`/`!~`, `<`/`>`/`<=`/`>=` and `==`/`!=` for string
comparison, there are more predictable versions with `#` or `?`
appended (i.e. `=~#` in this case, versions with `?` are needed very
rarely). Also it is rather uncommon to use `if ( condition )` in VimL,
usually it is just `if condition`.
> " do something
> else
> " do something else
> endif
> endfunction
>
> "And the regex needs a little bit of work too:
>
> call FindPattern( '=>\s\?{' )
>
> I would probably use '=>\s*{' but either could work depending on the situation.
>
> --
> --
> 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.
Monday, August 8, 2016
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment