nmac427 / guess-indent.nvim Goto Github PK
View Code? Open in Web Editor NEWAutomatic indentation style detection for Neovim
License: MIT License
Automatic indentation style detection for Neovim
License: MIT License
Thanks for this plugin.
guess-indent
not detect tabs with size 4.
Example using lua file.
Thank you for making this plugin. Are there advantages/USPs of using this over indent-o-matic
, another fairly new lua plugin?
Perhaps you could provide an explanation and/or benchmarks?
Hi,
use({
"nmac427/guess-indent.nvim",
config = function()
require("guess-indent").setup({})
end,
})
Trying out this plugin with the config from the readme.
Sadly the autostart is not working. Even with auto_cmd=true
.
I need to manually call GuessIndent
to get it work. :(
Any idea? Do you need more info? Do i need to setup the plugin in an specific order?
I find it useful to only show tab via listchars
when using spaces and vice versa, since that allows me to quickly identify the use of the wrong type of indention in a file.
Currently, I run a simple autocommand like this to adjust listchars
depending whether the buffer uses tabs or spaces:
autocmd("BufReadPost", {
callback = function()
-- defered, to ensure it runs after `:GuessIndent`
vim.defer_fn(function()
opt_local.listchars = vim.opt_global.listchars:get() -- copy the global
if bo.expandtab then
opt_local.listchars:append { tab = "? " }
opt_local.listchars:append { lead = " " }
else
opt_local.listchars:append { tab = " " }
opt_local.listchars:append { lead = "�" }
end
end, 5)
end,
})
I was thinking that adjusting listchars
would actually make a lot of sense for in the context of this plugin (and would also save one from using hacky solutions like deferring that autocmd)
The file types and buffer types to exclude are ignored when auto_cmd
is set to false. However, I only disabled the autocmd so I could call guess-indent from my own autocmd, to allow for more control over when it's run relative to other indentation-related configuration.
Currently I'm manually calling require("guess-indent").set_from_buffer(true)
from my own autocmd, but it would be great if there was a command, or perhaps an argument that could be passed to :GuessIndent
, that would respect the user config regardless of what auto_cmd
is set to.
I noticed that the plugin seems to creates a prints a notification every time it sets the indentation.
While that may be useful for when you manually run :GuessIndent
or when the indentation values have been changed, it is a bit annoying when the notification appears every time you enter a new buffer, even if the indentation was already set correctly?
Hi,
thank you so much for making this plugin!!
Below is my lua for lazy, you could add that to the readme.
I've also added the following keybindings:
<Tab>g to guess the indetation
<Tab>t to convert to tabs (normal mode)
<Tab>t to convert to tabs (visual line mode)
<Tab>s to convert to spaces (normal mode)
<Tab>s to convert to spaces (visual line mode)
While the last two (four) bindings don't have anything to do with your plugin, you may still choose to add them to the readme as they provide a great workflow enhancement when converting styles.
return {
'nmac427/guess-indent.nvim',
lazy = false,
config = function()
require('guess-indent').setup {}
vim.keymap.set('n', '<Tab>g', vim.cmd.GuessIndent, { desc = "GuessIndent (manual)" })
-- to tabs
vim.keymap.set('n', '<Tab>t', '<Cmd>set noexpandtab<CR><Cmd>%retab!<CR><Cmd>set tabstop=8<CR>', { noremap = true, desc = "retab to tabs" })
vim.keymap.set('v', '<Tab>t', "<Cmd>set noexpandtab<CR><Cmd>'<,'>retab!<CR><Cmd>set tabstop=8<CR>", { noremap = true, desc = "retab to tabs" })
-- to spaces (for the average emacs enjoyer)
vim.keymap.set('n', '<Tab>s', '<Cmd>set expandtab<CR><Cmd>set tabstop=8<CR><Cmd>%retab!<CR>', { noremap = true, desc = "retab to spaces" })
vim.keymap.set('v', '<Tab>s', "<Cmd>set expandtab<CR><Cmd>set tabstop=8<CR><Cmd>'<,'>retab!<CR>", { noremap = true, desc = "retab to spaces" })
end,
}
For beginners like me, these would be quite helpful.
Hello, thanks for your work on GuessIndent plugin : it's a great tool for my neovim usage.
I'm using ftplugin
files for C, Go and Python to automatically configure my indent settings (filetype plugin indent on
in configuration). For example, ftplugin/python.vim
:
setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal smarttab
setlocal expandtab
How to use your plugin to set automatically indentation with ftplugin files ? If your plugin detects an indentation different from my configuration, what configuration will be used ?
I want to use my default configuration for C, Go and Python when I work on my projects but I would like to use automatic indentation detected by GuessIndent when I work on external project (common usage : C project indented with TAB of 8, 4 spaces for indent in my personal config for C).
I disabled the automatic execution of guess-indent and started calling vim.api.nvim_command("GuessIndent")
in one of my own autocmds so I can dynamically adjust listchars
based on the file's indentation.
But now I'm getting messages about the indentation being set (eg, Did set indentation to tabs.
) Is there a way to silence those messages?
Google C++ style place class member access specifier in 3 spaces indent, which make guess-indent set indent to 1 space. In practice this should be 4 spaces.
A simple example:
class Example {
public:
Example() {}
};
can we support this as a special case?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.