diff --git a/home/private_dot_config/nvim/init.lua b/home/private_dot_config/nvim/init.lua index d02ae9b..63caa23 100644 --- a/home/private_dot_config/nvim/init.lua +++ b/home/private_dot_config/nvim/init.lua @@ -2,5 +2,59 @@ vim.opt.number = true vim.opt.relativenumber = true --- Highlight the current line -vim.opt.cursorline = true +-- GUI stuff +vim.opt.cursorline = true -- Highlight the current line +vim.opt.colorcolumn = "80,120" -- Show vertical ruler +vim.opt.scrolloff = 8 -- Keep at least 8 lines between the cursor and the borders +vim.opt.wrap = false -- Don't wrap long lines + +-- Show whitespace characters (tabs, trailing spaces, etc.) +vim.opt.list = true +vim.opt.listchars = { tab = '» ', trail = '·', multispace = '·', nbsp = '␣' } + +-- Strip trailing whitespace and extra blank lines at end of file on save +local trim_group = vim.api.nvim_create_augroup('TrimOnSave', { clear = true }) +vim.api.nvim_create_autocmd('BufWritePre', { + group = trim_group, + pattern = '*', + callback = function() + local save_view = vim.fn.winsaveview() + vim.cmd([[%s/\s\+$//e]]) -- Remove trailing whitespace on every line + vim.cmd([[%s/\n\+\%$//e]]) -- Remove all trailing blank lines + vim.fn.append(vim.fn.line('$'), '') -- Always append exactly one blank line at the end + vim.fn.setpos('.', save_cursor) -- Restore the window to where it was before the edits + end, +}) + +-- Remove background opacity +vim.api.nvim_set_hl(0, 'Normal', { bg = 'none' }) +vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'none' }) + +-- Remember old sessions +vim.opt.undofile = true +local restore_cursor_group = vim.api.nvim_create_augroup('RestoreCursor', { clear = true }) +vim.api.nvim_create_autocmd('BufReadPost', { + group = restore_cursor_group, + callback = function() + local mark = vim.api.nvim_buf_get_mark(0, '"') + local last_line = vim.api.nvim_buf_line_count(0) + if mark[1] > 0 and mark[1] <= last_line then + vim.schedule(function() + vim.api.nvim_win_set_cursor(0, mark) + vim.cmd.normal({ 'zz', bang = true }) + end) + end + end, +}) + +-- Indentation +vim.opt.tabstop = 4 -- Visual width of a tab character +vim.opt.softtabstop = 4 -- Spaces inserted/deleted per Tab/Backspace in insert mode +vim.opt.shiftwidth = 4 -- Width used by >>, <<, and autoindent +vim.opt.expandtab = true -- Typed tabs become spaces +vim.opt.smartindent = true -- Auto-indent new lines based on syntax (e.g. after '{') + +-- Search +vim.opt.ignorecase = true -- Case-insensitive search... +vim.opt.smartcase = true -- ...unless you type an explicit uppercase letter + diff --git a/setup-script/roles/editor/tasks/main.yaml b/setup-script/roles/editor/tasks/main.yaml index 7fad585..5b3ac20 100644 --- a/setup-script/roles/editor/tasks/main.yaml +++ b/setup-script/roles/editor/tasks/main.yaml @@ -3,3 +3,9 @@ ansible.builtin.pacman: name: neovim when: chezmoi.osRelease.id == "arch" + +- name: Install the clipboard manager + become: true + ansible.builtin.pacman: + name: "{{ 'wl-clipboard' if lookup('env', 'XDG_SESSION_TYPE') == 'wayland' else 'xclip' }}" + when: chezmoi.osRelease.id == "arch"