_buf.lua 782 B

123456789101112131415161718192021222324
  1. local M = {}
  2. --- Adds one or more blank lines above or below the cursor.
  3. -- TODO: move to _defaults.lua once it is possible to assign a Lua function to options #25672
  4. --- @param above? boolean Place blank line(s) above the cursor
  5. local function add_blank(above)
  6. local offset = above and 1 or 0
  7. local repeated = vim.fn['repeat']({ '' }, vim.v.count1)
  8. local linenr = vim.api.nvim_win_get_cursor(0)[1]
  9. vim.api.nvim_buf_set_lines(0, linenr - offset, linenr - offset, true, repeated)
  10. end
  11. -- TODO: move to _defaults.lua once it is possible to assign a Lua function to options #25672
  12. function M.space_above()
  13. add_blank(true)
  14. end
  15. -- TODO: move to _defaults.lua once it is possible to assign a Lua function to options #25672
  16. function M.space_below()
  17. add_blank()
  18. end
  19. return M