How can I pass the current line to a Vimscript function?

I am trying to create a Vim mapping that will operate on the current line, taking a string like this:

[boiled cabbage, mad donkey, elephant, very dark fudge]

And quoting all the list elements to end up with this:

["boiled cabbage", "mad donkey", "elephant", "very dark fudge"]

I tried with vim regexes, but figured it would be easier to write a function that takes the current line as an argument and returns the transformed line. I have no problem performing the transformation in vimscript. But how can I pass the current line to the function, and how do I replace the line with the transformed line?


To get current line you can use

let line=getline('.')

(note: you can also do getline(10, 20) to get a list of 11 lines).

To set current line you can use

call setline('.', line)

. You can also replace a number of lines starting with current if you pass a list to this function.

You can yank it into a register and then access it from there. byy yanks the line your cursor is at. You can access it then by using @b

Check out

Need Your Help

Android studio only finding "some" classes when browsing SDK sources

java android-studio

I seem to be having a massive problem with paths when browsing the SDK sources. Basically my issue is this: