From 21046a455463e6a2bf58ce7a4e9d958729bf2479 Mon Sep 17 00:00:00 2001 From: Jidbo Date: Sun, 23 Jan 2022 23:24:50 +0100 Subject: [PATCH] switch to lua based nvim config --- nvim/functions.vim | 77 ----------------------------- nvim/init.lua | 14 ++++++ nvim/init.vim | 12 ----- nvim/lua/autocompletion.lua | 2 +- nvim/lua/mappings.lua | 64 ++++++++++++++++++++++++ nvim/lua/options.lua | 59 +++++++++++++++++++++++ nvim/lua/plugins.lua | 91 +++++++++++++++++++++++++++++++++++ nvim/lua/telescopeconfig.lua | 21 ++++++++ nvim/lua/treesitterconfig.lua | 8 +++ nvim/mappings.vim | 53 -------------------- nvim/options.vim | 59 ----------------------- nvim/pluginoptions.vim | 19 -------- nvim/plugins.vim | 85 -------------------------------- 13 files changed, 258 insertions(+), 306 deletions(-) delete mode 100644 nvim/functions.vim create mode 100644 nvim/init.lua delete mode 100644 nvim/init.vim create mode 100644 nvim/lua/mappings.lua create mode 100644 nvim/lua/options.lua create mode 100644 nvim/lua/plugins.lua create mode 100644 nvim/lua/telescopeconfig.lua create mode 100644 nvim/lua/treesitterconfig.lua delete mode 100644 nvim/mappings.vim delete mode 100644 nvim/options.vim delete mode 100644 nvim/plugins.vim diff --git a/nvim/functions.vim b/nvim/functions.vim deleted file mode 100644 index ae5b381..0000000 --- a/nvim/functions.vim +++ /dev/null @@ -1,77 +0,0 @@ -" FUNCTIONS - -" auto reload .vimrc on write -autocmd BufWritePost init.vim source % - -" Delete buffer while keeping window layout (don't close buffer's windows). -" Version 2008-11-18 from http://vim.wikia.com/wiki/VimTip165 -if v:version < 700 || exists('loaded_bclose') || &cp - finish -endif -let loaded_bclose = 1 -if !exists('bclose_multiple') - let bclose_multiple = 1 -endif - -" Display an error message. -function! s:Warn(msg) - echohl ErrorMsg - echomsg a:msg - echohl NONE -endfunction - -" Command ':Bclose' executes ':bd' to delete buffer in current window. -" The window will show the alternate buffer (Ctrl-^) if it exists, -" or the previous buffer (:bp), or a blank buffer if no previous. -" Command ':Bclose!' is the same, but executes ':bd!' (discard changes). -" An optional argument can specify which buffer to close (name or number). -function! s:Bclose(bang, buffer) - if empty(a:buffer) - let btarget = bufnr('%') - elseif a:buffer =~ '^\d\+$' - let btarget = bufnr(str2nr(a:buffer)) - else - let btarget = bufnr(a:buffer) - endif - if btarget < 0 - call s:Warn('No matching buffer for '.a:buffer) - return - endif - if empty(a:bang) && getbufvar(btarget, '&modified') - call s:Warn('No write since last change for buffer '.btarget.' (use :Bclose!)') - return - endif - " Numbers of windows that view target buffer which we will delete. - let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == btarget') - if !g:bclose_multiple && len(wnums) > 1 - call s:Warn('Buffer is in multiple windows (use ":let bclose_multiple=1")') - return - endif - let wcurrent = winnr() - for w in wnums - execute w.'wincmd w' - let prevbuf = bufnr('#') - if prevbuf > 0 && buflisted(prevbuf) && prevbuf != btarget - buffer # - else - bprevious - endif - if btarget == bufnr('%') - " Numbers of listed buffers which are not the target to be deleted. - let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != btarget') - " Listed, not target, and not displayed. - let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0') - " Take the first buffer, if any (could be more intelligent). - let bjump = (bhidden + blisted + [-1])[0] - if bjump > 0 - execute 'buffer '.bjump - else - execute 'enew'.a:bang - endif - endif - endfor - execute 'bdelete'.a:bang.' '.btarget - execute wcurrent.'wincmd w' -endfunction -command! -bang -complete=buffer -nargs=? Bclose call Bclose(, ) -nnoremap bd :Bclose diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..198fafa --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,14 @@ +local nvim_config_root = "~/.config/nvim" + +-- BASIC OPTIONS +require('plugins') +require('options') +require('mappings') + +-- VIM PLUGIN OPTIONS +vim.cmd("source " .. nvim_config_root .. "/pluginoptions.vim") + +-- LUA PLUGIN OPTIONS +require('telescopeconfig') +require('autocompletion') +require('treesitterconfig') diff --git a/nvim/init.vim b/nvim/init.vim deleted file mode 100644 index ca0db41..0000000 --- a/nvim/init.vim +++ /dev/null @@ -1,12 +0,0 @@ -let g:nvim_config_root = stdpath('config') -let g:config_file_list = [ -\ 'plugins.vim', -\ 'options.vim', -\ 'mappings.vim', -\ 'functions.vim', -\ 'pluginoptions.vim', -\ ] - -for f in g:config_file_list - execute 'source ' . g:nvim_config_root . '/' . f -endfor diff --git a/nvim/lua/autocompletion.lua b/nvim/lua/autocompletion.lua index 35c1da1..d270caa 100644 --- a/nvim/lua/autocompletion.lua +++ b/nvim/lua/autocompletion.lua @@ -10,7 +10,7 @@ cmp.setup({ mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua new file mode 100644 index 0000000..1436408 --- /dev/null +++ b/nvim/lua/mappings.lua @@ -0,0 +1,64 @@ +local map = function(key) + -- get the extra options + local opts = {noremap = true} + for i, v in pairs(key) do + if type(i) == 'string' then opts[i] = v end + end + + -- basic support for buffer-scoped keybindings + local buffer = opts.buffer + opts.buffer = nil + + if buffer then + vim.api.nvim_buf_set_keymap(0, key[1], key[2], key[3], opts) + else + vim.api.nvim_set_keymap(key[1], key[2], key[3], opts) + end +end + +-- search for visual selection +map {'v', '//', 'y/"'} +map {'n', 'H', '^'} + +-- ex command +map {'c', '', ''} +map {'c', '', ''} + +-- auto expand brackets +map {'i', '(;', '()O'} +map {'i', '(,', '(),O'} +map {'i', '{;', '{}O'} +map {'i', '{,', '{},O'} +map {'i', '[;', '[]O'} +map {'i', '[,', '[],O'} + +-- toggle hybrid mode +map {'n', 'h', ':set rnu!'} + +-- nerdtree +map {'n', 'e', ':NERDTreeToggle'} + +-- Telescope +map {'n', '', 'Telescope buffers'} +map {'n', 'f', 'Telescope find_files'} +map {'n', 'l', 'Telescope live_grep'} +map {'n', ' gD', 'Telescope lsp_implementations'} +map {'n', ' gH', 'Telescope lsp_code_actions'} +map {'n', ' gd', 'Telescope lsp_definitions'} +map {'n', ' gr', 'Telescope lsp_references'} +map {'n', ' gy', 'Telescope treesitter'} + +-- neo formatter +map {'n', 'p', ':Neoformat'} + +-- goyo mapping +map {'n', ' w', ':Goyo'} + +-- spelling +map {'n', ' se', ':set spell spelllang=en'} +map {'n', ' sd', ':set spell spelllang=de'} + +map {'n', ' gh', 'lua vim.lsp.buf.hover()'} +map {'n', ' gs', 'lua vim.lsp.buf.signature_help()'} +map {'n', ' gR', 'lua vim.lsp.buf.rename()'} +map {'n', ' ge', 'lua vim.diagnostic.open_float()'} diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua new file mode 100644 index 0000000..66b5611 --- /dev/null +++ b/nvim/lua/options.lua @@ -0,0 +1,59 @@ +-- OPTIONS + +-- syntax +vim.cmd [[ + syntax on + let mapleader=" " + colorscheme kuroi + hi MatchParen guibg=NONE guifg=red gui=bold + set shortmess+=c +]] + +-- color settings +vim.opt.termguicolors=true +vim.opt.background='dark' + +-- random settings +vim.opt.number=true +vim.opt.rnu=true +vim.opt.clipboard='unnamed' +vim.opt.mouse='nvi' + +vim.opt.visualbell=true +vim.opt.virtualedit='block' +vim.opt.scrolloff=1 +vim.opt.wildmenu=true +vim.opt.autoread=true +vim.opt.lazyredraw=true +vim.opt.history=250 +vim.opt.showmode=false + +vim.opt.completeopt='menuone,noinsert,noselect' + +-- tabs and line wrap +vim.opt.expandtab=true +vim.opt.tabstop=2 +vim.opt.wrapmargin=8 +vim.opt.softtabstop=0 +vim.opt.shiftwidth=2 +vim.opt.backspace='indent,eol,start' +vim.opt.encoding='utf-8' +vim.opt.autoindent=true + +-- search +vim.opt.incsearch=true +vim.opt.hlsearch=true +vim.opt.smartcase=true + +-- Disable Backup and Swap files +vim.opt.swapfile=false +vim.opt.backup=false +vim.opt.writebackup=false + +-- setup split +vim.opt.splitbelow=true +vim.opt.splitright=true + +-- Enable folding +vim.opt.foldmethod='indent' +vim.opt.foldlevel=99 diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua new file mode 100644 index 0000000..3a21458 --- /dev/null +++ b/nvim/lua/plugins.lua @@ -0,0 +1,91 @@ +local Plug = vim.fn['plug#'] +-- PLUGINS +vim.call('plug#begin', '~/.config/nvim/bundle') +-- USEFUL +-- =================== + +-- Editor config +Plug 'editorconfig/editorconfig-vim' + +-- brackets management +Plug 'tpope/vim-surround' + +-- new text objects +Plug 'wellle/targets.vim' + +-- WINDOW MANAGEMENT +-- =================== + +-- tmux navigator +Plug 'christoomey/vim-tmux-navigator' + +-- winresizer +Plug 'simeji/winresizer' + +-- goyo +Plug 'junegunn/goyo.vim' + +-- FILE MANAGEMENT +-- =================== + +-- nerd-tree +Plug 'preservim/nerdtree' + +-- Icons +Plug 'ryanoasis/vim-devicons' + +-- fzf plugin +Plug 'nvim-lua/plenary.nvim' +Plug 'nvim-telescope/telescope.nvim' + +-- vimwiki +Plug 'vimwiki/vimwiki' + +-- GIT STUFF +-- =================== + +-- git +Plug 'tpope/vim-fugitive' + +-- vim gitgutter +Plug 'airblade/vim-gitgutter' + +-- COLORS +-- =================== + +-- Plastic colorscheme +Plug 'jidbo/kuroi.vim' + +-- Color higlighting +Plug 'norcalli/nvim-colorizer.lua' + +-- powerline +Plug 'vim-airline/vim-airline' + +-- LANGUAGES +-- =================== + +-- nvim completion +Plug 'neovim/nvim-lspconfig' +Plug 'williamboman/nvim-lsp-installer' + +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/cmp-path' +Plug 'hrsh7th/cmp-cmdline' +Plug 'hrsh7th/nvim-cmp' + +Plug 'SirVer/ultisnips' +Plug 'quangnguyen30192/cmp-nvim-ultisnips' + +-- Autoformatter +Plug 'sbdchd/neoformat' + +-- treesitter +Plug('nvim-treesitter/nvim-treesitter', {['do'] = ':TSUpdate'}) + +-- latex +Plug 'lervag/vimtex' + +-- All of your Plugins must be added before the following line +vim.call('plug#end') diff --git a/nvim/lua/telescopeconfig.lua b/nvim/lua/telescopeconfig.lua new file mode 100644 index 0000000..9f34cf8 --- /dev/null +++ b/nvim/lua/telescopeconfig.lua @@ -0,0 +1,21 @@ +-- load telescope + +-- require("telescope").setup { +-- extensions = { +-- file_browser = { +-- -- theme = "ivy", +-- -- initial_mode = "normal", +-- mappings = { +-- ["i"] = { +-- [""] = fb_actions.goto_parent_dir, +-- }, +-- ["n"] = { +-- ["b"] = fb_actions.goto_parent_dir, +-- }, +-- }, +-- }, +-- }, +-- } +-- +-- -- plugins +-- require("telescope").load_extension "file_browser" diff --git a/nvim/lua/treesitterconfig.lua b/nvim/lua/treesitterconfig.lua new file mode 100644 index 0000000..e5447c7 --- /dev/null +++ b/nvim/lua/treesitterconfig.lua @@ -0,0 +1,8 @@ +require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + }, + indent = { + enable = true + }, +} diff --git a/nvim/mappings.vim b/nvim/mappings.vim deleted file mode 100644 index 0bebdf7..0000000 --- a/nvim/mappings.vim +++ /dev/null @@ -1,53 +0,0 @@ -" REMAPS -" search for visual selection -vnoremap // y/" -nnoremap H ^ - -" ex command -cnoremap -cnoremap - -" auto expand brackets -inoremap (; ()O -inoremap (, (),O -inoremap {; {}O -inoremap {, {},O -inoremap [; []O -inoremap [, [],O - -" toggle hybrid mode -nnoremap h :set rnu! - -" nerdtree -map e :NERDTreeToggle - -" Telescope -nnoremap Telescope buffers -nnoremap f Telescope find_files -nnoremap l Telescope live_grep -nnoremap gD Telescope lsp_implementations -nnoremap gH Telescope lsp_code_actions -nnoremap gd Telescope lsp_definitions -nnoremap gr Telescope lsp_references -nnoremap gy Telescope treesitter - -" vim fugitive -nnoremap gg :G - -" neo formatter -nnoremap p :Neoformat - -" goyo mapping -nnoremap w :Goyo - -" spelling -nnoremap se :set spell spelllang=en -nnoremap sd :set spell spelllang=de - -" nnoremap gd lua vim.lsp.buf.definition() -nnoremap gh lua vim.lsp.buf.hover() -" nnoremap gH lua vim.lsp.buf.code_action() -" nnoremap gD lua vim.lsp.buf.implementation() -nnoremap gs lua vim.lsp.buf.signature_help() -" nnoremap gr lua vim.lsp.buf.references() -nnoremap gR lua vim.lsp.buf.rename() diff --git a/nvim/options.vim b/nvim/options.vim deleted file mode 100644 index 90642b5..0000000 --- a/nvim/options.vim +++ /dev/null @@ -1,59 +0,0 @@ -" OPTIONS - -" syntax -syntax on -let mapleader=" " - -" color settings -set termguicolors -colorscheme kuroi -set background=dark -hi MatchParen guibg=NONE guifg=red gui=bold - -" random settings -set number -set rnu -set clipboard=unnamed -set mouse=nvi - -" set smarttab -set expandtab -set tabstop=4 -set visualbell -set virtualedit=block -set scrolloff=1 -set wildmenu -set autoread -set lazyredraw -set history=250 -set noshowmode - -" tabs and line wrap -set wrapmargin=8 -set softtabstop=0 noexpandtab -set shiftwidth=4 -set backspace=2 -set backspace=indent,eol,start -set encoding=utf-8 -set autoindent - -" search -set incsearch -set hlsearch -set smartcase - -" Disable Backup and Swap files -set noswapfile -set nobackup -set nowritebackup - -" setup split -set splitbelow -set splitright - -" Enable folding -set foldmethod=indent -set foldlevel=99 - -" highlight yanked -au TextYankPost * silent! lua vim.highlight.on_yank() diff --git a/nvim/pluginoptions.vim b/nvim/pluginoptions.vim index 13c8197..535e323 100644 --- a/nvim/pluginoptions.vim +++ b/nvim/pluginoptions.vim @@ -100,22 +100,3 @@ autocmd! User GoyoEnter nested call goyo_enter() autocmd! User GoyoLeave nested call goyo_leave() let g:goyo_width = 120 - -" AUTOCOMPLETION -" ========================= -set completeopt=menuone,noinsert,noselect -set shortmess+=c - -lua require('autocompletion') - -" TREESITTER -lua <