On 12/12/2009 05:12 AM, Hattori Hanzo wrote:
> Second thing: Now i have a file consisting of the header in the first line
> and sequence in the second line. For further processing i would like to
> again introduce "returns" after a defined number of characters, e.g.
49, 69.
Hello, David,
If you want all of the lines to have the same length (e.g., 49
characters), you can put your cursor on the line containing your
sequence and type the following characters:
:s/.\{49}/&\r/g
The above is a substitution that scans across the long line,
replacing each group of 49 characters with that group followed
by a return character. The command breaks down as follows:
:s/ - start a substitute command delimited by slashes
. - match any character
\{49} - match character 49 times instead of just once
/ - search pattern ends, replacement string begins
& - all characters that were matched by search pattern
\r - a "newline" or "return" character
/ - end of replacement string
g - repeat "globally" throughout this line
You can read more about these by using the :help command:
:help :s
:help pattern
:help /.
:help /\{
:help s/\&
:help s/\r
:help :s_flags
The above works if you want all of the lines to be the same
length. If you instead meant your example "49, 69" to mean
you want to split the long line into pairs of lines, first a
line with 49 characters followed by a line with 69 characters,
then 49 again, etc., the substitute command would be a little
different:
s/\(.\{49}\)\(.\{69}\)/\1\r\2\r/g
In this second example, grouping parentheses \(...\) are used to
capture 49 characters as group one and the next 69 characters as
group two. These two groups are replaced with themselves (\1 or
\2) followed by a newline.
The additional features are documented here:
:help /\(
:help s/\\1
Michael Henry
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php