1

I want to find a way to set my default commentstring to '#' for files of unknown extension. As far as I know, there is no way to do this.

Issuing a setlocal commentstring=#\ %s on my .vimrc would overwrite the commentstring of all known files.

1 Answer 1

1

So, I came up to the following solution that works great :

autocmd BufNewFile,BufRead * if &syntax == '' | setlocal commentstring=#\ %s | endif

Idea taken from here:

vim default syntax for files with no extension

Sign up to request clarification or add additional context in comments.

4 Comments

True, thanks for that. Edited to add it. I am not sure why I am being downvoted ? Anyone care to explain it to me ?
Because your Q and A are the same text, so it is not really correct site usage. You post a question in the question, and answers in answers. They dont really mix (it’s not a forum where text can just go everywhere).
Thanks for the anwer. I edited the Q&A to match the format. I'd appreciate if you could remove the downvote now please?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.