mcauley-penney / tidy.nvim Goto Github PK
View Code? Open in Web Editor NEWA small Neovim plugin to remove trailing whitespace and empty lines at end of file on every save
A small Neovim plugin to remove trailing whitespace and empty lines at end of file on every save
For reference, see https://github.com/axelf4/vim-strip-trailing-whitespace
The motivation for this feature is to prevent modifying many lines on save, polluting a commit with changes that are not relevant to a feature or fix. To effectively use this tool as it is now on a large file with many errant white spaces, one almost needs to reformat the file, commit those changes, then begin working on their task.
In some cases (for example when using real-time preview for markdown or tex files) many saves can happen.
This causes the plugin to repeatedly delete trailing whitespaces while writing.
For situations like these it could be useful to stop the plugin and run it manually.
A function to stop the plugin and a function to run the cleanup could be provided.
{
"mcauley-penney/tidy.nvim",
config = { -- <----------------------------- here
filetype_exclude = { "markdown", "diff" }
},
init = function()
vim.keymap.set('n', "<leader>te", require("tidy").toggle, {})
end
}
In the above snippet it should be opts
instead of config
I believe
Hi! I'm trying to migrate my vim config to lua, and stumbled upon this plugin, which looks great, except for one thing: it uses Markdown as an example for the main usage, and Markdown is the only file format I know for which trailing whitespace is meaningful. I don't use it and no longer work with people who do so I'm still going to use your plugin, but still, it would be nice to be able to disable this plugin for markdown only.
Received an error when writing file.
Error detected while processing BufWritePre Autocommands for "*":
Error executing lua callback: ...config/nvim/autoload/plugged/tidy.nvim/lua/tidy/init.lua:17: attempt to call field 'list_contains' (a nil value)
stack traceback:
...config/nvim/autoload/plugged/tidy.nvim/lua/tidy/init.lua:17: in function 'is_excluded_ft'
You can use now with neovim master
vim.api.nvim_create_augroup('MYAUCMDS', {clear = true})
vim.api.nvim_create_autocmd('BufWritePre', {group = 'MYAUCMDS', pattern = '*', command = [[:keepjumps keeppatterns %s/\s\+$//e]]}) -- remove trailing spaces
Also, I dont understand what you want to preserve in the undotree.
Marks will be lost, if they correspond to deleted text. You would need to tell neovim how the text was moved, once parts get deleted.
But you only delete empty lines, which should not have marks. So its unclear to me, what behavior has problems.
Use this C program as an example:
#include <stdio.h>
int main(void)
{
printf("%s\n", "Hello world");
}
Notice the unnecessary leading space in front of #include <stdio.h>
. After writing to the file, the result should be this:
#include <stdio.h>
int main(void)
{
printf("%s\n", "Hello world");
}
The leading whitespace in front of printf
should not be deleted because it is used for indentation. This should work if someone indents with tabs or spaces. I am not sure how to implement this myself, so I am opening an issue instead of a pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.