From 6d739e9ce5a0c248683dfc5e760317a55b281f0d Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Sun, 6 Aug 2023 08:49:51 +0200 Subject: [PATCH] Add Formatter Plugin --- UltiSnips/python.snippets | 18 +++++ init.lua | 136 ++++++++++++++++++++++++++------------ lastSession.vi | 19 +++--- lua/plugins.lua | 1 + viml/legacyconf.vim | 6 ++ 5 files changed, 128 insertions(+), 52 deletions(-) diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets index 5216672..47ac20a 100644 --- a/UltiSnips/python.snippets +++ b/UltiSnips/python.snippets @@ -8,3 +8,21 @@ Created on: `date` $0 endsnippet +snippet def "Python Function" A +def ${1:function}($2): + """ + ${3:function description} + + Args: + ${2} (${4:type}): ${5:description} + + Returns: + $6 ${7:description} + """ + `!p +if t[6] != "" and not t[8].endswith(f"return {t[6]}"): + t[8] = t[8] + f"\n\treturn {t[6]}"` + $8 +$0 +endsnippet + diff --git a/init.lua b/init.lua index 9ebab19..b30a8df 100644 --- a/init.lua +++ b/init.lua @@ -3,19 +3,18 @@ vim.cmd([[ set nocompatible filetype on -filetype plugin on -syntax on +filetype plugin on +syntax on ]]) -vim.opt.number = true +vim.opt.number = true vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true -vim.opt.showmatch = true +vim.opt.showmatch = true vim.opt.cursorline = true -vim.opt.hlsearch = true -vim.opt.encoding = 'UTF-8' +vim.opt.hlsearch = true +vim.opt.encoding = "UTF-8" vim.g.tex_flavor = "latex" -vim.g.clipboard = true vim.opt.conceallevel = 2 vim.opt.guifont = "DroidSansMono Nerd Font 11" @@ -26,25 +25,76 @@ colorscheme slate ]]) -- vim.cmd('source ~/.config/nvim/viml/plugins.vim') -require('plugins') +require("plugins") -- UltiSnipsConfig -vim.g.UltiSnipsExpandTrigger="" -vim.g.UltiSnipsJumpForwardTrigger="" -vim.g.UltiSnipsJumpBackwardTrigger="" -vim.g.UltiSnipsEditSplit="vertical" -vim.g.UltiSnipsSnippetDirectories={"~/.config/nvim/UltiSnips"} +vim.g.UltiSnipsExpandTrigger = "" +vim.g.UltiSnipsJumpForwardTrigger = "" +vim.g.UltiSnipsJumpBackwardTrigger = "" +vim.g.UltiSnipsEditSplit = "vertical" +vim.g.UltiSnipsSnippetDirectories = { "~/.config/nvim/UltiSnips" } -- indentLine config -vim.g.indentLine_char = '▏' +vim.g.indentLine_char = "▏" -- NERDTree Config vim.g.NERDTreeShowHidden = 1 --- Vim Lexima +-- Vim Lexima vim.g.lexima_enable_basic_rules = 1 vim.g.lexima_enable_newline_rules = 1 +-- Nvim Formatter +-- Utilities for creating configurations +local util = require("formatter.util") + +-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands +require("formatter").setup({ + -- Enable or disable logging + logging = true, + -- Set the log level + log_level = vim.log.levels.WARN, + -- All formatter configurations are opt-in + filetype = { + -- Formatter configurations for filetype "lua" go here + -- and will be executed in order + lua = { + -- "formatter.filetypes.lua" defines default configurations for the + -- "lua" filetype + require("formatter.filetypes.lua").stylua, + + -- You can also define your own configuration + function() + -- Supports conditional formatting + if util.get_current_buffer_file_name() == "special.lua" then + return nil + end + + -- Full specification of configurations is down below and in Vim help + -- files + return { + exe = "stylua", + args = { + "--search-parent-directories", + "--stdin-filepath", + util.escape_path(util.get_current_buffer_file_path()), + "--", + "-", + }, + stdin = true, + } + end, + }, + + -- Use the special "*" filetype for defining formatter configurations on + -- any filetype + ["*"] = { + -- "formatter.filetypes.any" defines default configurations for any + -- filetype + require("formatter.filetypes.any").remove_trailing_whitespace, + }, + }, +}) -- YCM config -- replace tab by crtl-k -- vim.cmd("let g:ycm_key_list_select_completion = ['']") @@ -52,60 +102,60 @@ vim.g.lexima_enable_newline_rules = 1 -- vim.g.ycm_global_ycm_extra_conf = '~/.config/nvim/python/.ycm_extra_conf.py' -- Treesitter config -local configs = require'nvim-treesitter.configs' -configs.setup { - ensure_installed = {'python', 'c', 'cpp', 'lua', 'make', 'markdown'}, +local configs = require("nvim-treesitter.configs") +configs.setup({ + ensure_installed = { "python", "c", "cpp", "lua", "make", "markdown" }, highlight = { - enable = true; + enable = true, }, indent = { enable = true, }, rainbow = { enable = true, - -- disable = {"langtodisable"}, + -- disable = {"langtodisable"}, extended_mode = true, max_file_lines = 50000, - -- colors = {}, -- hex strings - -- termcolors = {}, -- color names - } -} + -- colors = {}, -- hex strings + -- termcolors = {}, -- color names + }, +}) -- Let Treesitter fold with and , but keeps buffers unfolded on enter vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" vim.opt.foldenable = false --- Mason setup +-- Mason setup require("mason").setup(require("mason").setup({ - ui = { - icons = { - package_installed = "✓", - package_pending = "➜", - package_uninstalled = "✗" - } - } + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗", + }, + }, })) require("mason-lspconfig").setup({ - ensure_installed = {"clangd", "cmake", "jdtls", "texlab", "pylsp"} + ensure_installed = { "clangd", "cmake", "jdtls", "texlab", "pylsp" }, }) -require("mason-lspconfig").setup_handlers { - function (clangd) - require("lspconfig")[clangd].setup {} - end -} +require("mason-lspconfig").setup_handlers({ + function(clangd) + require("lspconfig")[clangd].setup({}) + end, +}) -local wilder = require('wilder') -wilder.setup({modes = {':', '/', '?'}, next_key= '', previous_key= '', accept_key= '', reject_key= ''}) +local wilder = require("wilder") +wilder.setup({ modes = { ":", "/", "?" } }) --, next_key= '', previous_key= '', accept_key= '', reject_key= ''}) require("code-completion") -- neovide configuration if vim.g.neovide then - vim.o.guifont = "DroidSansMono Nerd Font:8" - vim.g.neovide_scale_factor = 1.0 + vim.o.guifont = "DroidSansMono Nerd Font:8" + vim.g.neovide_scale_factor = 1.0 end -vim.cmd('source ~/.config/nvim/viml/legacyconf.vim') +vim.cmd("source ~/.config/nvim/viml/legacyconf.vim") diff --git a/lastSession.vi b/lastSession.vi index 594c033..0aab68c 100644 --- a/lastSession.vi +++ b/lastSession.vi @@ -3,7 +3,7 @@ let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=- let v:this_session=expand(":p") silent only silent tabonly -cd ~/.config/nvim +cd ~ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' let s:wipebuf = bufnr('%') endif @@ -13,26 +13,26 @@ if &shortmess =~ 'A' else set shortmess=aoO endif -badd +19 UltiSnips/all.snippets +badd +1 .config/nvim/init.lua argglobal %argdel -$argadd UltiSnips/all.snippets -edit UltiSnips/all.snippets +$argadd .config/nvim/init.lua +edit .config/nvim/init.lua argglobal -setlocal fdm=syntax +setlocal fdm=expr setlocal fde=nvim_treesitter#foldexpr() setlocal fmr={{{,}}} setlocal fdi=# -setlocal fdl=99 +setlocal fdl=0 setlocal fml=1 setlocal fdn=20 setlocal nofen -let s:l = 19 - ((18 * winheight(0) + 25) / 50) +let s:l = 1 - ((0 * winheight(0) + 23) / 47) if s:l < 1 | let s:l = 1 | endif keepjumps exe s:l normal! zt -keepjumps 19 -normal! 056| +keepjumps 1 +normal! 0 tabnext 1 if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal' silent exe 'bwipe ' . s:wipebuf @@ -46,6 +46,7 @@ if filereadable(s:sx) endif let &g:so = s:so_save | let &g:siso = s:siso_save set hlsearch +nohlsearch doautoall SessionLoadPost unlet SessionLoad " vim: set ft=vim : diff --git a/lua/plugins.lua b/lua/plugins.lua index 154f146..bd97227 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -42,4 +42,5 @@ return require('packer').startup(function(use) use({"petertriho/cmp-git", requires = "nvim-lua/plenary.nvim"}) use 'quangnguyen30192/cmp-nvim-ultisnips' use 'ryanoasis/vim-devicons' + use 'mhartington/formatter.nvim' end) diff --git a/viml/legacyconf.vim b/viml/legacyconf.vim index 6759a38..472c219 100644 --- a/viml/legacyconf.vim +++ b/viml/legacyconf.vim @@ -16,6 +16,12 @@ set splitbelow set clipboard+=unnamedplus +" Autoformat on save +augroup FormatAutogroup + autocmd! + autocmd BufWritePost * FormatWrite +augroup END + " Update Plugins and Treesitter languages autocmd VimLeave * mksession! ~/.config/nvim/lastSession.vi