2 ms·
command! StripTrailingWhitespace %s/\s\+$// I'm more inclined to use it on a regular basis when it has a friendly name, even though I'm pretty handy with regex
by nerdponx 3y ago
command! StripTrailingWhitespace %s/\s\+$//
I'm more inclined to use it on a regular basis when it has a friendly name, even though I'm pretty handy with regex.
- 000ooo000 3y agoI do the same. For Neovim users, Command Center is a neat customisable command palette (e.g. from VsCode) menu, but there's a few around. I typically create a command but also add it to command center, whose open mapping I have set to shift+enter. You can then fuzzy find command names/content which helps for those commands you don't use all that often.
- arp242 3y agoIf you wrap it in a function it wont clobber the last search pattern, and use winsaveview()/winrestview() to not move the cursor/view around. fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun command! TrimWhitespace call TrimWhitespace() Little bit more, but not too much and gives a much nicer experience IMHO.
- Zardoz84 3y agooh, nice improvement!
- Zardoz84 3y agoI like to use a shortcut for that : nnoremap <silent> <Leader>tl :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>