-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract some lua functions to lua files
- Loading branch information
1 parent
9e74f20
commit 42b0d08
Showing
5 changed files
with
235 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
system/with/user/with/program/neovim/commands/jump_down_half_a_page.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function() | ||
-- Get the current window height | ||
local win_id = vim.api.nvim_get_current_win() | ||
local height = vim.api.nvim_win_get_height(win_id) | ||
|
||
-- Get the current cursor position (row, col) | ||
local cursor = vim.api.nvim_win_get_cursor(win_id) | ||
local current_row = cursor[1] | ||
|
||
-- Calculate the new row (half the window height below the current position) | ||
local new_row = current_row + math.floor(height / 2) | ||
|
||
-- Ensure the new row is within the bounds of the buffer | ||
local buf_line_count = vim.api.nvim_buf_line_count(0) | ||
new_row = math.min(new_row, buf_line_count) -- Don't scroll past the last line | ||
|
||
-- Move the cursor to the new row (the column remains the same) | ||
vim.api.nvim_win_set_cursor(win_id, {new_row, cursor[2]}) | ||
end |
19 changes: 19 additions & 0 deletions
19
system/with/user/with/program/neovim/commands/jump_up_half_a_page.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function() | ||
-- Get the current window height | ||
local win_id = vim.api.nvim_get_current_win() | ||
local height = vim.api.nvim_win_get_height(win_id) | ||
|
||
-- Get the current cursor position (row, col) | ||
local cursor = vim.api.nvim_win_get_cursor(win_id) | ||
local current_row = cursor[1] | ||
|
||
-- Calculate the new row (half the window height below the current position) | ||
local new_row = current_row - math.floor(height / 2) | ||
|
||
-- Ensure the new row is within the bounds of the buffer | ||
local buf_line_count = vim.api.nvim_buf_line_count(0) | ||
new_row = math.max(new_row, 1) -- Don't scroll above the first line | ||
|
||
-- Move the cursor to the new row (the column remains the same) | ||
vim.api.nvim_win_set_cursor(win_id, {new_row, cursor[2]}) | ||
end |
Oops, something went wrong.