How are apps like vim and w3m built? I was trying to find info about this online but I couldn’t really find much.
You could check the project's source code repositories. For instance, the vim source code can be found at: https://github.com/vim/vim
However, you probably want to start a few steps earlier, as such large and grown projects tend to be very complicated.
But I don't think this was your intended question. I assume you are rather interested in how to create terminal UIs. Behind the scenes this is basically writing a bunch of magic characters with
printf which make the terminal do stuff like switching to alternative buffers or printing in different colors. There is even a Wikipedia page on the codes. But normally you would use a library that is abstracting away the low level parts like ncurses.
For more details, you could for instance check this article which looks like it answers your actual question.