Friday, June 23, 2017

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

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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: