diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-22 01:01:25 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-22 01:01:25 -0600 |
commit | de0704ff9ad57f53ae42f0f73de189084768679e (patch) | |
tree | e050956dd4343f610ee7ee1ff8277d3180c8b43a /plugin/mark.lua | |
parent | 496be085b855d0192753d933313536929671a9d3 (diff) | |
download | rneovim-userregs-de0704ff9ad57f53ae42f0f73de189084768679e.tar.gz rneovim-userregs-de0704ff9ad57f53ae42f0f73de189084768679e.tar.bz2 rneovim-userregs-de0704ff9ad57f53ae42f0f73de189084768679e.zip |
Add mark.lua.
Diffstat (limited to 'plugin/mark.lua')
-rw-r--r-- | plugin/mark.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/plugin/mark.lua b/plugin/mark.lua new file mode 100644 index 0000000..dd3baa6 --- /dev/null +++ b/plugin/mark.lua @@ -0,0 +1,54 @@ +-- Implementation of middle mark. This mark is always in the middle of the +-- viewport. + +local api = vim.api + +-- Compatibility check. +if not api.nvim_call_function('has', {'usermarks'}) then + return nil +end + +local usermark = require("vim.usermark") + +-- The middle mark is on the middle of the screen. +local middle_mark = {} +function middle_mark.get(self) + local topline = vim.api.nvim_call_function('line', {'w0'}) + local bottomline = vim.api.nvim_call_function('line', {'w$'}) + + return math.floor((topline + bottomline) / 2) +end + +-- Setting the middle mark sets the current cusor line to the middle of the +-- window. Principally this is the same as z. +function middle_mark.set(self) + api.nvim_command('norm z.') +end + +-- The top mark is the first line on the window. Right now scrolloff is ignored, +-- but maybe it shouldn't be. +local top_mark = {} +function top_mark.get(self) + return vim.api.nvim_call_function('line', {'w0'}) +end +-- Setting the top mark move the current line to the top. Principally this is +-- the same mas z<cr> +function top_mark.set(self) + api.nvim_command('norm z<cr>') +end + +-- Setting the bottom mark moves the current line to the bottom. Principally +-- this is the same as z- +local bottom_mark = {} +function bottom_mark.get(self) + return vim.api.nvim_call_function('line', {'w$'}) +end +-- Setting the bottom mark doesn't do anything. +function bottom_mark.set(self) + api.nvim_command('norm z-') +end + +-- Register all the marks with their respective characters. +usermark.register_handler('-', middle_mark) +usermark.register_handler('+', top_mark) +usermark.register_handler('_', bottom_mark) |