Re: missing functions in visincr.vim [Was: Re: Changing a long list of entries with corresponding index]
Charles E Campbell Jr wrote: Gerald Lai wrote: I have a new question: When trying to do :IDMY, I find that I am missing both these functions Jul2Cal() Cal2Jul() AFAIK, there doesn't seem to be any extra required plugin file to run visincr.vim. Is something missing? Yes -- both my website and the vim.sf.net page mention that if you want to use the calendrical incrementing that you need calutil.vim, which is available at my website: http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Calendar Utilities") Regards, Chip Campbell
missing functions in visincr.vim [Was: Re: Changing a long list of entries with corresponding index]
I've had time to explore visincr.vim in detail today. As a result, please disregard both my questions below. For question 2, zfill IS a leading pad. I misunderstood this at first. For question 1, I now understand why the default zfill is set to a space " " character. It's because the default :II behavior of right-aligning numbers should be apparent, by padding spaces. Since I'd like to change this default, I've modified the line in visincr.vim: let zfill= ' ' to become let zfill= '' Now I can use :II if I don't wish to pad anything to the numbers. I can also specify zfill should I need a right-align, but that is rare. I have a new question: When trying to do :IDMY, I find that I am missing both these functions Jul2Cal() Cal2Jul() AFAIK, there doesn't seem to be any extra required plugin file to run visincr.vim. Is something missing? Thanks :) -- Gerald -- Forwarded message -- Date: Wed, 7 Jun 2006 23:18:38 -0700 (PDT) From: Gerald Lai <[EMAIL PROTECTED]> To: Charles E Campbell Jr <[EMAIL PROTECTED]> Cc: vim@vim.org Subject: Re: Changing a long list of entries with corresponding index On Wed, 7 Jun 2006, Charles E Campbell Jr wrote: Gerald Lai wrote: Visincr pads trailing spaces as the number of characters needed to represent the end number increases. What I mean is, for the above example, we will be left with: cities[0 ] = ... . . cities[2039] = ... Could it be made to pad nothing? Or, in addition, even leading zeros/spaces/other characters? Also, are there plans for incrementing/decrementing hex & octal? As of v13, a zfill of '' or "" will work to "pad nothing": :[visual-block range]II 1 "" You may use other characters, too. As of v14b, the :IX (and :IIX) commands do hexadecimal incrementing. I haven't done octal (yet). Guess that'll be :[visual-block range]IO (and IIO). Version v14b is available at my website: http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs as "Visual Incrementing". Thanks! I'll install it on my next update cycle. Keep up the good work :) 1. Can (and should) zfill be made into a global option? I'd imagine most people would prefer to "pad nothing". 2. How about leading zfills? For example: cities[] = ... cities[0001] = ... . . cities[2039] = ... -- Gerald
Re: Changing a long list of entries with corresponding index
On Wed, 7 Jun 2006, Charles E Campbell Jr wrote: Gerald Lai wrote: Visincr pads trailing spaces as the number of characters needed to represent the end number increases. What I mean is, for the above example, we will be left with: cities[0 ] = ... . . cities[2039] = ... Could it be made to pad nothing? Or, in addition, even leading zeros/spaces/other characters? Also, are there plans for incrementing/decrementing hex & octal? As of v13, a zfill of '' or "" will work to "pad nothing": :[visual-block range]II 1 "" You may use other characters, too. As of v14b, the :IX (and :IIX) commands do hexadecimal incrementing. I haven't done octal (yet). Guess that'll be :[visual-block range]IO (and IIO). Version v14b is available at my website: http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs as "Visual Incrementing". Thanks! I'll install it on my next update cycle. Keep up the good work :) 1. Can (and should) zfill be made into a global option? I'd imagine most people would prefer to "pad nothing". 2. How about leading zfills? For example: cities[] = ... cities[0001] = ... . . cities[2039] = ... -- Gerald
Re: Changing a long list of entries with corresponding index
Gerald Lai wrote: Visincr pads trailing spaces as the number of characters needed to represent the end number increases. What I mean is, for the above example, we will be left with: cities[0 ] = ... . . cities[2039] = ... Could it be made to pad nothing? Or, in addition, even leading zeros/spaces/other characters? Also, are there plans for incrementing/decrementing hex & octal? As of v13, a zfill of '' or "" will work to "pad nothing": :[visual-block range]II 1 "" You may use other characters, too. As of v14b, the :IX (and :IIX) commands do hexadecimal incrementing. I haven't done octal (yet). Guess that'll be :[visual-block range]IO (and IIO). Version v14b is available at my website: http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs as "Visual Incrementing". Regards, Chip Campbell
Re: Changing a long list of entries with corresponding index
On Tue, 6 Jun 2006, Charles E Campbell Jr wrote: Salman Mohsin wrote: I have a long list of city names (more than 2,000 of them) in a file, each name on a separate line. I'd like to modify each line so that: ABERFOYLE . . ZURICH Becomes: cities[0] = "ABERFOYLE" . . cities[2039] = "ZURICH" Is there a way I could issue a command (or some commands) and achieve the above? The way I'd do it is to use a simple substitute and visincr.vim: :[range]s/^.*$/cities[0]= "&" (goto the first 0 in the first cities[0] line, enter visual-block mode) ctrl-v (goto the last 0 in the last cities[0] line) :I Visincr.vim will transform the visual-block column of zeros into an incremented list. You can get visincr.vim from: http://vim.sourceforge.net/scripts/script.php?script_id=670 or the most up-to-date one from http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Visual Incrementing"). visincr.vim also supports date, dayname, monthname, and alphameric incrementing. Chip, Visincr pads trailing spaces as the number of characters needed to represent the end number increases. What I mean is, for the above example, we will be left with: cities[0 ] = ... . . cities[2039] = ... Could it be made to pad nothing? Or, in addition, even leading zeros/spaces/other characters? Also, are there plans for incrementing/decrementing hex & octal? -- Gerald
Re: Changing a long list of entries with corresponding index
Salman Mohsin wrote: I have a long list of city names (more than 2,000 of them) in a file, each name on a separate line. I'd like to modify each line so that: ABERFOYLE . . ZURICH Becomes: cities[0] = "ABERFOYLE" . . cities[2039] = "ZURICH" Is there a way I could issue a command (or some commands) and achieve the above? The way I'd do it is to use a simple substitute and visincr.vim: :[range]s/^.*$/cities[0]= "&" (goto the first 0 in the first cities[0] line, enter visual-block mode) ctrl-v (goto the last 0 in the last cities[0] line) :I Visincr.vim will transform the visual-block column of zeros into an incremented list. You can get visincr.vim from: http://vim.sourceforge.net/scripts/script.php?script_id=670 or the most up-to-date one from http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Visual Incrementing"). visincr.vim also supports date, dayname, monthname, and alphameric incrementing. Regards, Chip Campbell
Re: Changing a long list of entries with corresponding index
On Tue, 6 Jun 2006, Gary Johnson wrote: On 2006-06-06, Salman Mohsin <[EMAIL PROTECTED]> wrote: Hi, I have a long list of city names (more than 2,000 of them) in a file, each name on a separate line. I'd like to modify each line so that: ABERFOYLE . . ZURICH Becomes: cities[0] = "ABERFOYLE" . . cities[2039] = "ZURICH" Is there a way I could issue a command (or some commands) and achieve the above? :%s/.*/\='cities['.line(".").'] = "'.submatch(0).'"' The key here is the "\=" in the replacement string. See :help sub-replace-expression You can't mix replacement expressions with other forms of replacement string. That is, the replacement must start with \= and everything that follows must be part of that expression. Using an expression allows the use of functions such as line() to interpolate the current line number. "submatch(0)" returns the entire string matched by the pattern. See :help line() :help submatch() Adding to this, let's say you have ABERFOYLE on line 5, and ZURICH on line 2044, then this would do what you want: :5,2044s/.*/\='cities['.(line(".") - 5).'] = "'.submatch(0).'"' -- Gerald
Re: Changing a long list of entries with corresponding index
On 2006-06-06, Salman Mohsin <[EMAIL PROTECTED]> wrote: > Hi, > > I have a long list of city names (more than 2,000 of them) in a file, each > name on a separate line. I'd like to modify each line so that: > > ABERFOYLE > . > . > ZURICH > > Becomes: > > cities[0] = "ABERFOYLE" > . > . > cities[2039] = "ZURICH" > > Is there a way I could issue a command (or some commands) and achieve the > above? :%s/.*/\='cities['.line(".").'] = "'.submatch(0).'"' The key here is the "\=" in the replacement string. See :help sub-replace-expression You can't mix replacement expressions with other forms of replacement string. That is, the replacement must start with \= and everything that follows must be part of that expression. Using an expression allows the use of functions such as line() to interpolate the current line number. "submatch(0)" returns the entire string matched by the pattern. See :help line() :help submatch() HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Wireless Division | Spokane, Washington, USA
Changing a long list of entries with corresponding index
Hi, I have a long list of city names (more than 2,000 of them) in a file, each name on a separate line. I'd like to modify each line so that: ABERFOYLE . . ZURICH Becomes: cities[0] = "ABERFOYLE" . . cities[2039] = "ZURICH" Is there a way I could issue a command (or some commands) and achieve the above? Thanks, Salman