- update readme
        - mention cfg branch
        - include todo section
        - fix capitalization typos

    - remove initials from source
main
McAuley Penney 3 years ago
parent 25715ac21f
commit 1b230b4045

@ -10,8 +10,10 @@ on every `BufWritePre`.
![tidy](https://user-images.githubusercontent.com/59481467/142785684-96559135-88e7-4c50-a848-56f2c65262ef.gif)
**Note**: See the `cfg` branch for increased functionality and configuration.
## install
## Installation
- Packer
```lua
@ -24,8 +26,11 @@ or with lazy-loading
use{ "McAuleyPenney/tidy.nvim", event = "BufWritePre" }
```
## Todo
- [ ] preserve undotree
## Credits:
## Credits
- [Vim Tips Wiki entry for removing unwanted spaces](https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace)
- ib., the author of [this stack overflow answer](https://stackoverflow.com/a/7501902)

@ -1,20 +1,17 @@
-- MP
local M = {}
function M.tidy_up()
-- get tuple of cursor position before making changes
local pos = vim.api.nvim_win_get_cursor( 0 )
local pos = vim.api.nvim_win_get_cursor(0)
-- delete all whitespace, see source 1
vim.cmd[[:keepjumps keeppatterns %s/\s\+$//e]]
vim.cmd([[:keepjumps keeppatterns %s/\s\+$//e]])
-- delete all lines at end of buffer, see source 2
vim.cmd[[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d]]
vim.cmd([[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d]])
-- get row count after line deletion
local end_row = vim.api.nvim_buf_line_count( 0 )
local end_row = vim.api.nvim_buf_line_count(0)
--[[
if the row value in the original cursor
@ -29,7 +26,7 @@ function M.tidy_up()
pos[1] = end_row
end
vim.api.nvim_win_set_cursor( 0, pos )
vim.api.nvim_win_set_cursor(0, pos)
end
return M

Loading…
Cancel
Save