Move my functions into the "custom" module 💬 by Caio 4 years ago (log)
Now the command namespace is not polluted. So much easier to use namespaces with lua <3
Now the command namespace is not polluted. So much easier to use namespaces with lua <3
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
local M = {}
-- If the current file has been opened before, try to jump to the
-- last cursor position the editor was at. If there are fewer
-- lines than remembered, it jumps to the end instead
function M.jump_to_last_position()
local previous_position = vim.fn.line("'\"")
if previous_position > 0 then
local max_line_nr = vim.fn.line("$")
if previous_position < max_line_nr then
vim.cmd("normal '\"")
else
vim.cmd("normal $")
end
end
end
-- It's very inconvenient to use the ^ motion (first non blank)
-- in a intl keyboard with dead keys. This functions acts as
-- a "smart" wrapper that flip-flops between ^ or 0, depending
-- on the cursor position.
function M.caret_or_zero()
-- select what's between the cursor and the beginning of the line
local linepart = vim.fn.strpart(vim.fn.getline('.'), -1, vim.fn.col('.'))
-- Are there only whitespace characters in it?
if string.match(linepart, "^%s+$") then
vim.cmd("normal! 0")
else
vim.cmd("normal! ^")
end
end
return M
|