Add Formatter Plugin

This commit is contained in:
Yannick Reiß 2023-08-06 08:49:51 +02:00
parent 7e6edf6e73
commit 6d739e9ce5
No known key found for this signature in database
GPG Key ID: 5A3AF456F0A0338C
5 changed files with 128 additions and 52 deletions

View File

@ -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

View File

@ -13,9 +13,8 @@ vim.opt.expandtab = true
vim.opt.showmatch = true
vim.opt.cursorline = true
vim.opt.hlsearch = true
vim.opt.encoding = 'UTF-8'
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,7 +25,7 @@ colorscheme slate
]])
-- vim.cmd('source ~/.config/nvim/viml/plugins.vim')
require('plugins')
require("plugins")
-- UltiSnipsConfig
vim.g.UltiSnipsExpandTrigger = "<tab>"
@ -36,7 +35,7 @@ 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
@ -45,6 +44,57 @@ vim.g.NERDTreeShowHidden = 1
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 = ['<c-k>']")
@ -52,11 +102,11 @@ 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,
@ -68,8 +118,8 @@ configs.setup {
max_file_lines = 50000,
-- colors = {}, -- hex strings
-- termcolors = {}, -- color names
}
}
},
})
-- Let Treesitter fold with <zo> and <zc>, but keeps buffers unfolded on enter
vim.opt.foldmethod = "expr"
@ -82,23 +132,23 @@ require("mason").setup(require("mason").setup({
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = ""
}
}
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 {
require("mason-lspconfig").setup_handlers({
function(clangd)
require("lspconfig")[clangd].setup {}
end
}
require("lspconfig")[clangd].setup({})
end,
})
local wilder = require('wilder')
wilder.setup({modes = {':', '/', '?'}, next_key= '<Tab>', previous_key= '<S-Tab>', accept_key= '<c-k>', reject_key= '<Up>'})
local wilder = require("wilder")
wilder.setup({ modes = { ":", "/", "?" } }) --, next_key= '<Tab>', previous_key= '<S-Tab>', accept_key= '<c-k>', reject_key= '<Up>'})
require("code-completion")
@ -108,4 +158,4 @@ if vim.g.neovide then
vim.g.neovide_scale_factor = 1.0
end
vim.cmd('source ~/.config/nvim/viml/legacyconf.vim')
vim.cmd("source ~/.config/nvim/viml/legacyconf.vim")

View File

@ -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("<sfile>: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 :

View File

@ -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)

View File

@ -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