Skip to main content
replaced http://vi.stackexchange.com/ with https://vi.stackexchange.com/
Source Link

I have a functionfunction that changes the 6th caracter of a line to a dollar symbol ($).

I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under).

But I have the feeling that there must be a much simpler, more "vim-esque" way to do that -- my function seems a bit complicated for such a simple task. Maybe I'm wrong, but I would appreciate any simplification/comments.

My current function is :

function! DollarSplit(nlines) let current_pos = getpos(".") let a:count = 0 while a:count < a:nlines normal! 6|r$j a:count += 1 endwhile call setpos(".", current_pos) endfunction 

I have a function that changes the 6th caracter of a line to a dollar symbol ($).

I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under).

But I have the feeling that there must be a much simpler, more "vim-esque" way to do that -- my function seems a bit complicated for such a simple task. Maybe I'm wrong, but I would appreciate any simplification/comments.

My current function is :

function! DollarSplit(nlines) let current_pos = getpos(".") let a:count = 0 while a:count < a:nlines normal! 6|r$j a:count += 1 endwhile call setpos(".", current_pos) endfunction 

I have a function that changes the 6th caracter of a line to a dollar symbol ($).

I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under).

But I have the feeling that there must be a much simpler, more "vim-esque" way to do that -- my function seems a bit complicated for such a simple task. Maybe I'm wrong, but I would appreciate any simplification/comments.

My current function is :

function! DollarSplit(nlines) let current_pos = getpos(".") let a:count = 0 while a:count < a:nlines normal! 6|r$j a:count += 1 endwhile call setpos(".", current_pos) endfunction 
Source Link
Feffe
  • 1.8k
  • 2
  • 15
  • 21

Call function on several lines

I have a function that changes the 6th caracter of a line to a dollar symbol ($).

I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under).

But I have the feeling that there must be a much simpler, more "vim-esque" way to do that -- my function seems a bit complicated for such a simple task. Maybe I'm wrong, but I would appreciate any simplification/comments.

My current function is :

function! DollarSplit(nlines) let current_pos = getpos(".") let a:count = 0 while a:count < a:nlines normal! 6|r$j a:count += 1 endwhile call setpos(".", current_pos) endfunction