Skip to content

Commit

Permalink
added how to automatically load commentstring (#21)
Browse files Browse the repository at this point in the history
* added how to automatically load commentstring

* Update README.md

Co-authored-by: Alex Tylor <alex@tylor.co.uk>
  • Loading branch information
christopher-besch and terrortylor authored Jul 25, 2021
1 parent 8780a53 commit a469348
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a469348

Please sign in to comment.