Skip to content

Commit

Permalink
feat: 'dont_center' option
Browse files Browse the repository at this point in the history
  • Loading branch information
yshui authored and vladdoster committed Dec 4, 2022
1 parent e5f9ef3 commit 6b49f00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions doc/remember.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ g:remember_open_folds *g:remember_open_folds*
let g:remember_open_folds = true
------------------------------------------------------------------------------
g:remember_dont_center *g:remember_dont_center*

Disable screen centering when restoring cursor position.

Default: false ~

Example: >
let g:remember_dont_center = true
==============================================================================
4. CHANGELOG *remember-changelog*

Expand Down
10 changes: 8 additions & 2 deletions lua/remember.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local config = {
ignore_filetype = { "gitcommit", "gitrebase", "svn", "hgcommit" },
ignore_buftype = { "quickfix", "nofile", "help" },
open_folds = true,
dont_center = false,
}

function M.setup(options)
Expand All @@ -33,6 +34,10 @@ function M.setup(options)
if options["open_folds"] then
config["open_folds"] = options["open_folds"]
end

if options["dont_center"] then
config["dont_center"] = options["dont_center"]
end
end

function set_cursor_position()
Expand Down Expand Up @@ -62,8 +67,9 @@ function set_cursor_position()
-- then continue
if row > 0 and row <= api.nvim_buf_line_count(0) then
-- If the last row is visible within this window, like in a very short
-- file, just set the cursor position to the saved position
if api.nvim_buf_line_count(0) == fn.line("w$") then
-- file, or user requested us not centering the screen, just set the cursor
-- position to the saved position
if api.nvim_buf_line_count(0) == fn.line("w$") or config["dont_center"] then
api.nvim_win_set_cursor(0, cursor_position)

-- If we're in the middle of the file, set the cursor position and center
Expand Down

0 comments on commit 6b49f00

Please sign in to comment.