Friday, June 29, 2012

Re: It works but it doesn't work

On 2012-06-28, howard Schwartz wrote:
> I've got two simple ex commands in a larger script. When I run them
> on the file, direct from the ex command line, they work fine. When I
> run them from the script, they do not work. Even If I simply jut put
> the commands below in
> a simple script file, script.vim, enter my main file and execute
>
> :source script.vim <ENTER>
>
> The commands do not do their job on the file. Why would they work, if run
> directly, but not, if run within a script?
>
> set wrapscan
> "wrap long lines
> g/^.\{80,}$/gqgq
> "join hyphnated words at end of lines
> g/[^-]-\n/s/-\n\([^ ]*\)/\1 /

If you're using Windows, it could be that you are saving script.vim
with the DOS file format, i.e., with carriage-return/line-feed line
endings. When Vim sources such a file, it sees the carriage returns
at the ends of the lines as part of the lines and not as part of the
line terminators.

Open script.vim and execute

:set ff?

to determine the file format. If it's "dos", that could be the
problem. Execute

:set ff=unix
:w

to get rid of those carriage returns, then try sourcing your script
again.

HTH,
Gary

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

No comments: