On Saturday, August 2, 2014 4:48:42 AM UTC-5, sinbad wrote:
> hi,
>
> i'm trying to write a vim function to generate the
> following output. first of all why is it so difficult
> to ptint text into the buffer, i thought vim will
> have a simple printf() command which can dump the text
> into the buffer, but after googling a lot i found that
> append() is the function i should use. so i wrote the
> following function.
>
> 1.2.3.4
> 1.2.4.5
> 1.2.5.6
> 1.2.6.7
> 1.2.7.8
> 1.2.8.9
> 1.2.8.11
>
> 1. how do i print the numbers in hex, even though i used '%x'
> it doesn seem to be working.
>
What doesn't work about it? You only showed output for ma=1. 1 in hexadecimal is still just 1. Maybe you wanted "0x%02x" as your format specifier instead, to force 2 digits and put the 0x at the front?
> 2. why the output is displayed in reverse order , i was expecting
> 1.2.1.1 to come first.
>
Because "append" isn't changing the current line. You are placing each new line in turn after the same line. Thus the last one placed will always be one line below the current line.
Fix this by moving down a line after every append(), or adding an offset to the line number used in your append() function call.
> 3. and even though i set the 'setf vim' whey doesn't vim
> recognize that this is vim script and indent it properly.
>
> func! Test()
> let ma=0x1
> let mb=0x1
>
> while ma<20
> while mb<20
> call append(line('.'), "1.2.".printf("%x", ma).":".mb)
> let mb+=1
> endwhile
> let ma+=1
> endwhile
> endfunc
>
Maybe you don't have filetype indentation turned on? Is "filetype plugin indent on" in your .vimrc?
>
> actual output of above function:
>
> 1.2.1.19
> 1.2.1.18
> 1.2.1.17
> 1.2.1.16
> 1.2.1.15
> 1.2.1.14
> 1.2.1.13
> 1.2.1.12
> 1.2.1.11
> 1.2.1.10
> 1.2.1.9
> 1.2.1.8
> 1.2.1.7
> 1.2.1.6
> 1.2.1.5
> 1.2.1.4
> 1.2.1.3
> 1.2.1.2
> 1.2.1.1
>
> -sinbad
--
--
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:
Post a Comment