Skip to main content
4 of 7
[Edit removed during grace period]
Hotschke
  • 4.9k
  • 26
  • 38

=p from vim-unimpaired

Given file

function Scene:get(...)

    local l = {}

    for i, e in ipaires(self.nodelist) do
        if (e:is(...)) then
            l[#l +1] = e
        end
    end

    return l

end
  1. Yank word function with
    yiw
    Now the unnamed register contains function (verify with :reg ")

  2. Add one new blank line and leave insert mode with
    oEsc or with vim-unimpaired ]-Spacej (does not enter insert mode)

  3. =p from unimpaired does what you want.

This is more impressive if you insert several lines from a register. For example, yank full function with yG in step 1 and then do steps 2 and 3.

Remark: filetype support for lua in vim

I tried to figure out if the default ftplugin for lua or a third party lua plugin provides dedicated lua motions to move the cursor reliably to the end of the function. Apparently, there is

However, it looks unmaintained. A maintained ftplugin for lua which does not provide, as far as I can see, lua dedicated motions is

Therefore, I am not too happy with lua support in vim. Useful tpope plugins with lua support are

Hotschke
  • 4.9k
  • 26
  • 38