Comments (2)
I think you can just do something like this to set a default commentstring yourself?
vim.api.nvim_create_autocmd("FileType", {
pattern = { "*" },
callback = function(event)
vim.api.nvim_buf_set_option(event.buf, "commentstring", vim.api.nvim_buf_get_option(event.buf, "commentstring") or "# %s")
end,
group = vim.api.nvim_create_augroup("commentstring", { clear = true }),
})
from comment.nvim.
I think you can just do something like this to set a default commentstring yourself?
vim.api.nvim_create_autocmd("FileType", { pattern = { "*" }, callback = function(event) vim.api.nvim_buf_set_option(event.buf, "commentstring", vim.api.nvim_buf_get_option(event.buf, "commentstring") or "# %s") end, group = vim.api.nvim_create_augroup("commentstring", { clear = true }), })
@Amzd Thanks for the suggestion! I just tried this, but it doesn't seem to be working quite as expected. I put it inside my init.lua
, and added a print statement:
vim.api.nvim_create_autocmd("FileType", {
pattern = { "*" },
callback = function(event)
print("Hello world, my commentstring is: " .. (vim.api.nvim_buf_get_option(event.buf, "commentstring") or "# %s"))
vim.api.nvim_buf_set_option(
event.buf,
"commentstring",
vim.api.nvim_buf_get_option(event.buf, "commentstring") or "# %s"
)
end,
group = vim.api.nvim_create_augroup("commentstring", { clear = true }),
})
and I get the "hello world" when loading files like .lua, .py, .js, etc. but if I have a plaintext file, or something like test.conf
or test.filetypeunknown
, the message doesn't print to the console. Could it be that the FileType event doesn't fire for files of an unknown type? Any idea if there's another way to accomplish this?
from comment.nvim.
Related Issues (20)
- Not working for .kv files
- Issue with HCL files HOT 1
- how to add a header comment? HOT 3
- [Comment.nvim] nil for .lua files
- Adding a shortcut that selects the kind of comment
- Wrong commenting on HTML files. HOT 1
- Add blockwise comment support for verilog/systemverilog
- Support templ HOT 1
- How to support context filetype?
- Uses `//` as commentstring in html HOT 4
- NOT A BUG/ISSUE [a gen qs] HOT 2
- How to just do comment or uncomment?
- comment config working on arch but not on linux (arch) HOT 1
- Retain visual mode after commenting HOT 1
- [BUG] When I try to comment linewise in visual mode, unrelated or extra code gets commented HOT 5
- Adding a FOSS license HOT 2
- Not working for typescript react HOT 1
- BUG: fails silently in absence of LuaJIT HOT 1
- ft.set() not working for blade files defaults to html comments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comment.nvim.