Vim-script: How to produce an error if there is semicolon in buffer?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Vim-script: How to produce an error if there is semicolon in buffer?

Igor Forca
Hi,
using Vim 8 on Windows 7. I have written simple script that does some janitor in my config files. Tiding works fine.

I execute this script by executing keyboard shortcut: leader + r
So the following is in my vimrc file:
:nnoremap <leader>r :source $HOME\vimfiles\myscript.vim<CR>

In myscript.vim is all of the janitor work.

So far no problem. Now what I see if there is a semicolon (one or many) in my current buffer, then janitor work (executing myscript.vim) should not be performed.

How to do something like:
if semicolon-in-my-file == true
then in-status-bar-report-an-error and exit myscript.vim
else execute the rest of the myscript.vim to do the janitor work.

Thanks

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Vim-script: How to produce an error if there is semicolon in buffer?

Christian Brabandt

On Fr, 23 Jun 2017, Igor Forca wrote:

> Hi,
> using Vim 8 on Windows 7. I have written simple script that does some janitor in my config files. Tiding works fine.
>
> I execute this script by executing keyboard shortcut: leader + r
> So the following is in my vimrc file:
> :nnoremap <leader>r :source $HOME\vimfiles\myscript.vim<CR>
>
> In myscript.vim is all of the janitor work.
>
> So far no problem. Now what I see if there is a semicolon (one or many) in my current buffer, then janitor work (executing myscript.vim) should not be performed.
>
> How to do something like:
> if semicolon-in-my-file == true
> then in-status-bar-report-an-error and exit myscript.vim
> else execute the rest of the myscript.vim to do the janitor work.

At the beginning of your myscript.vim put something like

if search(';', 'nw') > 0
     echomsg "Warning HERE"
     finish
endif


You could also use :echoerr


Best,
Christian
--
Nehmen Sie die Menschen, wie sie sind, andere gibt's nicht.
                -- Konrad Adenauer

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Vim-script: How to produce an error if there is semicolon in buffer?

Igor Forca
Christian,
thanks a lot for you help. It works excellent. I just replaced the "echo" part to get an error in red color.

if search(';', 'nw') > 0
    echohl Error
    echomsg "Warning. Semicolon in file."
    echohl None
    finish
endif

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...