4 ms·
%s/ \s\+$// comes up for me a fair amount (trim trailing whitespace)
by tyingq 3y ago
%s/ \s\+$// comes up for me a fair amount (trim trailing whitespace)
- nerdponx 3y agocommand! 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>
- cyphar 3y agoI have these in my .vimrc, to display and auto-trim trailing whitespace: augroup trailing_whitespace_show autocmd! " Make trailing whitespace red. autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red autocmd BufWinEnter,InsertEnter,InsertLeave * match ExtraWhitespace /\s\+$/ " Can slow things down, but show trailing whitespace as red while typing. autocmd InsertCharPre * match ExtraWhitespace /\s\+$/ augroup END augroup trailing_whitespace_kill autocmd! " Delete all trailing whitespace on-save. autocmd FileWritePre,FileAppendPre,FilterWritePre,BufWritePre * \ let w:wv = winsaveview() | \ :%s/\s\+$//e | \ call winrestview(w:wv) augroup END
- cerved 3y agoYou can use listchars trail to show trailing whitespace set listchars+=trail:· set list