Vim Tips Wiki
m (Save each line of a text in separated numbered files moved to Save each line in separate numbered files: Page moved by JohnBot to improve title)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1059
 
|id=1059
  +
|previous=1058
|title=Save each line of a text in separated numbered files
 
  +
|next=1061
|created=November 25, 2005 16:26
+
|created=November 25, 2005
 
|complexity=basic
 
|complexity=basic
|author=Walter L�pez
+
|author=Walter López
 
|version=6.0
 
|version=6.0
 
|rating=5/2
 
|rating=5/2
 
}}
|text=
 
Create this function
+
Create this function
  +
<pre>
 
function! SaveLines()
 
execute line(".") . "w " . line(".") . ".xml"
 
endf
  +
</pre>
   
 
And call it
  +
<pre>
 
%call SaveLines()
  +
</pre>
   
 
The generated files are:
   
  +
<pre>
function! SaveLines()
 
 
1.xml
 
 
2.xml
execute line(".") . "w " . line(".") . ".xml"
 
 
...
 
  +
</pre>
endf
 
 
 
 
And call it
 
 
 
 
%call SaveLines()
 
 
 
 
The generated files are:
 
 
1.xml
 
 
2.xml
 
 
...
 
 
 
   
 
each containing a single line.
 
each containing a single line.
}}
 
   
== Comments ==
+
==Comments==
 
No need for a function. You can just use
wow. just what we wanted
 
   
  +
<pre>
Dingo
 
 
:g/^/exe ".w ".line(".").".txt"
, November 25, 2005 23:39
 
  +
</pre>
----
 
No need for a function...you can just use
 
 
:g/^/exe ".w ".line(".").".txt"
 
   
 
to get the same sort of effect.
 
to get the same sort of effect.
   
 
Explanation:
vim.tip [at] the chases {dot} com
 
, November 26, 2005 5:55
 
----
 
:g/^/exe ".w ".line(".").".txt"
 
   
  +
<pre>
Explanation:-
 
:g/^/ &#35; for very line
+
:g/^/ # for very line
exe &#35; Execute the following string as an ex command ie :
+
exe # Execute the following string as an ex command ie :
   
.w &#35; . means current line so .w means write current line
+
.w # . means current line so .w means write current line
line(".") &#35; returns current line number
+
line(".") # returns current line number
   
The string generated (for first line is) is
+
The string generated (for first line is) is
 
:g/^/exe ".w 1.txt"
 
:g/^/exe ".w 1.txt"
  +
</pre>
   
zzapper
 
, November 28, 2005 9:15
 
----
 
Great, without the function is better to do. Thanks!!
 
 
wjlc--AT--internet.com.uy
 
, November 30, 2005 11:01
 
----
 
vim is better than gmacs
 
 
parth007--AT--yahoo.com
 
, December 2, 2005 22:38
 
 
----
 
----
<!-- parsed by vimtips.py in 0.576481 seconds-->
 

Revision as of 10:15, 20 December 2007

Tip 1059 Printable Monobook Previous Next

created November 25, 2005 · complexity basic · author Walter López · version 6.0


Create this function

function! SaveLines()
  execute line(".") . "w " . line(".") . ".xml"
endf

And call it

%call SaveLines()

The generated files are:

1.xml
2.xml
...

each containing a single line.

Comments

No need for a function. You can just use

:g/^/exe ".w ".line(".").".txt"

to get the same sort of effect.

Explanation:

:g/^/ # for very line
exe # Execute the following string as an ex command ie :

.w # . means current line so .w means write current line
line(".") # returns current line number

The string generated (for first line is) is
:g/^/exe ".w 1.txt"