diff options
| author | nsfisis <nsfisis@gmail.com> | 2021-12-04 13:07:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2021-12-04 13:07:20 +0900 |
| commit | 12f18a076f79470941f7ed54ac2de7effcbff740 (patch) | |
| tree | 46ba444c33d0c081b804668f0a88eeb0a53478e8 /.config/nvim/lua/vimrc.lua | |
| parent | cd8fa7b1c73bcca9b5c28bae8b6aa092cd4a948a (diff) | |
| download | dotfiles-12f18a076f79470941f7ed54ac2de7effcbff740.tar.gz dotfiles-12f18a076f79470941f7ed54ac2de7effcbff740.tar.zst dotfiles-12f18a076f79470941f7ed54ac2de7effcbff740.zip | |
neovim: refactor after/ftplugin/*
Diffstat (limited to '.config/nvim/lua/vimrc.lua')
| -rw-r--r-- | .config/nvim/lua/vimrc.lua | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/.config/nvim/lua/vimrc.lua b/.config/nvim/lua/vimrc.lua index 80a02bc..0a2b9d9 100644 --- a/.config/nvim/lua/vimrc.lua +++ b/.config/nvim/lua/vimrc.lua @@ -15,19 +15,6 @@ function vimrc.autocmd(event, filter, callback) end -local conf = {} -conf.SPACE = true -conf.TAB = false -function conf.indent(style, width) - vim.bo.expandtab = style - vim.bo.tabstop = width - vim.bo.shiftwidth = width - vim.bo.softtabstop = width - - if vim.fn.exists(':IndentLinesReset') == 2 then - vim.cmd('IndentLinesReset') - end -end function vimrc.after_ftplugin(ft, callback) local var_name = 'did_ftplugin_' .. ft .. '_after' @@ -42,4 +29,52 @@ end +local SPACE = true +local TAB = false + +local indentation_settings = { + c = { style = SPACE, width = 4 }, + cmake = { style = SPACE, width = 2 }, + cpp = { style = SPACE, width = 4 }, + css = { style = SPACE, width = 2 }, + go = { style = TAB, width = 4 }, + haskell = { style = SPACE, width = 4 }, + html = { style = SPACE, width = 2 }, + javascript = { style = SPACE, width = 2 }, + json = { style = SPACE, width = 2 }, + lisp = { style = SPACE, width = 2 }, + lua = { style = SPACE, width = 3 }, + markdown = { style = SPACE, width = 4 }, + php = { style = SPACE, width = 2 }, + python = { style = SPACE, width = 4 }, + ruby = { style = SPACE, width = 2 }, + toml = { style = SPACE, width = 2 }, + typescript = { style = SPACE, width = 2 }, + vim = { style = SPACE, width = 4 }, + yaml = { style = SPACE, width = 2 }, +} + +function vimrc.register_filetype_autocmds_for_indentation() + for ft, setting in pairs(indentation_settings) do + vim.cmd(([[autocmd Vimrc FileType %s call v:lua.vimrc._set_indentation(%s, %d)]]):format( + ft, + setting.style and 'v:true' or 'v:false', + setting.width + )) + end +end + +function vimrc._set_indentation(style, width) + vim.bo.expandtab = style + vim.bo.tabstop = width + vim.bo.shiftwidth = width + vim.bo.softtabstop = width + + if vim.fn.exists(':IndentLinesReset') == 2 then + vim.cmd('IndentLinesReset') + end +end + + + return vimrc |
