On 2020-07-06 14:00, Albrecht Schlosser wrote:
> *Please configure your editors* accordingly to keep this new standard alive, i.e.:
>
> a. use 2 column indents
> b. use space for indenting
> c. do not use tabs for indenting
> d. do not use tabs for "trailing comments", etc. etc.
> e. avoid adding trailing whitespace
> f. remove trailing whitespace on exit if possible [1]
For VI/VIM, the following can be used to solve a-d:
set ai " Enable auto-indent
set sw=2 " 2 space indent (sw=shift width)
set expandtab " Uses spaces instead of tabs when you hit tab
set ts=8 " Always leave tabstop at 8
set softtabstop=8 " Columns the tab key stops at (ok to change to e.g. 2 or 4)
For e-f, I'm not sure there's an easy answer; see below.
Apparently 'autocmd BufWritePre {filepat} {cmd}' can be used to apply
a search/replace just before all :w write operations for files with
filename extensions that match {filepat}, e.g.
autocmd BufWritePre *.cxx,*.c,*.h,*.mm :s/\s\+$//e
----------- ------------------ -----------
All writes filepat regex cmd
..which applies the search/replace to all .cxx/.c/.h/.mm files
just before writing the file to disk.
But because this does a search/replace, the cursor might be moved to the
last search/replace match, loosing your cursor position, so to solve that
a slightly more complicated approach seems necessary (in your ~/.vimrc):
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
keepp %s/\s\+$//e
call cursor(l, c)
endfun
autocmd FileType c,cxx,h,mm autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
I haven't tried that yet, but perhaps it's a start.
I suggest all vi users try the different approaches out there and report back what works.
Here's a few links to start:
How can you automatically remove trailing whitespace in vim
===========================================================
https://stackoverflow.com/questions/356126/how-can-you-automatically-remove-trailing-whitespace-in-vim
How to automatically strip trailing spaces on save in Vi / Vim?
===============================================================
https://unix.stackexchange.com/questions/75430/how-to-automatically-strip-trailing-spaces-on-save-in-vi-and-vim
Remove Unwanted Spaces
======================
https://vim.fandom.com/wiki/Remove_unwanted_spaces
"New" Techniques (2010) for "Tidying Whitespace"
================================================
http://vimcasts.org/episodes/tidying-whitespace/
> *Please configure your editors* accordingly to keep this new standard alive, i.e.: > > a. use 2 column indents > b. use space for indenting > c. do not use tabs for indenting > d. do not use tabs for "trailing comments", etc. etc. > e. avoid adding trailing whitespace > f. remove trailing whitespace on exit if possible [1]
I'd sure like to see the suggested settings for Visual
Studio
if anyone knows them.