From b3ed5649513b97aeac5835bcd758433343c88c96 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Thu, 28 Dec 2023 16:08:38 +0100 Subject: nvim: Move to lua --- nvim/nvim/init.lua | 146 +++++++++++++++++++++++++ nvim/nvim/init.vim | 267 --------------------------------------------- nvim/nvim/init.vim.old | 267 +++++++++++++++++++++++++++++++++++++++++++++ nvim/nvim/lua/mappings.lua | 17 +++ 4 files changed, 430 insertions(+), 267 deletions(-) create mode 100644 nvim/nvim/init.lua delete mode 100644 nvim/nvim/init.vim create mode 100644 nvim/nvim/init.vim.old create mode 100644 nvim/nvim/lua/mappings.lua (limited to 'nvim') diff --git a/nvim/nvim/init.lua b/nvim/nvim/init.lua new file mode 100644 index 0000000..4632a11 --- /dev/null +++ b/nvim/nvim/init.lua @@ -0,0 +1,146 @@ +vim.opt.compatible = false +vim.cmd.filetype("off") + +-- Plugins +local Plug = vim.fn['plug#'] +vim.fn["plug#begin"]() + Plug("nvim-treesitter/nvim-treesitter") + Plug("kovisoft/paredit") + Plug("sgur/vim-editorconfig") + Plug("dracula/vim") + Plug("othree/html5.vim") + Plug("zaid/vim-rec") + Plug("https://gitlab.com/Efraim/guix.vim") + Plug("Olical/conjure") + vim.g["conjure#client_on_load"] = false + vim.g["conjure#filetype#scheme"] = "conjure.client.guile.socket" + vim.g["conjure#debug"] = true + vim.g.maplocalleader = "," + -- Zig is installed in nvim + vim.g.zig_fmt_autosave = 0 +vim.fn["plug#end"]() + +vim.cmd.filetype("plugin", "on") + +-- Syntax +vim.cmd.syntax("on") +vim.cmd.syntax("sync", "fromstart") +vim.opt.redrawtime = 10000 + +-- Colors +vim.opt.termguicolors = true +vim.opt.background = "dark" +vim.env.NVIM_TUI_ENABLE_TRUE_COLOR = 1 +vim.env.NVIM_TUI_ENABLE_CURSOR_SHAPE = 1 +vim.cmd.colorscheme("dracula") +vim.opt.cursorline = true +vim.cmd.highlight("CursorColumn", "ctermbg=DarkGrey", "guibg=#262626") +vim.cmd.highlight("CursorLine", "ctermbg=DarkGrey", "guibg=#262626") + +vim.opt.colorcolumn = "80" +vim.cmd.highlight("ColorColumn", "ctermbg=DarkGrey", "guibg=#262626") + +vim.cmd.highlight("ExtraWhitespace", "ctermbg=red", "guibg=red") + +-- HighLight search +vim.opt.hlsearch = true + +-- Whitespace +local extraWhitespace = vim.api.nvim_create_augroup('whitespace', { clear = false }) +vim.api.nvim_create_autocmd({"WinNew", "TabNew", "BufEnter", "InsertLeave"}, { + group = extraWhitespace, + pattern = {"*"}, + command = "match ExtraWhitespace /\\s\\+$/", +}) +vim.api.nvim_create_autocmd({"InsertEnter"}, { + group = extraWhitespace, + pattern = {"*"}, + command = "call clearmatches()", +}) + +vim.opt.list = true +vim.opt.listchars = {trail="·", tab="»·"} + +-- UI +vim.opt.showtabline = 1 +vim.opt.wildmenu = true +vim.opt.mouse = "a" +vim.opt.showmatch = true +vim.opt.modeline = true +vim.opt.path = {"**"} + +-- Ignore Case in search +vim.opt.ignorecase = true +vim.opt.smartcase = true + + +-- New splits +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- Netrw +vim.g.netrw_liststyle = 1 +vim.g.netrw_banner = 1 +vim.g.netrw_winsize = 75 + +-- Folds +vim.opt.foldmethod = "expr" +vim.opt.foldexpr = "nvim_treesitter#foldexpr()" +vim.opt.foldlevelstart = 99 + +-- Autocomplete +vim.opt.complete = {".", "w", "b", "u", "t", "i"} + +-- Edition +vim.opt.hidden = true +vim.opt.undofile = true + +-- Tabs +vim.opt.tabstop=4 +vim.opt.softtabstop=0 +vim.opt.expandtab = true +vim.opt.shiftwidth=4 + +-- Formatting +vim.opt.textwidth=79 +vim.opt.formatoptions="jcroql" + +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" + ensure_installed = { "c", "cpp", "lua", "python", "scheme", "javascript", + "fennel", "zig" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + -- Automatically install missing parsers when entering buffer + auto_install = false, + + -- List of parsers to ignore installing (for "all") + ignore_install = {}, + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + disable = {}, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} + + +if vim.fn.executable("rg") then + vim.opt.grepprg="rg --vimgrep --no-heading" + vim.opt.grepformat="%f:%l:%c:%m,%f:%l:%m" +end + +-- Mappings +require("mappings") diff --git a/nvim/nvim/init.vim b/nvim/nvim/init.vim deleted file mode 100644 index f7a8f5d..0000000 --- a/nvim/nvim/init.vim +++ /dev/null @@ -1,267 +0,0 @@ -" Vim Plug: -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -set nocompatible -filetype off - -call plug#begin() - -" Better syntax highlighting with treesitter -Plug 'nvim-treesitter/nvim-treesitter' ", {'do': ':TSUpdate'} - -" Post to Wordpress using MarkDown -" Plug 'ekaitz-zarraga/droWMark' - -" CoffeeScript stuff -" Plug 'kchmck/vim-coffee-script' - -" Paredit for Clojure and Lisp -" Plug 'vim-scripts/paredit.vim' -Plug 'kovisoft/paredit' - -" Clojure REPL integration ---> Conjure does this and more -" Plug 'tpope/vim-fireplace' - -" Write with no distractions -Plug 'junegunn/goyo.vim' - -" .editorconfig file support -Plug 'sgur/vim-editorconfig' - -" Dracula colorscheme -Plug 'dracula/vim' - -" HTML5 -Plug 'othree/html5.vim' - -" Recutils support -Plug 'zaid/vim-rec' - -" Guix -Plug 'https://gitlab.com/Efraim/guix.vim' - -" Conjure: lispy things! this is what I wanted to do with combustion! -Plug 'Olical/conjure' -let g:conjure#client_on_load = v:false -let g:conjure#filetype#scheme = "conjure.client.guile.socket" -let g:conjure#debug = v:true -let g:maplocalleader = "," - - -" Repl -" Plug 'https://gitlab.com/HiPhish/repl.nvim.git' - -" Combustion-testing -" Plug 'git@gitlab.com:ElenQ/combustion.git' - -" Add plugins here - -call plug#end() " required -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - - -" GUI: -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Activate syntax highlighting by default and make it almost work properly -syntax on -syntax sync fromstart -set redrawtime=10000 -" Maybe with tree-sitter we don't need this anymore -nnoremap :syntax sync fromstart - -" Keep 10 lines of space from the cursor to the window corners -" I don't like this, prefer to use zz -" set scrolloff=10 - -" Show completion in a menu -set wildmenu - -" Enable TRUE COLORS -let $NVIM_TUI_ENABLE_TRUE_COLOR=1 -let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 -set termguicolors -set background=dark - -" Set default colorscheme -" colorscheme desert -colorscheme dracula - -" Highligh column and line -" set cursorcolumn -set cursorline -highlight CursorColumn ctermbg=DarkGrey guibg=#262626 -highlight CursorLine ctermbg=DarkGrey guibg=#262626 -highlight! link CursorColumn CursorLine - -" Show trailing spaces -set list lcs=trail:·,tab:»· - -" Always show tabline (0=never, 1=when there are at least 2 tabs, 2=always) -set showtabline=1 - -" Split on the right in vertical and below in horizontal -set splitbelow -set splitright - -" Explore configured to show tree -" Use a banner -" always open files in previous window -let g:netrw_liststyle = 1 -let g:netrw_banner = 1 -let g:netrw_winsize = 75 " % of window by v or o operation - -" Mouse support -set mouse=a - -" Fold -" set foldmethod=indent -set foldmethod=expr -set foldexpr=nvim_treesitter#foldexpr() -set foldlevelstart=99 -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" EDITION: -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Completion -set complete=.,w,b,u,t,i - -" Allow backspace always -set backspace=indent,eol,start - -" Change buffers without needing to save -set hidden - -" Maintain undo history between sessions -set undofile - -" Clear trailing spaces on -function TrimWhiteSpace() - %s/\s*$// - '' -:endfunction -function TrimWhiteSpaceVisual() - '<,'>s/\s*$// - '' -:endfunction -" Whitexpace trimmer available in normal and edit mode -nnoremap :call TrimWhiteSpace() -inoremap :call TrimWhiteSpace() -vnoremap :call TrimWhiteSpaceVisual() - -" Scissors -" TODO: improve this -function AddScissors() - execute "normal i--8<---------------cut here---------------start------------->8---\n" - execute "normal i--8<---------------cut here---------------end--------------->8---\n" -:endfunction -command! Scissors execute 'call AddScissors()' - -" Default tabs -set tabstop=4 softtabstop=0 expandtab shiftwidth=4 -set autoindent - -" Show matching parenthesis and brackets on close -set showmatch - -" Enable modelines (they have vulnerabilities, but it should be fine LOL) -set modeline - -" Allow saving of files as sudo -" TODO LOOK FOR A BETTER WAY TO DO THIS -" cmap w!! w !sudo tee > /dev/null % - -" SEARCH - -" Search through files in the current tree (like :find) -set path+=** - -" Ignore .go files (guile object) -set wildignore+=*.go - -" Make ctags so we can search with ^] and g^] and ^t -command! MakeTags !ctags -R . - -" Use ripgrep as search tool -if executable("rg") - set grepprg=rg\ --vimgrep\ --no-heading - set grepformat=%f:%l:%c:%m,%f:%l:%m -endif - -command! -nargs=+ Sgrep execute 'silent grep! ' | copen 10 - -" HighLight search -set hlsearch - -" Ignore Case in search -set ignorecase -set smartcase - - -" TEXT WIDTH - -" Textwidth for automatic wrap, `gq` is formatting operation -set textwidth=79 -set formatoptions=jcroql - -" Highlight where the lines are more than 80 characters wide -set colorcolumn=80 -highlight ColorColumn ctermbg=DarkGrey guibg=#262626 - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" TERMINAL: -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Make terminal remap to go out of insert mode -:tnoremap -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" Different config for each filetype -filetype plugin on - - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Whitespace: highlight -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red -highlight ExtraWhitespace ctermbg=red guibg=red -autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ -autocmd InsertLeave * match ExtraWhitespace /\s\+$/ -autocmd InsertEnter * call clearmatches() -autocmd BufWinLeave * call clearmatches() - - -" Configure Treesitter -lua << ENDMARK -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" - ensure_installed = { "c", "cpp", "lua", "python", "scheme", "javascript", - "fennel", "zig" }, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - -- Automatically install missing parsers when entering buffer - auto_install = false, - - -- List of parsers to ignore installing (for "all") - ignore_install = {}, - - highlight = { - -- `false` will disable the whole extension - enable = true, - - -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to - -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is - -- the name of the parser) - -- list of language that will be disabled - disable = {}, - - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, -} -ENDMARK -" Redraw the syntax if the tree and the file went out of sync -" nnoremap :write | edit | TSBufEnable highlight -au FileType fennel call PareditInitBuffer() diff --git a/nvim/nvim/init.vim.old b/nvim/nvim/init.vim.old new file mode 100644 index 0000000..f7a8f5d --- /dev/null +++ b/nvim/nvim/init.vim.old @@ -0,0 +1,267 @@ +" Vim Plug: +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +set nocompatible +filetype off + +call plug#begin() + +" Better syntax highlighting with treesitter +Plug 'nvim-treesitter/nvim-treesitter' ", {'do': ':TSUpdate'} + +" Post to Wordpress using MarkDown +" Plug 'ekaitz-zarraga/droWMark' + +" CoffeeScript stuff +" Plug 'kchmck/vim-coffee-script' + +" Paredit for Clojure and Lisp +" Plug 'vim-scripts/paredit.vim' +Plug 'kovisoft/paredit' + +" Clojure REPL integration ---> Conjure does this and more +" Plug 'tpope/vim-fireplace' + +" Write with no distractions +Plug 'junegunn/goyo.vim' + +" .editorconfig file support +Plug 'sgur/vim-editorconfig' + +" Dracula colorscheme +Plug 'dracula/vim' + +" HTML5 +Plug 'othree/html5.vim' + +" Recutils support +Plug 'zaid/vim-rec' + +" Guix +Plug 'https://gitlab.com/Efraim/guix.vim' + +" Conjure: lispy things! this is what I wanted to do with combustion! +Plug 'Olical/conjure' +let g:conjure#client_on_load = v:false +let g:conjure#filetype#scheme = "conjure.client.guile.socket" +let g:conjure#debug = v:true +let g:maplocalleader = "," + + +" Repl +" Plug 'https://gitlab.com/HiPhish/repl.nvim.git' + +" Combustion-testing +" Plug 'git@gitlab.com:ElenQ/combustion.git' + +" Add plugins here + +call plug#end() " required +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + + +" GUI: +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Activate syntax highlighting by default and make it almost work properly +syntax on +syntax sync fromstart +set redrawtime=10000 +" Maybe with tree-sitter we don't need this anymore +nnoremap :syntax sync fromstart + +" Keep 10 lines of space from the cursor to the window corners +" I don't like this, prefer to use zz +" set scrolloff=10 + +" Show completion in a menu +set wildmenu + +" Enable TRUE COLORS +let $NVIM_TUI_ENABLE_TRUE_COLOR=1 +let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 +set termguicolors +set background=dark + +" Set default colorscheme +" colorscheme desert +colorscheme dracula + +" Highligh column and line +" set cursorcolumn +set cursorline +highlight CursorColumn ctermbg=DarkGrey guibg=#262626 +highlight CursorLine ctermbg=DarkGrey guibg=#262626 +highlight! link CursorColumn CursorLine + +" Show trailing spaces +set list lcs=trail:·,tab:»· + +" Always show tabline (0=never, 1=when there are at least 2 tabs, 2=always) +set showtabline=1 + +" Split on the right in vertical and below in horizontal +set splitbelow +set splitright + +" Explore configured to show tree +" Use a banner +" always open files in previous window +let g:netrw_liststyle = 1 +let g:netrw_banner = 1 +let g:netrw_winsize = 75 " % of window by v or o operation + +" Mouse support +set mouse=a + +" Fold +" set foldmethod=indent +set foldmethod=expr +set foldexpr=nvim_treesitter#foldexpr() +set foldlevelstart=99 +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" EDITION: +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Completion +set complete=.,w,b,u,t,i + +" Allow backspace always +set backspace=indent,eol,start + +" Change buffers without needing to save +set hidden + +" Maintain undo history between sessions +set undofile + +" Clear trailing spaces on +function TrimWhiteSpace() + %s/\s*$// + '' +:endfunction +function TrimWhiteSpaceVisual() + '<,'>s/\s*$// + '' +:endfunction +" Whitexpace trimmer available in normal and edit mode +nnoremap :call TrimWhiteSpace() +inoremap :call TrimWhiteSpace() +vnoremap :call TrimWhiteSpaceVisual() + +" Scissors +" TODO: improve this +function AddScissors() + execute "normal i--8<---------------cut here---------------start------------->8---\n" + execute "normal i--8<---------------cut here---------------end--------------->8---\n" +:endfunction +command! Scissors execute 'call AddScissors()' + +" Default tabs +set tabstop=4 softtabstop=0 expandtab shiftwidth=4 +set autoindent + +" Show matching parenthesis and brackets on close +set showmatch + +" Enable modelines (they have vulnerabilities, but it should be fine LOL) +set modeline + +" Allow saving of files as sudo +" TODO LOOK FOR A BETTER WAY TO DO THIS +" cmap w!! w !sudo tee > /dev/null % + +" SEARCH + +" Search through files in the current tree (like :find) +set path+=** + +" Ignore .go files (guile object) +set wildignore+=*.go + +" Make ctags so we can search with ^] and g^] and ^t +command! MakeTags !ctags -R . + +" Use ripgrep as search tool +if executable("rg") + set grepprg=rg\ --vimgrep\ --no-heading + set grepformat=%f:%l:%c:%m,%f:%l:%m +endif + +command! -nargs=+ Sgrep execute 'silent grep! ' | copen 10 + +" HighLight search +set hlsearch + +" Ignore Case in search +set ignorecase +set smartcase + + +" TEXT WIDTH + +" Textwidth for automatic wrap, `gq` is formatting operation +set textwidth=79 +set formatoptions=jcroql + +" Highlight where the lines are more than 80 characters wide +set colorcolumn=80 +highlight ColorColumn ctermbg=DarkGrey guibg=#262626 + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" TERMINAL: +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Make terminal remap to go out of insert mode +:tnoremap +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" Different config for each filetype +filetype plugin on + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Whitespace: highlight +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red +highlight ExtraWhitespace ctermbg=red guibg=red +autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ +autocmd InsertLeave * match ExtraWhitespace /\s\+$/ +autocmd InsertEnter * call clearmatches() +autocmd BufWinLeave * call clearmatches() + + +" Configure Treesitter +lua << ENDMARK +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" + ensure_installed = { "c", "cpp", "lua", "python", "scheme", "javascript", + "fennel", "zig" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + -- Automatically install missing parsers when entering buffer + auto_install = false, + + -- List of parsers to ignore installing (for "all") + ignore_install = {}, + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + disable = {}, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} +ENDMARK +" Redraw the syntax if the tree and the file went out of sync +" nnoremap :write | edit | TSBufEnable highlight +au FileType fennel call PareditInitBuffer() diff --git a/nvim/nvim/lua/mappings.lua b/nvim/nvim/lua/mappings.lua new file mode 100644 index 0000000..02e42f3 --- /dev/null +++ b/nvim/nvim/lua/mappings.lua @@ -0,0 +1,17 @@ +-- These functions are shit at the moment: they screw up the search list +function trimWhiteSpace() + vim.cmd("%s/\\s\\+$//") +end +function trimWhiteSpaceVisual() + vim.cmd("'<,'>s/\\s\\+$//") +end +vim.keymap.set('n', '', trimWhiteSpace) +vim.keymap.set('v', '', trimWhiteSpaceVisual) + +-- more natural movement with wrap on +vim.keymap.set('n', 'j', 'gj') +vim.keymap.set('n', 'k', 'gk') +vim.keymap.set('n', 'j', 'gj') +vim.keymap.set('n', 'k', 'gk') + +vim.api.nvim_create_user_command('MakeTags', '!ctags -R .', {}) -- cgit v1.2.3