diff options
author | Yigit Sever | 2021-10-08 13:40:08 +0300 |
---|---|---|
committer | Yigit Sever | 2021-10-08 13:40:41 +0300 |
commit | 484188c99b21e668f40b84b21d1b21f5b9ce8d9e (patch) | |
tree | 97592a6667dafe35eb51171c4485208da1e5abba | |
parent | 98795863769fc46b78439b39a97c5d2c057fbb80 (diff) | |
download | dotfiles-484188c99b21e668f40b84b21d1b21f5b9ce8d9e.tar.gz dotfiles-484188c99b21e668f40b84b21d1b21f5b9ce8d9e.tar.bz2 dotfiles-484188c99b21e668f40b84b21d1b21f5b9ce8d9e.zip |
nvim: autocommands
-rw-r--r-- | .config/nvim/init.lua | 1 | ||||
-rw-r--r-- | .config/nvim/lua/au.lua | 50 | ||||
-rw-r--r-- | .config/nvim/lua/autocmds.lua | 59 | ||||
-rw-r--r-- | .config/nvim/lua/plugin_settings.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/plugins.lua | 12 |
5 files changed, 116 insertions, 8 deletions
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 @@ | |||
13 | 13 | ||
14 | require('plugins') | 14 | require('plugins') |
15 | require('settings') | 15 | require('settings') |
16 | require('autocmds') | ||
16 | require('mappings') | 17 | require('mappings') |
17 | require('plugin_settings') | 18 | 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 @@ | |||
1 | -- | ||
2 | -- https://gist.github.com/numToStr/1ab83dd2e919de9235f9f774ef8076da | ||
3 | -- | ||
4 | local cmd = vim.api.nvim_command | ||
5 | |||
6 | local function autocmd(this, event, spec) | ||
7 | local is_table = type(spec) == 'table' | ||
8 | local pattern = is_table and spec[1] or '*' | ||
9 | local action = is_table and spec[2] or spec | ||
10 | if type(action) == 'function' then | ||
11 | action = this.set(action) | ||
12 | end | ||
13 | local e = type(event) == 'table' and table.concat(event, ',') or event | ||
14 | cmd('autocmd ' .. e .. ' ' .. pattern .. ' ' .. action) | ||
15 | end | ||
16 | |||
17 | local S = { | ||
18 | __au = {}, | ||
19 | } | ||
20 | |||
21 | local X = setmetatable({}, { | ||
22 | __index = S, | ||
23 | __newindex = autocmd, | ||
24 | __call = autocmd, | ||
25 | }) | ||
26 | |||
27 | function S.exec(id) | ||
28 | S.__au[id]() | ||
29 | end | ||
30 | |||
31 | function S.set(fn) | ||
32 | local id = string.format('%p', fn) | ||
33 | S.__au[id] = fn | ||
34 | return string.format('lua require("au").exec("%s")', id) | ||
35 | end | ||
36 | |||
37 | function S.group(grp, cmds) | ||
38 | cmd('augroup ' .. grp) | ||
39 | cmd('autocmd!') | ||
40 | if type(cmds) == 'function' then | ||
41 | cmds(X) | ||
42 | else | ||
43 | for _, au in ipairs(cmds) do | ||
44 | autocmd(S, au[1], { au[2], au[3] }) | ||
45 | end | ||
46 | end | ||
47 | cmd('augroup END') | ||
48 | end | ||
49 | |||
50 | 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 @@ | |||
1 | -- ┌─────────────────────────┐ | ||
2 | -- │ ▐ ▌ │ | ||
3 | -- │▝▀▖▌ ▌▜▀ ▞▀▖▞▀▖▛▚▀▖▞▀▌▞▀▘│ | ||
4 | -- │▞▀▌▌ ▌▐ ▖▌ ▌▌ ▖▌▐ ▌▌ ▌▝▀▖│ | ||
5 | -- │▝▀▘▝▀▘ ▀ ▝▀ ▝▀ ▘▝ ▘▝▀▘▀▀ │ | ||
6 | -- └─────────────────────────┘ | ||
7 | |||
8 | local au = require('au') | ||
9 | |||
10 | au.TextYankPost = function() | ||
11 | vim.highlight.on_yank({ higroup = 'Visual', timeout = 120 }) | ||
12 | end | ||
13 | |||
14 | au.BufEnter = { | ||
15 | 'PKGBUILD', | ||
16 | function() | ||
17 | vim.bo.filetype = "PKGBUILD" | ||
18 | end, | ||
19 | } | ||
20 | |||
21 | -- autocmd FileType vimwiki,latex,tex setlocal formatprg=/home/yigit/.local/bin/sentences | ||
22 | au.FileType = { | ||
23 | 'vimwiki,latex,tex', | ||
24 | function() | ||
25 | vim.bo.formatprg = "/home/yigit/.local/bin/sentences" | ||
26 | end, | ||
27 | } | ||
28 | |||
29 | -- autocmd VimLeave *.tex !texclear % | ||
30 | au.VimLeave = { | ||
31 | '*.tex', | ||
32 | function() | ||
33 | vim.cmd("!texclear %") | ||
34 | end, | ||
35 | } | ||
36 | |||
37 | -- autocmd FileType rust let b:dispatch = 'cargo run' | ||
38 | au.FileType = { | ||
39 | 'rust', | ||
40 | function() | ||
41 | vim.b.dispatch = 'cargo run' | ||
42 | end, | ||
43 | } | ||
44 | |||
45 | -- autocmd VimResized * :wincmd = | ||
46 | au.VimResized = { | ||
47 | '*', | ||
48 | function() | ||
49 | vim.cmd(":wincmd =") | ||
50 | end, | ||
51 | } | ||
52 | |||
53 | -- autocmd FileType markdown,tex setlocal spell | ||
54 | au.FileType = { | ||
55 | 'markdown,text', | ||
56 | function() | ||
57 | vim.bo.spell = true | ||
58 | end, | ||
59 | } | ||
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 | |||
37 | -- lualine {{{ -- | 37 | -- lualine {{{ -- |
38 | require'lualine'.setup { | 38 | require'lualine'.setup { |
39 | options = { | 39 | options = { |
40 | lower = true, | 40 | lower = false, |
41 | icons_enabled = true, | 41 | icons_enabled = true, |
42 | theme = 'rose-pine', | 42 | theme = 'rose-pine', |
43 | section_separators = {'', ''}, | 43 | 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 @@ | |||
6 | -- └───────────────────┘ | 6 | -- └───────────────────┘ |
7 | 7 | ||
8 | return require('packer').startup(function() | 8 | return require('packer').startup(function() |
9 | -- Packer can manage itself | 9 | -- packer can manage itself |
10 | use 'wbthomason/packer.nvim' | 10 | use 'wbthomason/packer.nvim' |
11 | 11 | ||
12 | -- latex suite | 12 | -- latex suite |
@@ -22,8 +22,6 @@ return require('packer').startup(function() | |||
22 | use 'jpalardy/vim-slime' | 22 | use 'jpalardy/vim-slime' |
23 | -- snippets to expand | 23 | -- snippets to expand |
24 | use {'SirVer/ultisnips', 'honza/vim-snippets'} | 24 | use {'SirVer/ultisnips', 'honza/vim-snippets'} |
25 | -- Highlight the yanked region | ||
26 | use 'machakann/vim-highlightedyank' | ||
27 | 25 | ||
28 | -- auto pair plugin, people hate these | 26 | -- auto pair plugin, people hate these |
29 | use 'tmsvg/pear-tree' | 27 | use 'tmsvg/pear-tree' |
@@ -50,13 +48,13 @@ return require('packer').startup(function() | |||
50 | 48 | ||
51 | -- displays tags ordered by scope | 49 | -- displays tags ordered by scope |
52 | use 'majutsushi/tagbar' | 50 | use 'majutsushi/tagbar' |
53 | -- Undo tree | 51 | -- undo tree |
54 | use { | 52 | use { |
55 | 'mbbill/undotree', | 53 | 'mbbill/undotree', |
56 | cmd = 'UndotreeToggle', | 54 | cmd = 'UndotreeToggle', |
57 | config = [[vim.g.undotree_SetFocusWhenToggle = 1]], | 55 | config = [[vim.g.undotree_SetFocusWhenToggle = 1]], |
58 | } | 56 | } |
59 | -- Highlight colors | 57 | -- highlight colors |
60 | use { | 58 | use { |
61 | 'norcalli/nvim-colorizer.lua', | 59 | 'norcalli/nvim-colorizer.lua', |
62 | ft = { 'css', 'javascript', 'vim', 'html' }, | 60 | ft = { 'css', 'javascript', 'vim', 'html' }, |
@@ -70,7 +68,7 @@ return require('packer').startup(function() | |||
70 | 'svermeulen/vim-yoink' | 68 | 'svermeulen/vim-yoink' |
71 | } | 69 | } |
72 | 70 | ||
73 | -- Personal wiki | 71 | -- personal wiki |
74 | use 'vimwiki/vimwiki' | 72 | use 'vimwiki/vimwiki' |
75 | -- centers the writing | 73 | -- centers the writing |
76 | use 'junegunn/goyo.vim' | 74 | use 'junegunn/goyo.vim' |
@@ -78,7 +76,7 @@ return require('packer').startup(function() | |||
78 | use 'junegunn/limelight.vim' | 76 | use 'junegunn/limelight.vim' |
79 | -- change ASCII text to Turkish text | 77 | -- change ASCII text to Turkish text |
80 | use 'yigitsever/turkish-deasciifier.vim' | 78 | use 'yigitsever/turkish-deasciifier.vim' |
81 | 79 | ||
82 | -- text alignment \w :Tab | 80 | -- text alignment \w :Tab |
83 | use 'godlygeek/tabular' | 81 | use 'godlygeek/tabular' |
84 | -- move selections up and down with alt+[j,k] | 82 | -- move selections up and down with alt+[j,k] |