From 29e053af75436c66496f12265fc609291b6132b9 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Thu, 6 Aug 2026 23:56:13 +0200 Subject: [PATCH] Add Neovim config --- .config/bashrc.d/10_common.sh | 5 + .config/nvim/init.lua | 128 +++++++++++++++++++++++++ .config/nvim/lua/init/plugins.lua | 103 +++++++++++++++++++++ .config/nvim/lua/init/theme.lua | 36 ++++++++ .config/nvim/nvim-pack-lock.json | 34 +++++++ .vimrc | 149 +++++++++--------------------- 6 files changed, 352 insertions(+), 103 deletions(-) create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/init/plugins.lua create mode 100644 .config/nvim/lua/init/theme.lua create mode 100644 .config/nvim/nvim-pack-lock.json diff --git a/.config/bashrc.d/10_common.sh b/.config/bashrc.d/10_common.sh index 6bf0b0d..a7cf2dc 100644 --- a/.config/bashrc.d/10_common.sh +++ b/.config/bashrc.d/10_common.sh @@ -30,6 +30,11 @@ vimdiff() { stty "$STTYOPTS" } +# Neovim shortcuts +alias nv='nvim' +alias nvimr='nvim -R' +alias nvim-config='nvim ~/.config/nvim/init.lua' + # yay without parameters does "pacman -Syu" but I don't want it to do this yay() { [[ $# -gt 0 ]] || { echo "error: no operation specified (use -h for help)"; return 1; } diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..9524df8 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,128 @@ +-- Config shortcuts +local o = vim.o +local opt = vim.opt +local keymap = vim.keymap + + +------------------ +-- GENERAL OPTIONS +------------------ + +-- Line numbers +o.number = true +o.relativenumber = true + +-- Highlight the cursor line +o.cursorline = true + +-- Amount of screen lines that should be visible above/below the cursor +o.scrolloff = 8 + +-- Show tabs and trailing spaces +o.list = true + +-- Wrap lines at word boundaries +o.linebreak = true + +-- Case insensitive search (except when explicitly using uppercase letters) +o.ignorecase = true +o.smartcase = true + +-- Indentation settings +o.smartindent = true +o.expandtab = true +o.shiftwidth = 4 +o.softtabstop = -1 + +-- Don't auto-insert comment leader when entering insert mode with o/O +vim.api.nvim_create_autocmd('FileType', { + command = 'set formatoptions-=o', +}) + + +------------- +-- FILE TYPES +------------- + +vim.filetype.add { + extension = { + gitconfig = 'gitconfig', + }, +} + +-- HTML formatting +vim.g.html_indent_autotags = 'html,body' +vim.g.html_indent_inctags = 'p' + + +----------- +-- MAPPINGS +----------- + +-- For keys that are safe to be mapped, see: https://vim.fandom.com/wiki/Unused_keys + +-- Exit insert mode with jk +keymap.set('i', 'jk', '') + +-- Quick exit with Ctrl-q +keymap.set('n', '', ':q') + +-- Quick save all open buffers with Ctrl-s +keymap.set('n', '', ':wall') +keymap.set('i', '', ':wall') + +-- Simple copy and paste to/from system clipboard with Ctrl-c in visual mode +-- and Ctrl-v in insert mode +keymap.set('v', '', '"+y') +keymap.set('i', '', '"+P') + +-- Navigate between windows with Alt and hjkl +keymap.set('n', '', 'h') +keymap.set('n', '', 'j') +keymap.set('n', '', 'k') +keymap.set('n', '', 'l') + +-- Resize windows with Alt and arrow keys +keymap.set('n', '', '2-') +keymap.set('n', '', '2+') +keymap.set('n', '', '4<') +keymap.set('n', '', '4>') + +-- Shortcuts for jumping to start of line (H) or end of line (L) +keymap.set({'n', 'x'}, 'H', '^') +keymap.set({'n', 'x'}, 'L', '$') + +-- Use comma (,) as a "modifier prefix" for alternative functions of regular +-- commands (e.g. yank to system clipboard) or for random shortcuts. +-- TODO: Comma or semicolon or single quote? +keymap.set({'n', 'x'}, ',', '') + +-- Prefix yank/delete/change/paste commands with "," to use system clipboard +keymap.set({'n', 'x'}, ',y', '"+y') +keymap.set({'n', 'x'}, ',Y', '"+y$') +keymap.set({'n', 'x'}, ',d', '"+d') +keymap.set({'n', 'x'}, ',D', '"+D') +keymap.set({'n', 'x'}, ',c', '"+c') +keymap.set({'n', 'x'}, ',C', '"+C') +keymap.set({'n', 'x'}, ',p', '"+p') +keymap.set({'n', 'x'}, ',P', '"+P') + +-- Insert empty line(s) below or above current line without moving the cursor +keymap.set('n', ',o', function() + local line = vim.api.nvim_win_get_cursor(0)[1] + local repeated = vim.fn['repeat']({''}, vim.v.count1) + vim.api.nvim_buf_set_lines(0, line, line, true, repeated) +end) +keymap.set('n', ',O', function() + local line = vim.api.nvim_win_get_cursor(0)[1] - 1 + local repeated = vim.fn['repeat']({''}, vim.v.count1) + vim.api.nvim_buf_set_lines(0, line, line, true, repeated) +end) + + +---------- +-- PLUGINS +---------- + +require('init.theme') +require('init.plugins') diff --git a/.config/nvim/lua/init/plugins.lua b/.config/nvim/lua/init/plugins.lua new file mode 100644 index 0000000..9f95917 --- /dev/null +++ b/.config/nvim/lua/init/plugins.lua @@ -0,0 +1,103 @@ +-- Config shortcuts +local keymap = vim.keymap +local vr = vim.version.range + + +------------------ +-- INSTALL PLUGINS +------------------ + +vim.pack.add { + -- Better code completion + { src = 'https://github.com/saghen/blink.cmp', version = vr '1.*' }, + + -- Better marks + 'https://github.com/chentoast/marks.nvim', + + -- Surround selections with quotes etc. + { src = 'https://github.com/kylechui/nvim-surround', version = vr '4.*' }, + + -- Substitute and exchange operator + 'https://github.com/gbprod/substitute.nvim', + + -- Highlight todo comments + 'https://github.com/folke/todo-comments.nvim', + + -- Highlight colors (hex codes etc.) + 'https://github.com/brenoprata10/nvim-highlight-colors', +} + + +--------------------- +-- INITIALIZE PLUGINS +--------------------- + +-- Better code completion +require('blink.cmp').setup { + keymap = { + preset = 'super-tab', + }, + cmdline = { + keymap = { + preset = 'inherit', + [''] = { + 'show', + 'select_and_accept', + 'fallback', + }, + }, + completion = { + menu = { auto_show = true }, + }, + }, +} + + +-- Better marks +require('marks').setup { + -- Show builtin marks in gutter: last jump position (`), last change (.), + -- last selection in visual mode (). + -- TODO: See which of those are really helpful and remove the others. + builtin_marks = { '`', '.', '<', '>' }, +} + + +-- Surround selections with quotes etc. +require('nvim-surround').setup {} + + +-- Substitute and exchange operator +local substitute = require('substitute') +substitute.setup {} + +-- ... Use "s" key for substitute (by default "s" is equivalent to "cl") +keymap.set('n', 's', substitute.operator) +keymap.set('n', 'ss', substitute.line) +keymap.set('n', 'S', substitute.eol) +keymap.set('x', 's', substitute.visual) + +-- ... Prefix with "," to use system clipboard (remap to use the substitute mappings above) +keymap.set({'n', 'x'}, ',s', '"+s', { remap = true }) +keymap.set({'n', 'x'}, ',S', '"+S', { remap = true }) + + +-- Highlight todo comments +require('todo-comments').setup { + -- Disable gutter icons + signs = false, + + -- Customize highlighting + highlight = { + before = '', + -- By default ("wide"), the surrounding space and colon are highlighted too, + -- which makes the colon invisible + keyword = 'bg', + after = 'fg', + -- Highlight keywords always, not just when followed by a colon (the default) + pattern = '<(KEYWORDS)>', + }, +} + + +-- Highlight colors (hex codes etc.) +require('nvim-highlight-colors').setup {} diff --git a/.config/nvim/lua/init/theme.lua b/.config/nvim/lua/init/theme.lua new file mode 100644 index 0000000..c805b9b --- /dev/null +++ b/.config/nvim/lua/init/theme.lua @@ -0,0 +1,36 @@ +-- Install theme plugins +vim.pack.add { + { src = 'https://github.com/rebelot/kanagawa.nvim', name = 'kanagawa' }, + -- { src = 'https://github.com/rose-pine/neovim', name = 'rose-pine' }, + -- { src = 'https://github.com/nickkadutskyi/jb.nvim', name = 'jetbrains-theme' }, +} + +-- Initialize and customize themes +require('kanagawa').setup { + -- Compile colorscheme for fast startup times. + -- Note: When changing the theme, make sure to run `:KanagawaCompile` afterwards! + compile = true, + + -- Dim inactive windows + dimInactive = true, + + -- Customize colors + colors = { + theme = { + all = { + ui = { + -- Disable background of gutter (line numbers etc.) + bg_gutter = 'none', + }, + }, + }, + }, +} + +--require('rose-pine').setup {} +--require('jb').setup {} + +-- Enable theme +vim.cmd.colorscheme('kanagawa') +--vim.cmd.colorscheme('rose-pine') +--vim.cmd.colorscheme('jb') diff --git a/.config/nvim/nvim-pack-lock.json b/.config/nvim/nvim-pack-lock.json new file mode 100644 index 0000000..7308339 --- /dev/null +++ b/.config/nvim/nvim-pack-lock.json @@ -0,0 +1,34 @@ +{ + "plugins": { + "blink.cmp": { + "rev": "78336bc89ee5365633bcf754d93df01678b5c08f", + "src": "https://github.com/saghen/blink.cmp", + "version": "1.0.0 - 2.0.0" + }, + "kanagawa": { + "rev": "bb85e4bfc8d89b0e62c8fa53ccdd13d12e2f77b3", + "src": "https://github.com/rebelot/kanagawa.nvim" + }, + "marks.nvim": { + "rev": "f353e8c08c50f39e99a9ed474172df7eddd89b72", + "src": "https://github.com/chentoast/marks.nvim" + }, + "nvim-highlight-colors": { + "rev": "e4c7af0211866162d999ce0bdd6a029302e19139", + "src": "https://github.com/brenoprata10/nvim-highlight-colors" + }, + "nvim-surround": { + "rev": "2e93e154de9ff326def6480a4358bfc149d5da2c", + "src": "https://github.com/kylechui/nvim-surround", + "version": "4.0.0 - 5.0.0" + }, + "substitute.nvim": { + "rev": "0d2077398552f069abccbd964a26dd7cd26882cd", + "src": "https://github.com/gbprod/substitute.nvim" + }, + "todo-comments.nvim": { + "rev": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668", + "src": "https://github.com/folke/todo-comments.nvim" + } + } +} diff --git a/.vimrc b/.vimrc index 1e91ac6..9001fcb 100644 --- a/.vimrc +++ b/.vimrc @@ -1,9 +1,24 @@ " Visual settings set t_Co=16 set bg=dark -set number highlight LineNr ctermfg=darkgrey +" Disable beeping on console +set belloff=all + +" Mouse settings +set mouse=a + +" Line numbers +set number +set relativenumber + +" Amount of screen lines that should be visible above/below the cursor +set scrolloff=5 + +" Wrap lines at word boundaries +set linebreak + " Syntax highlighting syntax on set hlsearch @@ -12,12 +27,11 @@ set hlsearch set ignorecase set smartcase -" Indentation options (yeah let's switch to spaces instead of tabs I guess...) -set autoindent +" Indentation settings +set smartindent set expandtab set shiftwidth=4 -set tabstop=4 -set softtabstop=4 +set softtabstop=-1 " Activate filetype plugin (e.g. for automatically using tabs instead of spaces in Makefiles) filetype plugin on @@ -29,120 +43,49 @@ autocmd BufNewFile,BufRead *.rasi set syntax=scss " Indentation for YAML (use 2 spaces) autocmd FileType yml,yaml setlocal sts=2 sw=2 -" Mouse settings -set mouse=a - -" Disable beeping on console -set belloff=all - " Do not insert comment leader when entering insert mode with 'o'/'O' in comment line autocmd BufNewFile,BufRead * set formatoptions-=o -" clang autocomplete: do not open completion box automatically -let g:clang_complete_auto=0 - - -" Disable middle mouse button paste when in normal mode -map -map <2-MiddleMouse> -map <3-MiddleMouse> -map <4-MiddleMouse> - " Keyboard mappings " ----------------- -nnoremap :nohl:diffupdate + +nnoremap :nohl:diffupdate set pastetoggle= -" Toggle line numbers -nnoremap :set number! +" Exit insert mode with jk +inoremap jk -" If the current buffer has never been saved, it will have no name, -" call the file browser to save it, otherwise just save it. -command! -nargs=0 -bar Update if &modified - \| if empty(bufname('%')) - \| browse confirm write - \| else - \| confirm write - \| endif - \|endif +" Quick exit with Ctrl-q +nnoremap :q +nnoremap Q -" Bind to save -nnoremap :Update -inoremap :Update +" Quick save all open buffers with Ctrl-S +nnoremap :wall +inoremap :wall + +" Simple copy and paste to/from system clipboard with Ctrl-c in visual mode +" and Ctrl-v in insert mode +vnoremap "+y +inoremap "+P " sudo-write with :w!! cnoremap w!! w !sudo tee >/dev/null % -" Edit (\ev) and reload (\rv) .vimrc (reload .gvimrc if running gvim) -nnoremap ev :split $MYVIMRC -if has('gui_running') - nnoremap rv :source $MYVIMRC:source $MYGVIMRC -else - nnoremap rv :source $MYVIMRC -endif - -" Split line at cursor with (as opposite of for join lines) -nnoremap ik$ - - -" Easier buffer switching -" ----------------------- -" Mappings to access buffers (don't use "\p" because a -" delay before pressing "p" would accidentally paste). -" \l : list buffers -" \b \n \g : go back/forward/last-used -" \1 \2 \3 : go to buffer 1/2/3 etc -nnoremap l :ls -nnoremap b :bp -nnoremap n :bn -nnoremap g :e# -nnoremap 1 :1b -nnoremap 2 :2b -nnoremap 3 :3b -nnoremap 4 :4b -nnoremap 5 :5b -nnoremap 6 :6b -nnoremap 7 :7b -nnoremap 8 :8b -nnoremap 9 :9b -nnoremap 0 :10b - -" Compiling and making -nnoremap :up:make:redraw! \| cw -nnoremap :up:make run:redraw! \| cw - -" Tab buffers -nnoremap :tab ball - " Tab movement noremap :-tabmove noremap :+tabmove +" Use comma (,) as a "modifier prefix" for alternative functions of regular +" commands (e.g. yank to system clipboard) or for random shortcuts. +noremap , -" -- Shortcuts for insert mode -" Exit insert mode -imap ,, -imap jk -inoremap - -" Quick movement with Alt-h/j/k/l -inoremap h -inoremap j -inoremap k -inoremap l - -" Unindent with Shift-Tab -inoremap << - -" Copy to and paste from X clipboard (Ctrl-C in visual mode and Ctrl-V in insert mode) -vmap "+y -imap "+P - -" Undo in insert mode with Ctrl-U -imap u - -" Quick exit -map Q :qa -" Because I always type q: too fast, which opens the command history... -map q: :q +" Prefix yank/delete/change/paste commands with "," to use system clipboard +noremap ,y "+y +noremap ,Y "+y$ +noremap ,d "+d +noremap ,D "+D +noremap ,c "+c +noremap ,C "+C +noremap ,p "+p +noremap ,P "+P