diff --git a/README.md b/README.md index e3209fd..3e0ce79 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,26 @@ If you want to override the comment markers or add a new filetype just set the * vim.api.nvim_buf_set_option(0, "commentstring", "# %s") ``` +You can also use an autocommand to automatically load your **commentstring** for certain file types: +```vim +" when you enter a (new) buffer +augroup set-commentstring-ag +autocmd! +autocmd BufEnter *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, "commentstring", "// %s") +" when you've changed the name of a file opened in a buffer, the file type may have changed +autocmd BufFilePost *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, "commentstring", "// %s") +auground END +``` + +Or add the comment string option in the relevant `filetype` file: +```vim +let commentstring="# %s" +``` + +```lua +vim.api.nvim_buf_set_option(0, "commentstring", "# %s") +``` + # Installation Install just as you would a normal plugin, here are some options: