From 58d49da5c2babf857c29227954fcb242eb461a1d Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Mon, 12 Jun 2023 18:15:10 +0200 Subject: [PATCH] Improve nvim configs --- .config/home-manager/nvim.nix | 1 + .config/nvim/after/plugin/lsp.lua | 7 +++---- .config/nvim/after/plugin/telescope.lua | 2 +- .config/nvim/lua/utils.lua | 21 +++++++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 .config/nvim/lua/utils.lua diff --git a/.config/home-manager/nvim.nix b/.config/home-manager/nvim.nix index 022bbe8..7b79ee0 100644 --- a/.config/home-manager/nvim.nix +++ b/.config/home-manager/nvim.nix @@ -14,6 +14,7 @@ require("set") require("remap") require("plugins") +require("utils") local status, ts_install = pcall(require, "nvim-treesitter.install") if(status) then diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index 37df7f8..a9ef985 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -3,10 +3,9 @@ local lsp = require("lsp-zero") lsp.preset("recommended") lsp.ensure_installed({ - -- 'bashls', - -- 'lua_ls', - -- 'pylsp', - -- 'rnix', + 'bashls', + 'lua_ls', + 'yamlls', }) -- Fix Undefined global 'vim' diff --git a/.config/nvim/after/plugin/telescope.lua b/.config/nvim/after/plugin/telescope.lua index f9a9a36..67b9635 100644 --- a/.config/nvim/after/plugin/telescope.lua +++ b/.config/nvim/after/plugin/telescope.lua @@ -1,6 +1,6 @@ local builtin = require('telescope.builtin') vim.keymap.set('n', 'pf', builtin.find_files, {}) -vim.keymap.set('n', '', builtin.git_files, {}) +vim.keymap.set('n', 'pg', builtin.git_files, {}) vim.keymap.set('n', 'ps', function() builtin.grep_string({ search = vim.fn.input("Grep > ") }) end) diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua new file mode 100644 index 0000000..d03d2be --- /dev/null +++ b/.config/nvim/lua/utils.lua @@ -0,0 +1,21 @@ +-- Check file extension and set syntax highlighting +vim.cmd([[ + augroup Jinja2Syntax + autocmd! + autocmd BufNewFile,BufRead *.j2 lua require('utils').set_jinja2_syntax() + augroup END +]]) + +-- Function to determine Jinja2 syntax highlighting +local function set_jinja2_syntax() + local file_extension = vim.fn.expand("%:e") + if file_extension == "j2" then + local base_filename = vim.fn.expand("%:r") + local base_filetype = vim.fn.fnamemodify(base_filename, ":t") + vim.opt.syntax = base_filetype + end +end + +return { + set_jinja2_syntax = set_jinja2_syntax +}