Saturday, December 26, 2015

Re: New in VIM

Thanks Paolo and Tony for your help.

I have tried this way maped to F7 so it works comment/uncomment

function Comment()
let currentLine = getline(".")
let result = match(currentLine, "^\#~ ") " here is the problem
if result >= 0
" Uncomment, delete "#~ "
else
" Comment, write "#~ " at ^ of line.
endif
endfunction

The problem is: (from :help /~)
~ matches the last given substitute string */~**/\~*

I can't find the way to match ~ without errors.

This is because I also use Geany, it has comment/uncomment with "#~ " but I
will use only "# " if I can find how to match() it in the current line.

Thanks a lot. Cheers.

--
Jose Angel Navarro Cortes
email: janc@telefonica.net
web: http://janc.es/
Usuario Linux: #49178

El 15.12.26 07:11:52 > Tony Mechelynck dijo:
> Even ^#\~ works for me: the # doesn't need backslash-escaping
>
> Let's say (assuming # is the start-comment delimiter)
>
> function Comment() range
> exe a:firstline ',' a:lastline 's/^\ze\~/#/'
> endfunction
>
> function Uncomment() range
> exe a:firstline ',' a:lastline 's/^#\ze\~//'
> endfunction
>
> Then use these functions by using the :call command with a range (or
> from Visual mode, which will pass '<,'> as the range to execute the
> function on the selected lines). For the whole file, use :%call or
> :1,$call
>
> See
> :help /~
> :help /\
> :help /\ze
> :help :func-range
> :help :call
> :help v_:
> :help :range
>
>
> Best regards,
> Tony.
>
> On Sat, Dec 26, 2015 at 5:54 AM, Paolo Bolzoni
> <paolo.bolzoni.brown@gmail.com> wrote:
> > ^\#\~ works fine to me, what is the problem?
> >
> > On Sat, Dec 26, 2015 at 4:39 AM, janc@telefonica.net
> > <janc@telefonica.net> wrote:
> >> Hi! all.
> >>
> >> I am almost newbie about VIM and every day I like it more and more.
> >>
> >> I am try to make a function to comment/uncomment lines with "#~ " at ^ of line.
> >>
> >> But I can not find the regex to search "#~ " at ^ of line, I think I have tried
> >> almost every posibilities.
> >>
> >> Can you help me? Thank in advanced.
> >>
> >> --
> >> Jose Angel Navarro Cortes
> >> email: janc@telefonica.net
> >> web: http://janc.es/
> >> Usuario Linux: #49178
> >>
> >> --
> >> --
> >> 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.
>
> --
> --
> 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: