Skip to content

Commit

Permalink
Merge pull request #3 from iamxiaojianzheng/main
Browse files Browse the repository at this point in the history
fix bug #2 (lateral movement)
  • Loading branch information
sarrisv authored Jul 16, 2024
2 parents 5815627 + e86ba58 commit 0527fc3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Simple neovim plugin for keeping your cursor centered while reading through code/text/whatever

![readermode.gif](readermode.gif)
https://github.com/user-attachments/assets/d9bd8a00-54cd-4264-83a8-2ad4d82d64dc

## Requirements

Expand All @@ -12,25 +12,25 @@ Simple neovim plugin for keeping your cursor centered while reading through code

### lazy.nvim

```lua
{
'sarrisv/readermode.nvim',
opts = { --[[ Configurations Options ]] }
}
```
```lua
{
'sarrisv/readermode.nvim',
opts = { --[[ Configurations Options ]] }
}
```

### Configuration

```lua
{
enabled = false, -- Turned off by default
keymap = "<leader>R" -- Keymap used to toggle ReaderMode on/off
}
```
```lua
{
enabled = false, -- Turned off by default
keymap = "<leader>R" -- Keymap used to toggle ReaderMode on/off
}
```

## Usage

Toggle **ReaderMode** using `:ReaderMode` or the provided *normal mode* keymapping
Toggle **ReaderMode** using `:ReaderMode` or the provided _normal mode_ keymapping

## Credits

Expand Down
14 changes: 13 additions & 1 deletion lua/readermode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@ function M.setup(opts)
vim.api.nvim_create_user_command("ReaderMode", require("readermode").toggle, {})
vim.keymap.set({ "n" }, M.opts.keymap, M.toggle, { desc = M.opts.desc })

local last_line = M.getCurrentLineNumber()

-- Define Autocommand w/ new Autogroup
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
group = vim.api.nvim_create_augroup("ReaderMode", { clear = true }),
callback = function()
if M.opts.enabled then
M.center()
local current_line = M.getCurrentLineNumber()
if current_line ~= last_line then
M.center()
else
end
last_line = current_line
end
end,
})
end

---@return number
function M.getCurrentLineNumber()
return vim.api.nvim_win_get_cursor(0)[1]
end

---@return nil
function M.toggle()
M.opts.enabled = not M.opts.enabled
Expand Down
Binary file removed readermode.gif
Binary file not shown.

0 comments on commit 0527fc3

Please sign in to comment.