myhome/.config/nvim/init.vim

667 lines
18 KiB
VimL
Raw Normal View History

2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Download vim-plug
""""""""""""""""""""""""""""""""
if has('nvim')
2022-01-02 01:36:22 +01:00
if ! filereadable(system('echo -n "$HOME/.config/nvim/autoload/plug.vim"'))
silent !mkdir -p $HOME/.config/nvim/autoload/
silent !curl --silent "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > $HOME/.config/nvim/autoload/plug.vim
autocmd VimEnter * PlugInstall
endif
endif
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Default settings nvim
""""""""""""""""""""""""""""""""
2021-10-17 21:06:19 +02:00
let g:python3_host_prog = expand('/usr/bin/python3')
let g:loaded_python_provider = 0
let g:python_host_prog = ''
2021-09-29 20:17:26 +02:00
set autoindent
2022-01-06 01:04:04 +01:00
set expandtab
set softtabstop=4
2022-01-02 01:27:27 +01:00
set shiftwidth=4
set tabstop=4
set nocompatible
set noshowmode
2021-10-31 23:57:39 +01:00
set noerrorbells
2023-06-17 17:10:15 +02:00
set wrap
2021-10-31 23:57:39 +01:00
set hidden
set cmdheight=1
set encoding=utf-8
set undofile
set scrolloff=8
set termguicolors
2021-09-22 14:44:51 +02:00
set t_BE=
au BufWritePre * let &bex = '@' . strftime("%F.%H:%M")
filetype plugin indent on
syntax on
2021-11-01 00:20:50 +01:00
" Disable by default indent line
" let g:indentLine_enabled = 0
" ansible
let g:ansible_extra_keywords_highlight = 1
" line numbers
set number
set ruler
set title
" indent
set backspace=indent,eol,start
2022-01-06 01:04:34 +01:00
"set list listchars=nbsp:¬,tab:»·,trail:·,extends:>
set list listchars=tab:\│\ ,trail
let g:indentLine_char_list = ['│', '│', '│', '│']
2021-11-01 00:20:50 +01:00
" editing
runtime! macros/matchit.vim
" visual feedback
set laststatus=2
set showmode
set showcmd
" off mouse
set mouse-=a
" disable pcspkr beep
set visualbell
set t_vb=
" searching
set smartcase
set ic
" cursor
2021-11-18 12:47:45 +01:00
set guicursor=
2021-11-20 14:58:15 +01:00
set guicursor+=a:blinkon0
2021-11-01 00:20:50 +01:00
let &t_SI = "\<esc>[6 q"
2021-11-20 14:58:15 +01:00
let &t_SR = "\<esc>[6 q"
let &t_EI = "\<esc>[6 q"
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Plugins
""""""""""""""""""""""""""""""""
call plug#begin('~/.config/nvim/plugged')
" Markdown
Plug 'tpope/vim-markdown'
2022-05-21 11:44:40 +02:00
" Live-preview
Plug 'nmante/vim-latex-live-preview'
" Goyo plugin for writing mutt mail
Plug 'junegunn/goyo.vim'
2021-10-30 23:48:37 +02:00
" Themes
2021-09-22 14:44:51 +02:00
Plug 'gruvbox-community/gruvbox', { 'as': 'gruvbox'}
2021-12-12 22:02:16 +01:00
Plug 'Mofiqul/dracula.nvim'
" Fzf plugin
2021-10-30 10:02:01 +02:00
Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf'
2021-10-24 15:48:54 +02:00
" CSS
Plug 'ap/vim-css-color'
2022-01-06 01:06:35 +01:00
" Copilot
Plug 'github/copilot.vim'
" PyRight
Plug 'sakhnik/nvim-gdb', { 'do': ':!./install.sh' }
" Ansible yaml
Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }
2021-10-30 22:45:48 +02:00
Plug 'Yggdroot/indentLine'
" Terraform
Plug 'hashivim/vim-terraform'
2023-01-04 11:45:15 +01:00
" GoLang
Plug 'fatih/vim-go'
" Multiple cursors
Plug 'terryma/vim-multiple-cursors'
" Enable gentoo-syntax in vim
Plug 'gentoo/gentoo-syntax'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
2021-09-22 14:44:51 +02:00
Plug 'junegunn/vim-easy-align'
2022-01-01 02:31:26 +01:00
" Git tool
Plug 'tpope/vim-fugitive'
2022-10-01 23:14:37 +02:00
" Prettier
Plug 'prettier/vim-prettier', { 'do': 'yarn install --frozen-lockfile --production' }
2022-01-06 01:06:35 +01:00
" Debug
Plug 'puremourning/vimspector'
Plug 'mfussenegger/nvim-dap'
2022-04-20 20:58:25 +02:00
" LSP
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
2022-04-20 20:58:25 +02:00
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'L3MON4D3/LuaSnip'
Plug 'sbdchd/neoformat'
Plug 'hrsh7th/cmp-vsnip'
2022-11-21 22:21:51 +01:00
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
2022-04-21 12:19:10 +02:00
" Telescope
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
2022-05-21 11:44:40 +02:00
" Tree
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-tree/nvim-tree.lua'
2022-08-25 08:54:44 +02:00
" SHFMT
2022-08-25 08:54:44 +02:00
Plug 'z0mbix/vim-shfmt', { 'for': 'sh' }
" Mikrotik
2022-10-15 14:54:38 +02:00
Plug 'zainin/vim-mikrotik'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-treesitter/nvim-treesitter-context'
2022-04-20 20:58:25 +02:00
call plug#end()
2022-04-20 20:58:25 +02:00
" LUA
lua<<EOF
local opts = { noremap=true, silent=true }
local capabilities = vim.lsp.protocol.make_client_capabilities()
2022-11-18 12:30:35 +01:00
capabilities = require('cmp_nvim_lsp').default_capabilities()
2022-04-20 20:58:25 +02:00
local lspconfig = require('lspconfig')
local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
2022-10-15 14:53:59 +02:00
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ge', '<cmd>lua vim.diagnostic.setqflist()<CR>', opts)
2022-04-20 20:58:25 +02:00
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
2022-04-29 13:17:13 +02:00
-- LSP settings (for overriding per client)
local handlers = {
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border}),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {border = border }),
}
2022-04-20 20:58:25 +02:00
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'bashls', 'yamlls', 'ansiblels', 'gopls', 'solargraph', 'terraformls', 'tflint' }
2022-04-20 20:58:25 +02:00
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
2022-04-29 13:17:13 +02:00
handlers=handlers,
2022-04-20 20:58:25 +02:00
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
}
}
end
-- Handlers when you are in the insert mode you see the errors
vim.lsp.handlers["textDocument/publishDiagnostics"] =
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics,
{update_in_insert = true})
2022-04-29 13:17:37 +02:00
-- Setup a yamlls plugin
require'lspconfig'.yamlls.setup{
settings = {
json = {
2022-04-26 09:48:13 +02:00
schemas = {
["https://raw.githubusercontent.com/quantumblacklabs/kedro/develop/static/jsonschema/kedro-catalog-0.17.json"]= "conf/**/*catalog*",
["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*",
["https://github.com/ansible/schemas/blob/main/f/ansible.json"] = "*.yaml,*.yml"
}
},
yaml = {
keyOrdering = false
},
}
}
2022-05-21 11:44:18 +02:00
-- Setup GoLang
require'lspconfig'.gopls.setup {
cmd = {"gopls", "serve"},
filetypes = {"go", "gomod"},
on_attach = on_attach,
handlers=handlers,
capabilities = capabilities,
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
linksInHover = false,
codelenses = {
generate = true,
gc_details = true,
regenerate_cgo = true,
tidy = true,
upgrade_depdendency = true,
vendor = true,
},
usePlaceholders = true,
},
},
}
2022-04-20 20:58:25 +02:00
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-a>'] = cmp.mapping.scroll_docs(-4),
['<C-s>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'vsnip' },
{ name = 'ultisnips' },
{ name = 'snippy' },
2022-04-27 10:43:27 +02:00
{ name = 'path' },
{ name = 'buffer' }
2022-04-20 20:58:25 +02:00
},
}
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
require("nvim-tree").setup({
})
2022-05-21 11:44:18 +02:00
require'treesitter-context'.setup{}
2022-04-20 20:58:25 +02:00
EOF
" Added popout window to see diagnostic
set updatetime=250
autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})
2022-04-20 20:58:25 +02:00
" Neoformat
let g:neoformat_try_formatprg = 1
let g:neoformat_basic_format_trim = 1
let g:neoformat_only_msg_on_error = 1
2023-01-16 09:48:16 +01:00
" autocmd BufWritePre * silent! undojoin | Neoformat
let g:neoformat_python_black = {
\ 'exe': 'black',
\ 'stdin': 1,
\ 'args': ['--line-length', '80', '-q', '-'],
\ }
let g:neoformat_enabled_python = ['black']
2022-04-20 20:58:25 +02:00
" Terraform
let g:terraform_fmt_on_save=1
let g:terraform_align=1
2021-10-30 23:18:43 +02:00
2021-10-24 15:47:37 +02:00
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
2021-11-01 00:20:50 +01:00
" Enable show hidden in NerdTree
let NERDTreeShowHidden=1
2021-10-24 15:47:37 +02:00
2021-11-01 00:20:50 +01:00
" latex
let g:tex_flavor = "latex"
2021-10-24 15:48:14 +02:00
2022-01-06 01:06:35 +01:00
" Debug
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-go', 'CodeLLDB', 'vscode-node-debug2' ]
2022-01-01 02:31:26 +01:00
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Theme
""""""""""""""""""""""""""""""""
2021-11-14 01:03:33 +01:00
"colorscheme gruvbox
"colorscheme default
2022-02-01 00:13:44 +01:00
colorscheme dracula
2021-11-01 00:20:50 +01:00
let g:gruvbox_invert_selection='0'
let g:gruvbox_contrast_dark = 'hard'
set background=dark
"hi Normal ctermbg=NONE
hi Pmenu ctermfg=NONE ctermbg=236 cterm=NONE guifg=NONE guibg=#64666d gui=NONE
hi PmenuSel ctermfg=NONE ctermbg=246 cterm=NONE guifg=NONE guibg=#204a87 gui=NONE
hi CursorLine cterm=NONE term=NONE ctermbg=NONE guibg=NONE
hi CursorLine ctermbg=235
hi DiffAdd cterm=BOLD ctermfg=NONE ctermbg=22
hi DiffDelete cterm=BOLD ctermfg=NONE ctermbg=52
hi DiffChange cterm=BOLD ctermfg=NONE ctermbg=23
hi DiffText cterm=BOLD ctermfg=NONE ctermbg=23
set t_ZH="\e[3m"
set t_ZR="\e[23m"
highlight Comment cterm=italic gui=italic
highlight htmlArg gui=italic cterm=italic
2021-10-31 22:26:14 +01:00
2021-11-01 00:20:50 +01:00
" columne
set textwidth=80
set colorcolumn=80
highlight ColorColumn ctermbg=236
""""""""""""""""""""""""""""""""
" Status Line
""""""""""""""""""""""""""""""""
2021-11-16 16:53:03 +01:00
function! GitBranch()
2022-01-02 01:37:32 +01:00
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
2021-11-16 16:53:03 +01:00
endfunction
function! StatuslineGit()
2022-01-02 01:37:32 +01:00
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
2021-11-16 16:53:03 +01:00
endfunction
set statusline=
set statusline+=%#IncSearch#
set statusline+=%{&filetype!=#''?'\ \ ['.&filetype.']\ ':'\ '}
set statusline+=%{&modified?'[+]\ ':''}
set statusline+=%#CursorLineNr#
set statusline+=\ %F
set statusline+=%= "Right side settings
set statusline+=%#CursorLineNr#
2021-11-16 16:53:03 +01:00
set statusline+=%{StatuslineGit()}
set statusline+=%#Search#
set statusline+=\ %l/%L
set statusline+=\ [%c]
2022-01-06 01:06:20 +01:00
" Disable godoc keys
let g:go_doc_keywordprg_enabled = 0
set completeopt-=preview
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Keyboard shortcuts
""""""""""""""""""""""""""""""""
let mapleader = "\<Space>"
2021-11-01 10:42:41 +01:00
nmap <leader>2 :w!<cr>
2022-07-18 22:59:51 +02:00
" Adding print message
2022-09-05 10:41:04 +02:00
autocmd FileType python nmap <leader>f i print("--------DEBUG--------")<CR>print()<CR>print("--------END DEBUG--------")<UP><LEFT>
2022-07-18 22:59:51 +02:00
autocmd FileType sh nmap <leader>f i echo -e "--------DEBUG--------"<CR>echo -e ""<CR>echo -e "--------END DEBUG--------"<UP><LEFT>
2021-11-24 15:52:24 +01:00
" Adding commentary
2021-11-01 00:20:50 +01:00
xmap <leader>c <Plug>Commentary
nmap <leader>c <Plug>Commentary
omap <leader>c <Plug>Commentary
2021-11-24 15:52:24 +01:00
nmap <leader>c <Plug>CommentaryLine
xmap <C-_> <Plug>Commentary
nmap <C-_> <Plug>Commentary
omap <C-_> <Plug>Commentary
nmap <C-_> <Plug>CommentaryLine
2021-11-01 00:20:50 +01:00
" Better tab
vnoremap <Tab> >
vnoremap <S-Tab> <
2022-09-10 14:00:25 +02:00
" Better word
nmap yw vey
2022-09-10 14:00:44 +02:00
" Select all text
nmap <C-a> gg<S-v>G
2022-04-21 12:19:10 +02:00
" Telescope
nmap <Leader>e <cmd>Telescope buffers<cr>
nmap <Leader>w <cmd>Telescope find_files<cr>
nmap <Leader>q <cmd>Telescope live_grep<cr>
nmap <Leader>g <cmd>Telescope git_branches<cr>
2022-10-15 14:53:59 +02:00
nmap <Leader>a <cmd>Telescope diagnostics<cr>
2021-10-24 15:48:54 +02:00
" Resize window
nnoremap <C-L> :vertical resize +5<CR>
nnoremap <C-H> :vertical resize -5<CR>
2022-09-13 08:33:44 +02:00
nnoremap <C-J> :res -5<CR>
nnoremap <C-K> :res +5<CR>
" Split window
nnoremap _ :vsp <CR>
nnoremap - :split <CR>
" Reload file
nnoremap <F5> :edit <CR>
nnoremap <Leader><F5> :edit! <CR>
2021-11-01 00:20:50 +01:00
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
2022-04-20 20:58:25 +02:00
" Moving line up or down using alt
nnoremap <A-Up> :m-2<CR>
nnoremap <A-Down> :m+<CR>
inoremap <A-Up> <Esc>:m-2<CR>
inoremap <A-Down> <Esc>:m+<CR>
vnoremap <A-Down> :m '>+1<CR>gv=gv
vnoremap <A-Up> :m '<-2<CR>gv=gv
nnoremap Ż :m-2<CR>
nnoremap ∆ :m+<CR>
vnoremap ∆ :m '>+1<CR>gv=gv
vnoremap Ż :m '<-2<CR>gv=gv
nnoremap <A-k> :m-2<CR>
nnoremap <A-j> :m+<CR>
inoremap <A-k> <Esc>:m-2<CR>
inoremap <A-j> <Esc>:m+<CR>
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
2021-11-01 00:20:50 +01:00
" Better replace
2021-12-12 10:17:39 +01:00
nnoremap <Leader>s :%s//g<Left><Left>
vnoremap <Leader>s :s//g<Left><Left>
2021-11-01 00:20:50 +01:00
" Better adding into begging and ending line
vnoremap F <C-v>$A
vnoremap f <C-v>0I
" Better management of tabs
2022-08-29 15:11:12 +02:00
nnoremap <C-t> :tabnew<CR>
2022-03-26 18:02:58 +01:00
nnoremap <F7> :tabprevious<CR>
nnoremap <F8> :tabnext<CR>
2022-07-23 14:06:52 +02:00
inoremap <F7> <Esc>:tabprevious<CR>i
inoremap <F8> <Esc>:tabnext<CR>i
2022-08-29 15:11:12 +02:00
nnoremap <Leader>k :tabprevious<CR>
nnoremap <Leader>j :tabnext<CR>
2022-07-23 14:06:52 +02:00
inoremap <C-t> <Esc>:tabnew<CR>
2021-11-01 10:42:34 +01:00
" Better moving
nnoremap J }
nnoremap K {
2022-09-10 14:00:57 +02:00
vnoremap J }
vnoremap K {
" Copy into system
noremap <Leader>y "*y
noremap <Leader>p "*p
2021-09-22 14:44:51 +02:00
" Code
map <Leader><Tab> Vgaip= <CR>
2021-11-01 00:20:50 +01:00
" Multiple cursors
let g:multi_cursor_start_word_key = '<C-n>'
let g:multi_cursor_select_all_word_key = '<A-n>'
let g:multi_cursor_start_key = 'g<C-n>'
let g:multi_cursor_select_all_key = 'g<A-n>'
let g:multi_cursor_next_key = '<C-n>'
let g:multi_cursor_prev_key = '<C-p>'
let g:multi_cursor_skip_key = '<C-x>'
let g:multi_cursor_quit_key = '<Esc>'
" Others
nnoremap ee :!mupdf $(echo % \| sed 's/tex$/pdf/') & disown<CR><CR>
2022-05-21 11:44:40 +02:00
map <C-d> :NvimTreeToggle<CR>
nnoremap <leader>r :NvimTreeRefresh<CR>
nnoremap <leader>n :NvimTreeFindFile<CR>
2021-11-01 00:20:50 +01:00
nnoremap <F11> :Goyo <CR>
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
map <F3> :setlocal spell! spelllang=en_gb<CR>
map <F4> :setlocal spell! spelllang=pl<CR>
2022-09-13 08:33:24 +02:00
" Human Errors
:command! W w
:command! Q q
:command! Wq wq
""""""""""""""""""""""""""""""""
" Custom functions
""""""""""""""""""""""""""""""""
lua <<EOF
function go_org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
end
EOF
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" Files
""""""""""""""""""""""""""""""""
2022-01-02 01:36:59 +01:00
" Bash
2022-08-25 08:54:44 +02:00
if executable('shfmt')
let &l:formatprg='shfmt -i ' . &l:shiftwidth . ' -ln posix -sr -ci -s'
endif
let g:shfmt_extra_args = '-i 4 -ci -sr -s'
let g:shfmt_fmt_on_save = 1
2022-09-03 23:25:37 +02:00
let g:shfmt_opt="-ci"
2022-01-02 01:36:59 +01:00
" Python
autocmd BufRead,BufNewFile *.py set textwidth=0
autocmd BufRead,BufNewFile *.py set fo-=t
2021-11-14 01:04:03 +01:00
" Newsboat
autocmd BufRead,BufNewFile urls set textwidth=0
2021-11-01 00:20:50 +01:00
" Latex
autocmd BufWritePost *.tex silent! execute "!pdflatex --shell-escape -synctex=1 -interaction=nonstopmode % > /dev/null " | redraw!
autocmd BufWritePost *.tex silent! execute "!latexmk -pdf -silent % > /dev/null" | redraw!
2022-01-31 20:40:27 +01:00
autocmd BufWritePost *.tex silent! execute "!rm -rf *.fls *.ilg *.nav *.snm *.toc *.idx *.lof *.lot *.synctex.gz *.aux *.fdb_latexmk *.fls *.log *.out > /dev/null" | redraw!
autocmd BufWritePost *.tex silent! execute "!pkill -HUP mupdf > /dev/null" | redraw!
2021-11-01 00:20:50 +01:00
" Mutt
autocmd BufRead,BufNewFile /tmp/neomutt* let g:goyo_width=80
autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo
autocmd BufRead,BufNewFile /tmp/neomutt* map ZZ :Goyo\|x!<CR>
autocmd BufRead,BufNewFile /tmp/neomutt* map ZQ :Goyo\|q!<CR>
2021-11-01 00:20:50 +01:00
" Yaml
autocmd BufRead,BufNewFile *.yaml let g:indentLine_enabled = 1
autocmd BufRead,BufNewFile *.yaml let g:indentLine_char = '⦙'
au BufRead,BufNewFile *.yaml,*.yml if search('hosts:\|tasks:', 'nw') | set ft=yaml.ansible | endif
autocmd BufWritePre * silent! undojoin | Neoformat prettier
2021-11-01 00:20:50 +01:00
2023-01-31 22:36:26 +01:00
" GoLang
2022-01-02 01:37:16 +01:00
autocmd BufRead *.go set noexpandtab
autocmd BufWritePre *.go lua go_org_imports()
let g:go_def_mapping_enabled = 0
2023-01-31 22:36:26 +01:00
let g:go#fmt#autosave = v:true
2022-01-02 01:27:34 +01:00
2021-11-01 00:20:50 +01:00
" Conf
au BufNewFile,BufRead *.conf setfiletype conf
2022-10-15 14:54:38 +02:00
" Mikrotik
au BufNewFile,BufRead *.mikrotik setfiletype routeros
" Ebuild
au BufNewFile,BufRead,BufWritePre *.ebuild let g:shfmt_extra_args = '-ci -sr -s'
" Terrafrom
autocmd BufWritePre *.tf lua vim.lsp.buf.format()
autocmd BufWritePre *.tfvars lua vim.lsp.buf.format()
" Automatically deletes all trailing whitespace and newlines at end of file on save.
autocmd BufWritePre * %s/\s\+$//e
autocmd BufWritepre * %s/\n\+\%$//e
2021-11-01 00:20:50 +01:00
" Source: https://vi.stackexchange.com/questions/20077/automatically-highlight-all-occurrences-of-the-selected-text-in-visual-mode
" highlight the visual selection after pressing enter.
xnoremap <silent> <cr> "*y:silent! let searchTerm = '\V'.substitute(escape(@*, '\/'), "\n", '\\n', "g") <bar> let @/ = searchTerm <bar> echo '/'.@/ <bar> call histadd("search", searchTerm) <bar> set hls<cr>
2021-11-01 00:20:50 +01:00
""""""""""""""""""""""""""""""""
" FZF
""""""""""""""""""""""""""""""""
let $FZF_DEFAULT_COMMAND = 'find . -type f -not -path "*/\.git/*" -not -path "*/\.local/share/nvim/*" -not -path "./Library/*" '
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --color "always" '.shellescape(<q-args>), 1, <bang>0)
command! -bang -nargs=* FindCurrentWord call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --color "always" '.shellescape(expand('<cword>')), 1, <bang>0)
set grepprg=rg\ --vimgrep
2023-06-26 22:06:05 +02:00
" Custom functions "
function! RemoveForti()
:%g/set uuid .*/d
:%g/set comments .*/d
:%s/edit .*/edit 0/g
:%s/ \+//g
:g/^$/d
2023-06-26 22:06:05 +02:00
endfunction