thirtythreeforty / lessspace.vim Goto Github PK
View Code? Open in Web Editor NEWBetter whitespace stripping for Vim
Better whitespace stripping for Vim
Hi George,
thanks for your very useful VIM plugin. I started using it a while back to get rid of trailing whitespace, especially in code checked into version control systems. Though your plugin does help a lot, there are still a number of whitespace errors remaining. I think the main source of these, at least in my case, is the deletion of trailing parts of a line, e.g. comments. For example, consider a line like
my $empty_string = ""; # the empty string
where I later decide to remove the comment. I would usually do this by going to this line and hitting f#d$
, which will remove the comment, but will not remove the whitespace after ";", yielding a whitespace error.
Would it be possible to add support to your plugin for removing these types of whitespace errors, too? More precisely, I think it would be sensible to remove whitespace not just from all lines visited in insert mode, but also from all lines which have been manipulated by deletions (d), regexp substitutions or pastes. What do you think?
Regards,
Felix
The test file I used (note trailing whitespace on each line):
some spaces here
some more here
and again
The test command was :%s/here/there/
. After running the command, affected lines still have their trailing whitespace.
This was on Vim 8.1 (my own compiled version).
As you type into the buffer when Codi is started, Codi evaluates the code. Unfortunately, a side effect of this behaviour is that this plug-in decides to strip the white space as you type - as you are still in insert mode. This is rather annoying, especially when you are trying to type code that is indented.
To illustrate this behaviour, see this:
I have mentioned this in this issue here metakirby5/codi.vim#90
file (add some whitespace to each line when testing):
private bla() {
sdfkljsdlkfj sdkl fjask ljakl sjdfkl jkl
}
open vim with that file and make sure that you have the whitespace saved.
now open vim and have lessspace enabled. run :%s/private/public/<CR>
and now the whitespace is stripped from every line, not just the 1st line (which would be the ideal behaviour)
It is a bit less intrusive/surprising that way. I'm not sure this possible based on how the plug in is permitted. If not possible, it's not a big deal
Hello, I'm hoping this is a solved problem as its a pretty common case (from my POV at least) but is it possible to override my C-r
mapping to disable LessSpace until I choose a register?
Quick example to demonstrate the problem, I'll use |
to represent the cursor and assume insert mode:
Register "
contains: this plugin is awesome!
new_string = "Thanks, |
When pressing C-r "
the trailing whitespace is removed and the register is pasted leaving us with the following:
new_string = "Thanks,this plugin is awesome!
I've tried manually toggling LessSpace but its not ideal, I've also experimented with wrapping registers.nvim
C-r
command with lessspace#TemporaryDisableBegin/End
but I've had no luck [0].
[0] - Gee19/registers.nvim@d38ef97
Any workarounds would be awesome
With Whitespaste installed, and given this sample file:
fn foo() {
}
fn baz() {
do_something();
do_something_else();
}
Yank yy
the empty line from foo
and try to paste it before the do_something()
call or after the do_something_else
call (essentially, next to a delimiter).
This error is thrown:
Error detected while processing function lessspace#OnTextChanged[18]..lessspace#MaybeStripWhitespace:
line 23:
E493: Backwards range given: 12 , 11 s/\v\s+$//e ```
I edit a file with blanks at end of, for example, lines 5 and 10. If I change line 5 and remain in insert mode and move down with down-arrow to line 10 and, remaining in insert mode, move back to line 5 and then exit insert mode, the blanks at the end of 5 go away. But they also go away at line 10 (which I did not change at all).
Ideally, only changed lines should have their trailing whitespace removed.
Then if I try to undo these changes, nothing happens. The change on line 5 won't undo and the blanks at the end of 5 and 10 won't come back.
Only if I do command :LessSpace! to disable the plugin can I undo any previous changes.
(Hopefully I installed in right. I just put the entire cloned project lessspace.vim/ under ~/.vim/plugin/)
This would prevent the slight cursor motion in cases like the autocommand in #5:
inoremap <c-f> <c-g>u<Esc>[s1z=`]a<c-g>u
However there may be other edge cases that make this unworkable, or this may be surprising to the user.
In any case, it would be nice to have an implementation to try it out with.
A couple points:
updatetime
is sufficiently low.I keep receiving below error message once a few hours. It usually happens when I press <ESC>
at the end of file, but I couldn't find a consistent way for reproducing it. Removing lines at the end of file may be causing this somehow, but I'm not sure as I couldn't intentionally trigger this message in any way. I suspect some kind of race condition.
I didn't realize any other issues caused by this other than printing error message on the screen.
Error detected while processing function lessspace#OnInsertExit[1]..lessspace#MaybeStripWhitespace:
line 33:
E16: Invalid range: 1 , 3 s/\v\s+$//e
Another one:
Error detected while processing function lessspace#OnInsertExit[1]..lessspace#MaybeStripWhitespace:
line 33:
E16: Invalid range: 12 , 14 s/\v\s+$//e
Something about nonexisting variables. Unfortunately I can't reliably reproduce it.
Thank you for an amazingly useful plugin!
Unfortunately I sometimes run into problems when undoing or redoing changes on the last line of a file. I'm not sure what types of changes cause this exactly, but I ran into this on several different occasions. It's mostly related to plugins and/or mappings I believe, but maybe it can occur on manual edits.
Just now it happened again so here is one way to reliably trigger this using the vim-surround plugin:
type a word into the last/only line of a file:
this
is
the
last
line
with the cursor over line
, type ysiw"<esc>
to wrap it in quotation marks.
this
is
the
last
"line"
undoing this change with u
triggers the error as well as redoing the change with <c-r>
:
Error detected while processing function lessspace#OnTextChanged[15]..lessspace#
MaybeStripWhitespace:
line 13:
E16: Invalid range: 5 , 6 s/\v\s+$//e
Press ENTER or type command to continue
The error message can be easily dismissed, but it would of course be preferable to not get the error :)
Maybe you can do something about this, thank you for your work in any case.
By the way I'm using lessspace with neovim v0.1.7 on linux.
It seems to interfere with telescope: nvim-telescope/telescope.nvim#1593
In a vim-multiple-cursors selection, adding trailing whitespace is impossible, due to being stripped immediately by lessspace.
Thank you for making this plugin, it's almost everything I'm looking for. Unfortunately for me it frequently messes up a mapping for auto-correcting the last spelling mistake before the cursor.
inoremap <c-f> <c-g>u<Esc>[s1z=`]a<c-g>u
nnoremap <c-f> [s1z=<c-o>
If I tpyed this sentence wrong. And hit <c-f>
right here|
Then the sentence would be corrected and the cursor would jump back to the correct spot. Everything is dandy.
However if I typed TIHS sentence wrong. And hit <c-f>
right here | (notice the space)
Then I think the `] mark gets overwritten and the cursor ends up after the first character of the line.
Any suggestions?
While typing, I often get a popup:
1 substitution on 1 line
Could the command causing this be silent !
?
Or perhaps an option to disable these messages?
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.