Vim functions to clear hidden characters

Currently, in my .vimrc file, I have a function that clears all spaces in spaces while saving, preserving my mouse position.

fun! <SID>StripTrailingWhitespaces()
  let l = line(".")
  let c = col(".")
  %s/\s\+$//e
  call cursor(l, c)
endfun

autocmd BufWritePre *.sql,*.php :call <SID>StripTrailingWhitespaces()

This works great. But I would like to add a few more things, for example:
* Delete carriage return
* Fix SP indent, followed by TAB

I tried adding

% s / ^ M // e

for my function StripTailingWhitespaces(), but when I save vim it tells me

Press ENTER or enter a command to continue

So, I think I did something wrong or forgot something. Any help on defining this? thank

:. . <CR> StripTrailingWhitespaces, BufWritePre. . , "Trailing Spaces". ?

, SP, TAB?

+3
1

fun! S()
  let l = line(".")
  let c = col(".")
  %s/\s\+$//e
  %s/^M//e   
  call cursor(l, c)
endfun

Vim 7.3 (: ^ M CTRL-V CTRL-M)

, , .

, , ?

, :messages, , .

Also :help messagesreads

  Press ENTER or type command to continue

This message is given when there is something on the screen for you to read,
and the screen is about to be redrawn:
- After executing an external command (e.g., ":!ls" and "=").
- Something is displayed on the status line that is longer than the width of
  the window, or runs into the 'showcmd' or 'ruler' output.

So this section may be worth a read (this is more than the one I inserted).

+1
source

Source: https://habr.com/ru/post/1792622/


All Articles