Indenting issues

hello,
i’ve submitted with the exercism submit and when asking a mentor for help, they tell me that i have to make sure that i “indent” properly.
now when i’m looking at my cli, it’s indented properly, “why is it not when looking at submitted code?”
(i use tabs and not spaces, yet my vimrc has set shiftwidth=4 and set tabstop=4)
thank you

The mentor should be able to help with that. If not, I’d recommend trying to close the discussion and get a new mentor.

If you want help here, please include the exact code and the exact error inside a codeblock (```) (and not a screenshot).

It’s possible you have tab characters if you didn’t set expandtab. Try :%s/\t/ / in vim.

If you share the track/exercise and a screenshot, that’d help too :slight_smile:

the mentor, just said that i have to “indent properly” and i told him that it was correct on my cli, and i didn’t know why it was like that on the submit.

it has been on two tracks, both iterations of “error handling” and the first submit of “two-fer”
each time it has happened the indent errors have been in the “main () {…}” part of the submit

I’d recommend another mentor and/or sharing the code here.

While ‘all’ monospace text displaying programs agree on the visual width of a space character, this is not the case for the tab character. (There is a world of difference between a keyboard key and a character!) Some choose to render it with a width of four columns, some with a width of eight, and others still with some other widths. Whichever way it is rendered, a single tab character is a single character.

@emetib I’m guessing the tabs look good in your local editor because you configured your editor to render tabs in a way that suits you and you write your code in a way that does not cause visible problems given your editor settings. If the code looks different on the website, that is because the website renders tab characters different from your editor. The website has different settings, so to speak.

There are a lot of arguments out there about using spaces vs. tabs. I will not bother you with any – at least for now (it is liable to waste your time) – but if you tell me which language you are writing then I can tell you which one to use.

my code or what it looks like in the editor?

i’m doing the bash tracks in vim on my cli.
from what i have read years ago, it’s been a while since i have played around with programming, bash and python. both want 4 space indents or have your tab set to be 4 spaces, python “emphasizes” that, so i read a whole bunch on how to set up my vimrc to do that, 4 spaces. not a tab key mark.
i just checked https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces to make sure that i had it set up like properly and it was.
thank you and take care
em

Either. Both. We’re trying to help you but we can’t provide any insight without seeing something.

Did you set expandtab in vim? You can check if you have tabs by searching in vim for \t.

this is my vimrc without all the comments->

runtime! debian.vim
set nocompatible
syntax on
set background=dark
if has(“autocmd”)
au BufReadPost * if line(“'"”) > 1 && line(“'"”) <= line(“$”) | exe “normal! g’"” | endif
endif
if has(“autocmd”)
filetype plugin indent on
endif
set tabstop=8
set expandtab
set shiftwidth=4 smarttab
set softtabstop=0
set number
set textwidth=100
set rulerformat=%l,%v
set modeline
set showmatch
packadd! ale
if filereadable(“/etc/vim/vimrc.local”)
source /etc/vim/vimrc.local
endif

these are the pkgs associated with vim installed →
VIM - Vi IMproved 8.2

vim
vim-addon-manager
vim-ale
vim-common
vim-runtime
vim-syntastic
vim-tiny

Is your issue with an exercise in Exercism or are you asking about your vim setup?

If you have a question about your exercise solution, it would be helpful to see your solution. If you may have an issue with tabs in your solution, you should check if you have tab characters (\t).

Your vimrc looks fine up me. You haven’t mentioned any issues with your vimrc so I don’t think there’s any issues with the config you shared.

When sharing code, please use a code block (```).

it is how the results are being displayed in the exercism online editor.
look at how both of the “error handling” submissions are, and the first from the 'two-fer" submission.
you were the mentor that told me i had to indent properly, and i told you at the time that it was fine on my cli.


main () {
    if [[ "${#}" -eq 0 ]] ; then
	echo "One for you, one for me."
    else echo "One for $1, one for me."
    fi
}

main "$@"

ok, i’m done. i did the bloke quote ``` and it’s not even showing up the same in teh preview as it’s showing on how i pasted it.

take care

If you try to highlight the whitespace at the beginning of the if line, you may notice there are four spaces and you can highlight any number of them.

If you try to highlight the whitespace at the beginning of the echo line, you may notice you cannot highlight single (width) characters; it’s a single tab character which can only be highlighted as a single block.

The else line starts with a tab (\t) character and not four spaces. If you open vim search for a tab (/ to open search, \t for a tab), it should highlight and show you the tab character.

The tab character ought to be replaced with eight spaces.

Since your vimrc has set expandtab, when you hit the <tab> key, you ought to get four spaces. It’s possible your smartindent put in a tab char, though.

Neither language has an opinion on how wide you should set your rendered tab width. Programming languages are concerned with characters, not their display on screen.

Python requires indentation. The norm is to use 4 spaces. Tabs are allowed but discouraged, and mixed use is forbidden.

Bash does not require indentation. Use whatever you want, but be consistent and be aware that you cannot generally reliably allign code using tabs alone.

As you might have noticed, mixing tabs and spaces is a recipe for disaster.

If you omit expandtab, having different tabstop and shiftwidth ensures you’ll get a mix of tabs and spaces for your indentation, and that leads to strange-looking results in the web editor.

I use

set shiftwidth=4 
set expandtab
set smarttab

without setting tabstop.

One other helpful thing vim can do. Add

set listchars=eol:$,tab:\\_

Then, :set list will display tab characters visually. You can see if you’re mixing tabs and spaces. Do :set nolist to turn it off.

these are the setting to have a tab key insert 4 spaces, on my machine anyway, and once i entered the listchars and seen what you could add to see spaces, then things made sense.

thanks you everyone’s help

39 set,tabstop=4$
40 set,expandtab$
41 set,shiftwidth=4$
42 set,smarttab$
43 set,softtabstop=0$
44 set,number$
45 set,textwidth=100$
46 set,rulerformat=%l,%v$
47 set,modeline$
48 set,listchars=eol:,tab:\>_,space:,
49 set,list$
50 set,showmatch>>_",Show,matching,brackets.$