From 484188c99b21e668f40b84b21d1b21f5b9ce8d9e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 8 Oct 2021 13:40:08 +0300 Subject: nvim: autocommands --- .config/nvim/init.lua | 1 + .config/nvim/lua/au.lua | 50 ++++++++++++++++++++++++++++++ .config/nvim/lua/autocmds.lua | 59 ++++++++++++++++++++++++++++++++++++ .config/nvim/lua/plugin_settings.lua | 2 +- .config/nvim/lua/plugins.lua | 12 +++----- 5 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 .config/nvim/lua/au.lua create mode 100644 .config/nvim/lua/autocmds.lua (limited to '.config/nvim') diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index ae54ee1..9dcc9b5 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -13,5 +13,6 @@ require('plugins') require('settings') +require('autocmds') require('mappings') require('plugin_settings') diff --git a/.config/nvim/lua/au.lua b/.config/nvim/lua/au.lua new file mode 100644 index 0000000..305169c --- /dev/null +++ b/.config/nvim/lua/au.lua @@ -0,0 +1,50 @@ +-- +-- https://gist.github.com/numToStr/1ab83dd2e919de9235f9f774ef8076da +-- +local cmd = vim.api.nvim_command + +local function autocmd(this, event, spec) + local is_table = type(spec) == 'table' + local pattern = is_table and spec[1] or '*' + local action = is_table and spec[2] or spec + if type(action) == 'function' then + action = this.set(action) + end + local e = type(event) == 'table' and table.concat(event, ',') or event + cmd('autocmd ' .. e .. ' ' .. pattern .. ' ' .. action) +end + +local S = { + __au = {}, +} + +local X = setmetatable({}, { + __index = S, + __newindex = autocmd, + __call = autocmd, +}) + +function S.exec(id) + S.__au[id]() +end + +function S.set(fn) + local id = string.format('%p', fn) + S.__au[id] = fn + return string.format('lua require("au").exec("%s")', id) +end + +function S.group(grp, cmds) + cmd('augroup ' .. grp) + cmd('autocmd!') + if type(cmds) == 'function' then + cmds(X) + else + for _, au in ipairs(cmds) do + autocmd(S, au[1], { au[2], au[3] }) + end + end + cmd('augroup END') +end + +return X diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua new file mode 100644 index 0000000..295dcc2 --- /dev/null +++ b/.config/nvim/lua/autocmds.lua @@ -0,0 +1,59 @@ +-- ┌─────────────────────────┐ +-- │ ▐ ▌ │ +-- │▝▀▖▌ ▌▜▀ ▞▀▖▞▀▖▛▚▀▖▞▀▌▞▀▘│ +-- │▞▀▌▌ ▌▐ ▖▌ ▌▌ ▖▌▐ ▌▌ ▌▝▀▖│ +-- │▝▀▘▝▀▘ ▀ ▝▀ ▝▀ ▘▝ ▘▝▀▘▀▀ │ +-- └─────────────────────────┘ + +local au = require('au') + +au.TextYankPost = function() + vim.highlight.on_yank({ higroup = 'Visual', timeout = 120 }) +end + +au.BufEnter = { + 'PKGBUILD', + function() + vim.bo.filetype = "PKGBUILD" + end, +} + +-- autocmd FileType vimwiki,latex,tex setlocal formatprg=/home/yigit/.local/bin/sentences +au.FileType = { + 'vimwiki,latex,tex', + function() + vim.bo.formatprg = "/home/yigit/.local/bin/sentences" + end, +} + +-- autocmd VimLeave *.tex !texclear % +au.VimLeave = { + '*.tex', + function() + vim.cmd("!texclear %") + end, +} + +-- autocmd FileType rust let b:dispatch = 'cargo run' +au.FileType = { + 'rust', + function() + vim.b.dispatch = 'cargo run' + end, +} + +-- autocmd VimResized * :wincmd = +au.VimResized = { + '*', + function() + vim.cmd(":wincmd =") + end, +} + +-- autocmd FileType markdown,tex setlocal spell +au.FileType = { + 'markdown,text', + function() + vim.bo.spell = true + end, +} diff --git a/.config/nvim/lua/plugin_settings.lua b/.config/nvim/lua/plugin_settings.lua index 6de7ebd..b10a002 100644 --- a/.config/nvim/lua/plugin_settings.lua +++ b/.config/nvim/lua/plugin_settings.lua @@ -37,7 +37,7 @@ g.vimwiki_hl_headers = 1 -- lualine {{{ -- require'lualine'.setup { options = { - lower = true, + lower = false, icons_enabled = true, theme = 'rose-pine', section_separators = {'', ''}, diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 58cccbc..4f5420f 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -6,7 +6,7 @@ -- └───────────────────┘ return require('packer').startup(function() - -- Packer can manage itself + -- packer can manage itself use 'wbthomason/packer.nvim' -- latex suite @@ -22,8 +22,6 @@ return require('packer').startup(function() use 'jpalardy/vim-slime' -- snippets to expand use {'SirVer/ultisnips', 'honza/vim-snippets'} - -- Highlight the yanked region - use 'machakann/vim-highlightedyank' -- auto pair plugin, people hate these use 'tmsvg/pear-tree' @@ -50,13 +48,13 @@ return require('packer').startup(function() -- displays tags ordered by scope use 'majutsushi/tagbar' - -- Undo tree + -- undo tree use { 'mbbill/undotree', cmd = 'UndotreeToggle', config = [[vim.g.undotree_SetFocusWhenToggle = 1]], } - -- Highlight colors + -- highlight colors use { 'norcalli/nvim-colorizer.lua', ft = { 'css', 'javascript', 'vim', 'html' }, @@ -70,7 +68,7 @@ return require('packer').startup(function() 'svermeulen/vim-yoink' } - -- Personal wiki + -- personal wiki use 'vimwiki/vimwiki' -- centers the writing use 'junegunn/goyo.vim' @@ -78,7 +76,7 @@ return require('packer').startup(function() use 'junegunn/limelight.vim' -- change ASCII text to Turkish text use 'yigitsever/turkish-deasciifier.vim' - + -- text alignment \w :Tab use 'godlygeek/tabular' -- move selections up and down with alt+[j,k] -- cgit v1.2.3-70-g09d2