Monday, March 23, 2015

Re: How to execute Vim commands from commands.vim file to my text mydata.txt file?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On March 23, 2015 4:11:09 PM EAT, Igor Forca <igor2x@gmail.com> wrote:
>Hi,
>using Vim 7.4 on Windows 7. I have a text file mydata.txt where is the
>text. I need to execute Vim commands on this data to transform data in
>file to my desired content. Because data in mydata.txt file is changed
>very frequently I would like to store Vim commands in separate file
>e.g. commands.vim and then execute those commands on mydata.txt file.
>
>Searching the web and the only solution that I have come into was the
>following.
>
>1. Save bellow comment to commands.vim file:
>===============
>:%s/ship/vessel/ge
>:%s/What/That/ge
>
>for line in getline(1, 2)
> let @a = line
> @a
>endfor

I am wondering what you are trying to achieve with this cycle. If the rest of the file does what you want just remove it because it is useless and potentially harmful.

Note that here you are trying to execute first two lines *of the file you edit*. **Not** of the commands.vim file.

>===============
>
>2. Save bellow content to mydata.txt file.
>===============
>This is one big ship. What ship?
>===============
>
>3. Open mydata.txt file with Vim and execute command:
>:source commands.vim
>
>4. The result after executed above command is:
>===============
>This is one big vessel. That vessel?
>===============
>
>This is exactly what I want as a result in mydata.txt file, but what I
>don't like is I get the following error:
>===============
>Error detected while processing C:\commands.vim file:
>line 6:
>E492: Not an editor command: This is one big vessel. That vessel?
>===============
>
>Is there a way to avoid the error message? Commands.vim file does what
>I want, but how to remove annoying error?
>Thanks

-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQI1BAEBCgAfBQJVECdFGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
HhHSvnsDD/0baRrunK/2v3MxH+th+aUm3a4R6zQBIl+rLASEBgaFEGepwr+fHQJl
HvSS0FdUx2skv+zRbjYHzYlSQJfEDRLf7TVkD8sMCmasDSnRdgJSIGxx85bh8uqc
aLbUju0edTD76AHMbj7SBZc8Tog0kxla5dLGWLTUzSAZ75JiAp+BWu0dbub9Esql
I4L1gYpSY/6oVHibxh0oMvYy6ty2gLOsPS/kTkuTlTHtjNnwneE+70Q+gSSphnXn
sLAe0FY9VLAjwMk/UgPjHxwzOsrOBGyivCmsvCuP6AmAEm2/rb1cMVouZFpOL6FC
YYzfFX6SzIlL8j30sC3DBHSjnwzYB41ctNJH6pTYyibUEqe7j4cB1vMXMziltAhT
QluG3vtZBMyJx7k+9CpoQarfLDPIRnAWfLnAEm4J32ndVcMmJDFgPJc04SgjKcGx
86nVbFuILjIl2HC0B5klJtRAq6kVuiBzqzz5lfvHv+O/RFsJJn2WgmsnbvkOyXb5
q4s64/biF6FQNFrqH6ECDDuEAQusU2JC1+ZxDBj01ynvEpPVf3YGsQiyqhQYPC9w
UcYcKAQpPyho4IA7NZB9Gnb3bKH4MwD5ocJYvR/83uKuy7WHTvLD72eHwE0/xbOA
uSkL3+tXym3Uk0JDs//sH7KRkABstsO66dQUQKkkY5f4OEvlbF739A==
=UEpJ
-----END PGP SIGNATURE-----

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