# HG changeset patch # User zegervdv # Date 1631437762 -7200 # Node ID 5c960b123cba71cd1d62dafcf44ff45d94f36327 # Parent d99353d717029eb92be10a8c2479947c06ec9fb3 Use template for linux/osx too diff -r d99353d71702 -r 5c960b123cba dot_config/nvim/init.lua --- a/dot_config/nvim/init.lua Sun Sep 12 11:01:25 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,719 +0,0 @@ --- --- Neovim dotfiles --- --- -local execute = vim.api.nvim_command -local fn = vim.fn - --- Bootstrap package manager -local install_path = fn.stdpath 'data' .. '/site/pack/packer/opt/packer.nvim' - -if fn.empty(fn.glob(install_path)) > 0 then - execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path) -end - -vim.defer_fn(function() - -- Packer configuration is compiled and only needs to be loaded on changes - vim.cmd 'packadd packer.nvim' - - require('packer').startup(function() - use { 'wbthomason/packer.nvim', opt = true } - - -- General plugins - use { 'tpope/vim-sensible' } - use { 'tpope/vim-repeat' } - use { 'tpope/vim-rsi' } - use { 'sgur/vim-editorconfig' } - use { 'ShikChen/osc52.vim' } - use { 'einfachtoll/didyoumean' } - - use { 'tpope/vim-obsession' } - use { - 'tpope/vim-eunuch', - cmd = { - 'Delete', - 'Unlink', - 'Move', - 'Rename', - 'Mkdir', - 'Chmod', - 'Cfind', - 'Clocate', - 'Lfind', - 'Llocate', - 'SudoEdit', - 'SudoWrite', - 'Wall', - }, - } - - use { 'psliwka/vim-smoothie' } - - use { 'nvim-lua/plenary.nvim' } - - -- Spelling/autocorrection - use { 'tpope/vim-abolish' } - - -- Git/VCS - use { 'vim-scripts/gitignore' } - use { - 'sjl/splice.vim', - opt = true, - cmd = { 'SpliceInit' }, - config = function() - vim.g.splice_initial_diff_grid = 1 - vim.g.splice_initial_diff_compare = 1 - vim.g.splice_initial_diff_path = 0 - vim.g.splice_initial_scrollbind_grid = 1 - vim.g.splice_initial_scrollbind_compare = 1 - vim.g.splice_initial_scrollbind_path = 1 - vim.g.splice_wrap = 'nowrap' - end, - } - use { 'tpope/vim-git', ft = { 'gitcommit', 'gitrebase' } } - - -- Comments - use { - 'b3nj5m1n/kommentary', - config = function() - require('kommentary.config').configure_language('default', { prefer_single_line_comments = true }) - end, - keys = { - { 'n', 'gcc' }, - { 'v', 'gc' }, - }, - } - - -- Undoing - use { 'sjl/gundo.vim', cmd = { 'GundoToggle' } } - - -- Parentheses etc - use { 'tpope/vim-surround' } - use { - 'windwp/nvim-autopairs', - config = function() - local npairs = require 'nvim-autopairs' - local Rule = require 'nvim-autopairs.rule' - - require('nvim-autopairs.completion.cmp').setup { - map_cr = true, -- map on insert mode - map_complete = true, -- it will auto insert `(` after select function or method item - auto_select = false, -- automatically select the first item - } - - npairs.setup { - ignored_next_char = string.gsub([[ [%w%%%'%[%.] ]], '%s+', ''), - } - - npairs.add_rules { - Rule(' ', ' '):with_pair(function(opts) - local pair = opts.line:sub(opts.col - 1, opts.col) - return vim.tbl_contains({ '()', '[]', '{}' }, pair) - end), - Rule('( ', ' )') - :with_pair(function() - return false - end) - :with_move(function(opts) - return opts.prev_char:match '.%)' ~= nil - end) - :use_key ')', - Rule('{ ', ' }') - :with_pair(function() - return false - end) - :with_move(function(opts) - return opts.prev_char:match '.%}' ~= nil - end) - :use_key '}', - Rule('[ ', ' ]') - :with_pair(function() - return false - end) - :with_move(function(opts) - return opts.prev_char:match '.%]' ~= nil - end) - :use_key ']', - } - - npairs.get_rule('`'):with_pair(function() - return vim.bo.filetype ~= 'systemverilog' - end) - - npairs.get_rule("'"):with_pair(function() - return vim.bo.filetype ~= 'systemverilog' - end) - end, - after = { 'nvim-cmp' }, - } - - -- Moving around within lines - use { 'wellle/targets.vim', event = 'InsertEnter *' } - - -- Searching - use { 'mhinz/vim-grepper', cmd = { 'Grepper' } } - - -- Keymaps TODO: to be removed when #13823 is merged - use { - 'tjdevries/astronauta.nvim', - config = function() - require 'astronauta.keymap' - end, - } - - -- Opening files - use { 'wsdjeg/vim-fetch' } - - -- Indent lines - use { - 'lukas-reineke/indent-blankline.nvim', - config = function() - vim.g.indent_blankline_buftype_exclude = { 'terminal', 'help', 'nofile' } - vim.g.indent_blankline_show_first_indent_level = false - vim.g.indent_blankline_char = '│' - end, - } - - -- Increment/decrement - use { - 'zegervdv/nrpattern.nvim', - requires = 'tpope/vim-repeat', - config = function() - local nrpattern = require 'nrpattern' - local defaults = require 'nrpattern.default' - - defaults[{ 'input', 'output' }] = { priority = 12, filetypes = { 'verilog', 'systemverilog' } } - defaults[{ "'1", "'0" }] = { priority = 9, filetypes = { 'verilog', 'systemverilog' } } - - nrpattern.setup(defaults) - end, - } - - -- Tmux - use { - 'numtostr/navigator.nvim', - config = function() - require('Navigator').setup { auto_save = 'current', disable_on_zoom = true } - - local nnoremap = vim.keymap.nnoremap - nnoremap { '', require('Navigator').left, silent = true } - nnoremap { '', require('Navigator').down, silent = true } - nnoremap { '', require('Navigator').up, silent = true } - nnoremap { '', require('Navigator').right, silent = true } - end, - requires = 'tjdevries/astronauta.nvim', - after = 'astronauta.nvim', - } - - -- Completion/snippets/LSP - use { 'neovim/nvim-lspconfig' } - use { - 'hrsh7th/nvim-cmp', - requires = { 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-vsnip', 'hrsh7th/cmp-path' }, - config = function() - local cmp = require 'cmp' - cmp.setup { - snippet = { - expand = function(args) - vim.fn['vsnip#anonymous'](args.body) - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - }, - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'buffer' }, - { name = 'vsnip' }, - { name = 'path' }, - }, - } - end, - } - use { - { - 'nvim-treesitter/nvim-treesitter', - config = function() - require 'nvim-treesitter.highlight' - - require('nvim-treesitter.configs').setup { - highlight = { enable = false }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = 'gnn', - node_incremental = 'grn', - scope_incremental = 'grc', - node_decremental = 'grm', - }, - }, - refactor = { - highlight_definitions = { enable = true }, - smart_rename = { enable = true, keymaps = { smart_rename = 'gsr' } }, - navigation = { - enable = true, - keymaps = { goto_definition = 'gnd', list_definitions = 'gnD' }, - }, - }, - textobjects = { - move = { - enable = true, - goto_next_start = { [']]'] = '@block.outer' }, - goto_previous_start = { ['[['] = '@block.outer' }, - goto_next_end = { [']['] = '@block.outer' }, - goto_previous_end = { ['[]'] = '@block.outer' }, - }, - }, - playground = { enable = true, disable = {}, updatetime = 25, persist_queries = false }, - } - end, - }, - 'nvim-treesitter/nvim-treesitter-refactor', - 'nvim-treesitter/nvim-treesitter-textobjects', - { 'nvim-treesitter/playground', opt = true }, - } - use { 'hrsh7th/vim-vsnip', requires = 'hrsh7th/vim-vsnip-integ' } - use { - 'rmagatti/goto-preview', - config = function() - require('goto-preview').setup {} - end, - } - use { - 'jose-elias-alvarez/null-ls.nvim', - requires = 'nvim-lua/plenary.nvim', - } - use { 'folke/lua-dev.nvim' } - - use { 'vimjas/vim-python-pep8-indent', ft = { 'python' } } - - -- Vanity - use { - 'yamatsum/nvim-web-nonicons', - requires = 'kyazdani42/nvim-web-devicons', - config = function() - require 'nvim-nonicons' - end, - } - - use { - 'glepnir/galaxyline.nvim', - branch = 'main', - -- your statusline - config = function() - local gl = require 'galaxyline' - local colors = require('galaxyline.theme').default - local condition = require 'galaxyline.condition' - local gls = gl.section - - colors.bg = '#2C323C' - - gls.left[1] = { - RainbowRed = { - provider = function() - return '▊ ' - end, - highlight = { colors.blue, colors.bg }, - }, - } - - gls.left[2] = { - FileName = { - provider = function() - return require('galaxyline.provider_fileinfo').get_current_file_name '⊙' - end, - condition = condition.buffer_not_empty, - highlight = { colors.magenta, colors.bg, 'bold' }, - }, - } - - gls.right[1] = { - ShowLspClient = { - provider = 'GetLspClient', - condition = function() - local tbl = { ['dashboard'] = true, [''] = true } - if tbl[vim.bo.filetype] then - return false - end - return true - end, - highlight = { colors.green, colors.bg, 'bold' }, - }, - } - - gls.right[2] = { - LineInfo = { - provider = 'LineColumn', - separator = ' ', - separator_highlight = { 'NONE', colors.bg }, - highlight = { colors.fg, colors.bg }, - }, - } - - gls.right[3] = { - PerCent = { - provider = 'LinePercent', - separator = ' ', - separator_highlight = { 'NONE', colors.bg }, - highlight = { colors.fg, colors.bg, 'bold' }, - }, - } - gls.right[8] = { - RainbowBlue = { - provider = function() - return ' ▊' - end, - highlight = { colors.blue, colors.bg }, - }, - } - - gls.short_line_left[1] = { - BufferType = { - provider = 'FileTypeName', - separator = ' ', - separator_highlight = { 'NONE', colors.bg }, - highlight = { colors.blue, colors.bg, 'bold' }, - }, - } - - gls.short_line_left[2] = { - SFileName = { - provider = 'SFileName', - condition = condition.buffer_not_empty, - highlight = { colors.fg, colors.bg, 'bold' }, - }, - } - - gls.short_line_right[1] = { - BufferIcon = { provider = 'BufferIcon', highlight = { colors.fg, colors.bg } }, - } - end, - } - - -- File navigation - use { 'justinmk/vim-dirvish' } - - -- Colorscheme - use { - 'zegervdv/one-lush', - requires = 'rktjmp/lush.nvim', - config = function() - require 'lush_theme.one-lush' - vim.cmd [[ colorscheme one-lush ]] - end, - } - - -- Terminal - use { - 'akinsho/nvim-toggleterm.lua', - config = function() - require('toggleterm').setup { - size = 15, - open_mapping = [[]], - shade_filetypes = { 'none' }, - shade_terminals = true, - persist_size = true, - direction = 'horizontal', - } - end, - keys = { [[]] }, - } - - -- Filetypes - use { 'lepture/vim-jinja' } - end) -end, 0) - --- Configuration -local opt = vim.opt - -opt.backspace = { 'indent', 'eol', 'start' } -- Backspace everything - -opt.autoread = true -- Read changed files -opt.hidden = true -- Allow to move away from modified files -opt.autowriteall = true -- Write changes when losing focus - --- Visuals -opt.number = true -opt.relativenumber = true -opt.scrolloff = 4 -opt.showcmd = true -- Show incomplete commands while typing - -opt.termguicolors = true -opt.background = 'dark' - -opt.showmatch = true -- Highligh matching braces - -opt.wrap = true -- Wrap lines -opt.wrapmargin = 2 -- Stay 2 chars from side -opt.textwidth = 79 -opt.colorcolumn = '81' -- Show indication of 81 chars -opt.linebreak = true -- Smarter wrapping -opt.breakindent = true -- Indent wrapped lines to same level - -opt.fixendofline = true -- Add EOL when missing - -opt.expandtab = true -- Add spaces when pressing tab -opt.tabstop = 2 -- Tab is 2 spaces -opt.shiftwidth = 2 -- Shift per 2 spaces -opt.shiftround = true -- Round shifts to allign (1 space + tab = 2 spaces) - --- Searching and substitute -opt.magic = true -- Enable regexes -opt.hlsearch = true -- Highlight all matches -opt.incsearch = true -- Show matches while typing -opt.ignorecase = true -opt.smartcase = true -- When search pattern contains cases, be case sensitive -opt.gdefault = true -- Use global flag for substitute: replace all matches on line -opt.inccommand = 'nosplit' -- Show live replacements directly in text - -opt.autoindent = true -opt.cindent = true -- C-syntax based indenting - -opt.updatetime = 300 -- Faster triggering of CursorHold events - -opt.errorbells = false -- Don't you beep to me - -opt.history = 1000 -- Remember last commands - -opt.wildmenu = true -- Command completion -opt.wildmode = 'longest:full,full' -opt.shortmess:append 'c' -- Hide ins-completion messages - -opt.ttyfast = true -- fast terminal -opt.lazyredraw = true -opt.ttimeoutlen = -1 -- Minimum timeout - -opt.diffopt:append 'iwhite' -- Ignore whitespace in diffs -opt.diffopt:append 'internal' -- Internal diff engine -opt.diffopt:append 'algorithm:patience' -- Use patience algorithm - -opt.tags = { '.git/tags', 'tags' } - -opt.path:append '**' -- Recursively search current directory - -opt.formatoptions = { - c = true, -- Wrap comments - r = true, -- Continue comments - o = true, -- Insert comment with o/O - q = true, -- Format comments with gq - n = true, -- Indent numbered lists - [2] = true, -- Indent from 2nd line of paragraph - [1] = true, -- Don't break before one letter words -} - -opt.signcolumn = 'yes' -- Always show signcolumn - -opt.cursorline = true - --- Show certain characters -opt.list = true -opt.listchars = { trail = '·', extends = '>', precedes = '<', nbsp = '+' } - -opt.sessionoptions:remove 'options' -- Remove options from saved sessions (reload from config) - -opt.completeopt = { 'menu', 'menuone', 'noselect' } - -opt.splitright = true -- Open new splits to right -opt.virtualedit = 'block' -- Enable block editting - -opt.conceallevel = 0 -- Disable conceal - -opt.pastetoggle = '' -- Enable paste mode - -opt.undofile = true -- Persistently remember undos -opt.undolevels = 1000 -opt.undodir = os.getenv 'HOME' .. '/.config/nvim/tmp/undo//' -opt.swapfile = false -- Disable swap files -opt.backup = true -- Keep backups -opt.backupdir = os.getenv 'HOME' .. '/.config/nvim/tmp/backup//' - --- Files to ignore from completion -opt.wildignore:append { - '*/tmp/*', - '*.so', - '*.swp', - '*.zip', - '*.o', - '*.bin', - '*.elf', - '*.hex', - '*.eps', - '.git/*', - '*.dup', - '.hg/**', - '*.orig', - '*.*~', -} - -opt.mouse = { - n = true, -- Normal mode - i = true, -- Insert mode - c = true, -- Commandline mode -} - --- LSP config -local lsp = require 'lspconfig' -local null_ls = require 'null-ls' - -local on_attach = function(client) - local nnoremap = vim.keymap.nnoremap - local inoremap = vim.keymap.inoremap - nnoremap { 'gd', vim.lsp.buf.declaration, silent = true } - nnoremap { '', vim.lsp.buf.definition, silent = true } - nnoremap { - 'g', - function() - local params = vim.lsp.util.make_position_params() - opts = {} - local results_lsp = vim.lsp.buf_request_sync(0, 'textDocument/definition', params, opts.timeout or 10000) - if not results_lsp or vim.tbl_isempty(results_lsp) then - print 'No results from textDocument/definition' - return - end - for _, lsp_data in pairs(results_lsp) do - if lsp_data ~= nil and lsp_data.result ~= nil and not vim.tbl_isempty(lsp_data.result) then - for _, value in pairs(lsp_data.result) do - local range = value.range or value.targetRange - if range ~= nil then - local file = value.uri or value.targetUri - if file ~= nil then - vim.api.nvim_command [[split]] - vim.lsp.util.jump_to_location(value) - return - end - end - end - end - end - -- try to call default lsp function - vim.lsp.buf.definition() - end, - silent = true, - } - nnoremap { 'K', vim.lsp.buf.hover, silent = true } - nnoremap { 'gD', vim.lsp.buf.implementation, silent = true } - nnoremap { '1gD', vim.lsp.buf.type_definition, silent = true } - nnoremap { 'gr', vim.lsp.buf.references, silent = true } - nnoremap { 'g0', vim.lsp.buf.document_symbol, silent = true } - nnoremap { - '', - function() - vim.lsp.buf.formatting_sync({}, 5000) - end, - silent = true, - } - -- nnoremap { 'gp', require'lspsaga.provider'.preview_definition, silent = true } - nnoremap { 'gp', require('goto-preview').goto_preview_definition, silent = true } - nnoremap { 'gP', require('goto-preview').close_all_win, silent = true } - - inoremap { '', vim.lsp.buf.signature_help, silent = true } - - vim.fn.sign_define( - 'LspDiagnosticsSignError', - { texthl = 'LspDiagnosticsSignError', linehl = '', numhl = '', text = '▎' } - ) - vim.fn.sign_define('LspDiagnosticsSignWarning', { - texthl = 'LspDiagnosticsSignWarning', - linehl = '', - numhl = '', - text = '▎', - }) - vim.fn.sign_define('LspDiagnosticsSignInformation', { - texthl = 'LspDiagnosticsSignInformation', - linehl = '', - numhl = '', - text = '▎', - }) - vim.fn.sign_define( - 'LspDiagnosticsSignHint', - { texthl = 'LspDiagnosticsSignHint', linehl = '', numhl = '', text = '▎' } - ) - - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) - vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) - vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = true, - update_in_insert = false, - virtual_text = { severity_limit = 'Warning' }, - }) -end - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - }, -} -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) - -lsp.pyright.setup { on_attach = on_attach, capabilities = capabilities } - -null_ls.config { - sources = { - null_ls.builtins.formatting.black, - null_ls.builtins.formatting.stylua, - }, -} -lsp['null-ls'].setup { - on_attach = on_attach, - root_dir = require('lspconfig.util').root_pattern('.hg', '.git'), -} - -local luadev = require('lua-dev').setup { - lspconfig = { - cmd = { 'lua-language-server' }, - on_attach = on_attach, - capabilities = capabilities, - settings = { - Lua = { - diagnostics = { - globals = { 'use' }, - }, - }, - }, - }, -} - -lsp.sumneko_lua.setup(luadev) - --- Populate quickfix with all locations of rename -function LspRename() - local params = vim.lsp.util.make_position_params() - params.newName = vim.fn.input("Rename: ", vim.fn.expand('')) - vim.lsp.buf_request(0, 'textDocument/rename', params, function(err, result, ctx, ...) - vim.lsp.handlers['textDocument/rename'](err, result, ctx, ...) - local changed = {} - for uri, changes in pairs(result.changes) do - local bufnr = vim.uri_to_bufnr(uri) - for _, edits in ipairs(changes) do - table.insert(changed, { - bufnr = bufnr, - lnum = edits.range.start.line + 1, - col = edits.range.start.character + 1, - text = vim.api.nvim_buf_get_lines(bufnr, edits.range.start.line, edits.range.start.line + 1, false)[1], - }) - end - end - vim.fn.setqflist(changed, 'r') - end) -end - -vim.cmd [[command! LspRename lua LspRename()]] - --- Try importing local config -local ok, localconfig = pcall(require, 'localconfig') -if ok then - localconfig.setup { on_attach = on_attach, capabilities = capabilities } -end diff -r d99353d71702 -r 5c960b123cba dot_config/nvim/init.lua.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dot_config/nvim/init.lua.tmpl Sun Sep 12 11:09:22 2021 +0200 @@ -0,0 +1,1 @@ +{{- template "init.lua" -}} diff -r d99353d71702 -r 5c960b123cba dot_config/nvim/plugin/config.vim --- a/dot_config/nvim/plugin/config.vim Sun Sep 12 11:01:25 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,798 +0,0 @@ -" vim:fdm=marker:ts=2:sw=2 - -let s:darwin = has('mac') -let s:windows = has('win32') - -" Activate built in plugins {{{ -if !has('nvim') - if has('packages') - packadd! matchit - packadd! shellmenu - endif -endif -source $VIMRUNTIME/ftplugin/man.vim - -if has('packages') - silent! packadd! log_file - silent! packadd! snippets -endif - -if has("nvim") - let g:python3_host_prog=expand('$HOME/.config/virtualenvs/python3/bin/python') - let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python') -endif -" }}} - -" General Settings and options {{{ - -augroup cline - au! - autocmd WinEnter * setlocal cursorline - autocmd WinLeave * setlocal nocursorline -augroup END - -if !isdirectory(expand(&backupdir)) - call mkdir(expand(&backupdir), "p") -endif -if !isdirectory(expand(&directory)) - call mkdir(expand(&directory), "p") -endif - -if v:version >= 703 - if !isdirectory(expand(&undodir)) - call mkdir(expand(&undodir), "p") - endif -endif - -" }}} - -" Mappings {{{ -" Set leader to spacebar -map - -" See long lines as line breaks -noremap j (v:count? 'j' : 'gj') -noremap k (v:count? 'k' : 'gk') - -" Remap tag-search to better place -nnoremap g -nnoremap y g - -nnoremap - -" Move while in insert mode -inoremap - -" Switch between the last two files -" nnoremap - -" " Very Magic search patterns -nnoremap / /\v -vnoremap / /\v - -" Keep search matches in the middle of the window. -nnoremap n nzzzv -nnoremap N Nzzzv - -" Search for beginning of command -cnoremap -cnoremap - -" Move whole lines -nnoremap [e :execute 'move -1-'. v:count1 -nnoremap ]e :execute 'move +'. v:count1 - -" Insert empty lines -nnoremap [ :put! =repeat(nr2char(10), v:count1)'[ -nnoremap ] :put =repeat(nr2char(10), v:count1) - -" Clear highlight -nnoremap l :noh - -inoremap £ \ - -" Highlight last inserted text -nnoremap gV `[v`] - -" Highlight VCS conflict markers -match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' - -" Use backspace as delete in visual mode -vmap x - -" Redraw screen -nnoremap :redraw! - -" Keep selection when shifting -vmap > KeepVisualSelection(">") -vmap < KeepVisualSelection("<") - -function! KeepVisualSelection(cmd) - set nosmartindent - if mode() ==# "V" - return a:cmd . ":set smartindent\gv" - else - return a:cmd . ":set smartindent\" - endif -endfunction - -" Swap backticks and quotes -nnoremap ` ' -nnoremap ' ` - -" Open vimrc -nnoremap ve :e $MYVIMRC -nnoremap vs :so $MYVIMRC - -" Open dup in diffmode -nnoremap d :call OpenDup(@%) - -function! OpenDup(file) - let l:filename = a:file . ".dup" - execute 'vsplit' l:filename - windo diffthis -endfunction - -" Do not move on * -nnoremap * :let stay_star_view = winsaveview()*:call winrestview(stay_star_view) - -" Search for selected text, forwards or backwards. -vnoremap * : - \let old_reg=getreg('"')let old_regtype=getregtype('"') - \gvy/=substitute( - \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g') - \gV:call setreg('"', old_reg, old_regtype) -vnoremap # : - \let old_reg=getreg('"')let old_regtype=getregtype('"') - \gvy?=substitute( - \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g') - \gV:call setreg('"', old_reg, old_regtype) - -" nnoremap :botright copen - -xnoremap p p:if v:register == '"'let @@=@0endif - -" Error navigation -nnoremap :cprev -nnoremap :cnext -nnoremap :cnf -nnoremap :cpf - -nnoremap y :ptjump - -function! ToggleDiff() - if &diff == 1 - windo diffoff - else - windo diffthis - endif -endfunction -nnoremap g :call ToggleDiff() - -if has('nvim') - tnoremap h - tnoremap j - tnoremap k - tnoremap l - augroup enter_term - au! - autocmd TermOpen * startinsert! - autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif - autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif - augroup END - let $GIT_EDITOR = 'nvr -cc split --remote-wait' -endif - -" Open buffers, tags... in vertical splits -nnoremap b :vert sbuffer -nnoremap t :vert stjump -nnoremap f :vert sfind - - -" }}} - -" Functions {{{ -" When editing a file, always jump to the last known cursor position. -" Don't do it for commit messages, when the position is invalid, or when -" inside an event handler (happens when dropping a file on gvim). -autocmd BufReadPost * - \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal g`\"" | - \ endif - -" Thg mappings -function! s:HGhist(file) - if !empty(a:file) - let path = a:file - else - let path = expand('%') - endif - exec 'silent! !thg filelog ' . path . ' &' -endfunction - -command! -nargs=? -complete=file HGhist call s:HGhist() - -augroup focus_lost - au! - au FocusLost * if !&readonly | :wa | endif -augroup END - -augroup LuaHighlight - autocmd! - autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() -augroup END - -" Resize splits after window resize {{{ -augroup vim_resize - au! - au VimResized * exe "normal! \=" -augroup END -" }}} - -" Automatically reload vimrc when saving {{{ -augroup reload_vim - autocmd! - autocmd BufWritePost $MYVIMRC nested source $MYVIMRC -augroup END -" }}} - -" Reload diffs {{{ -augroup diff_files - au! - au BufWritePost * if &diff == 1 | diffupdate | endif -augroup END -" }}} - -" Custom folding by Steve Losh -function! MyFoldText() " {{{ - let line = getline(v:foldstart) - - let nucolwidth = &fdc + &number * &numberwidth - let windowwidth = winwidth(0) - nucolwidth - 3 - let foldedlinecount = v:foldend - v:foldstart - - " expand tabs into spaces - let onetab = strpart(' ', 0, &tabstop) - let line = substitute(line, '\t', onetab, 'g') - - let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) - let fillcharcount = windowwidth - len(line) - len(foldedlinecount) - return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' -endfunction " }}} -set foldtext=MyFoldText() -set foldopen+=jump - -" Detect Filetype from content if file has no extension {{{ -augroup newFileDetection - au! - autocmd CursorMovedI * call CheckFileType() -augroup END - -function! CheckFileType() - if exists("b:countCheck") == 0 - let b:countCheck = 0 - endif - let b:countCheck += 1 - if &filetype == "" && b:countCheck > 20 && b:countCheck < 200 - filetype detect - " Delete the function if no filetype can be established, or the type has - " been found - elseif b:countCheck >= 200 || &filetype != "" - autocmd! newFileDetection - endif -endfunction -" }}} - -" Convert hex <-> decimal {{{ -command! -nargs=? -range Dec2hex call s:Dec2hex(, , '') -function! s:Dec2hex(line1, line2, arg) range - if empty(a:arg) - if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' - let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' - else - let cmd = 's/\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' - endif - try - execute a:line1 . ',' . a:line2 . cmd - catch - echo 'Error: No decimal number found' - endtry - else - echo printf('%x', a:arg + 0) - endif -endfunction - -command! -nargs=? -range Hex2dec call s:Hex2dec(, , '') -function! s:Hex2dec(line1, line2, arg) range - if empty(a:arg) - if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' - let cmd = 's/\%V0x\x\+/\=submatch(0)+0/g' - else - let cmd = 's/0x\x\+/\=submatch(0)+0/g' - endif - try - execute a:line1 . ',' . a:line2 . cmd - catch - echo 'Error: No hex number starting "0x" found' - endtry - else - echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 - endif -endfunction -" }}} - -" Recognize filetype for dup files {{{ -autocmd! BufRead *.dup call DupSetSyntax(@%) - -function! DupSetSyntax(name) - let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1] - if extension == "vhd" - setlocal filetype=vhdl - elseif extension == "v" - setlocal filetype=verilog - elseif extension == "sv" - setlocal filetype=verilog - else - echo "Unknown filetype" - endif -endfunction -" }}} - -" Create arguments list from files in quickfix list -" Allows to Grep for a pattern and apply an argdo command on each of the -" matching files {{{ -command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() -function! QuickfixFilenames() - " Building a hash ensures we get each buffer only once - let buffer_numbers = {} - for quickfix_item in getqflist() - let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) - endfor - return join(map(values(buffer_numbers), 'fnameescape(v:val)')) -endfunction -"}}} - -augroup mark_files - au! - au BufLeave test.tcl mark T - au BufLeave case.do mark C - au BufLeave drv_*.tcl mark D - au BufLeave *.rtl.vhd mark R -augroup END - - -" Toggle between opening/closing the quickfix window {{{ -function! GetBufferList() - redir =>buflist - silent! ls! - redir END - return buflist -endfunction - -function! ToggleList(bufname, pfx) - let buflist = GetBufferList() - for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') - if bufwinnr(bufnum) != -1 - exec(a:pfx.'close') - return - endif - endfor - if a:pfx == 'l' && len(getloclist(0)) == 0 - echohl ErrorMsg - echo "Location List is Empty." - return - endif - let winnr = winnr() - exec('botright '.a:pfx.'open') - if winnr() != winnr - wincmd p - endif -endfunction - -nnoremap :call ToggleList("Quickfix List", 'c') -" }}} - - -" Make list-like commands more intuitive {{{ -" Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 -function! CCR() - let cmdline = getcmdline() - if cmdline =~ '\v\C^(ls|files|buffers)' - " like :ls but prompts for a buffer command - return "\:b" - elseif cmdline =~ '\v\C/(#|nu|num|numb|numbe|number)$' - " like :g//# but prompts for a command - return "\:" - elseif cmdline =~ '\v\C^(dli|il)' - " like :dlist or :ilist but prompts for a count for :djump or :ijump - return "\:" . cmdline[0] . "j " . split(cmdline, " ")[1] . "\\" - elseif cmdline =~ '\v\C^(cli|lli)' - " like :clist or :llist but prompts for an error/location number - return "\:sil " . repeat(cmdline[0], 2) . "\" - elseif cmdline =~ '\C^old' - " like :oldfiles but prompts for an old file to edit - set nomore - return "\:sil se more|e #<" - elseif cmdline =~ '\C^changes' - " like :changes but prompts for a change to jump to - set nomore - return "\:sil se more|norm! g;\" - elseif cmdline =~ '\C^ju' - " like :jumps but prompts for a position to jump to - set nomore - return "\:sil se more|norm! \\" - elseif cmdline =~ '\C^marks' - " like :marks but prompts for a mark to jump to - return "\:norm! `" - elseif cmdline =~ '\C^undol' - " like :undolist but prompts for a change to undo - return "\:u " - else - return "\" - endif -endfunction -cnoremap CCR() -" }}} - -" Text objects {{{ -function! s:inIndentation() - " select all text in current indentation level excluding any empty lines - " that precede or follow the current indentationt level; - " - " the current implementation is pretty fast, even for many lines since it - " uses "search()" with "\%v" to find the unindented levels - " - " NOTE: if the current level of indentation is 1 (ie in virtual column 1), - " then the entire buffer will be selected - " - " WARNING: python devs have been known to become addicted to this - " magic is needed for this - let l:magic = &magic - set magic - - " move to beginning of line and get virtcol (current indentation level) - " BRAM: there is no searchpairvirtpos() ;) - normal! ^ - let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') - - " pattern matching anything except empty lines and lines with recorded - " indentation level - let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' - - " find first match (backwards & don't wrap or move cursor) - let l:start = search(l:pat, 'bWn') + 1 - - " next, find first match (forwards & don't wrap or move cursor) - let l:end = search(l:pat, 'Wn') - - if (l:end !=# 0) - " if search succeeded, it went too far, so subtract 1 - let l:end -= 1 - endif - - " go to start (this includes empty lines) and--importantly--column 0 - execute 'normal! '.l:start.'G0' - - " skip empty lines (unless already on one .. need to be in column 0) - call search('^[^\n\r]', 'Wc') - - " go to end (this includes empty lines) - execute 'normal! Vo'.l:end.'G' - - " skip backwards to last selected non-empty line - call search('^[^\n\r]', 'bWc') - - " go to end-of-line 'cause why not - normal! $o - - " restore magic - let &magic = l:magic -endfunction - -" "in indentation" (indentation level sans any surrounding empty lines) -xnoremap ii :call inIndentation() -onoremap ii :call inIndentation() - -function! s:aroundIndentation() - " select all text in the current indentation level including any emtpy - " lines that precede or follow the current indentation level; - " - " the current implementation is pretty fast, even for many lines since it - " uses "search()" with "\%v" to find the unindented levels - " - " NOTE: if the current level of indentation is 1 (ie in virtual column 1), - " then the entire buffer will be selected - " - " WARNING: python devs have been known to become addicted to this - - " magic is needed for this (/\v doesn't seem work) - let l:magic = &magic - set magic - - " move to beginning of line and get virtcol (current indentation level) - " BRAM: there is no searchpairvirtpos() ;) - normal! ^ - let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') - - " pattern matching anything except empty lines and lines with recorded - " indentation level - let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' - - " find first match (backwards & don't wrap or move cursor) - let l:start = search(l:pat, 'bWn') + 1 - - " NOTE: if l:start is 0, then search() failed; otherwise search() succeeded - " and l:start does not equal line('.') - " FORMER: l:start is 0; so, if we add 1 to l:start, then it will match - " everything from beginning of the buffer (if you don't like - " this, then you can modify the code) since this will be the - " equivalent of "norm! 1G" below - " LATTER: l:start is not 0 but is also not equal to line('.'); therefore, - " we want to add one to l:start since it will always match one - " line too high if search() succeeds - - " next, find first match (forwards & don't wrap or move cursor) - let l:end = search(l:pat, 'Wn') - - " NOTE: if l:end is 0, then search() failed; otherwise, if l:end is not - " equal to line('.'), then the search succeeded. - " FORMER: l:end is 0; we want this to match until the end-of-buffer if it - " fails to find a match for same reason as mentioned above; - " again, modify code if you do not like this); therefore, keep - " 0--see "NOTE:" below inside the if block comment - " LATTER: l:end is not 0, so the search() must have succeeded, which means - " that l:end will match a different line than line('.') - - if (l:end !=# 0) - " if l:end is 0, then the search() failed; if we subtract 1, then it - " will effectively do "norm! -1G" which is definitely not what is - " desired for probably every circumstance; therefore, only subtract one - " if the search() succeeded since this means that it will match at least - " one line too far down - " NOTE: exec "norm! 0G" still goes to end-of-buffer just like "norm! G", - " so it's ok if l:end is kept as 0. As mentioned above, this means - " that it will match until end of buffer, but that is what I want - " anyway (change code if you don't want) - let l:end -= 1 - endif - - " finally, select from l:start to l:end - execute 'normal! '.l:start.'G0V'.l:end.'G$o' - - " restore magic - let &magic = l:magic -endfunction - -" "around indentation" (indentation level and any surrounding empty lines) -xnoremap ai :call aroundIndentation() -onoremap ai :call aroundIndentation() -" }}} -" }}} - -" Filetype specific settings {{{ -" Text {{{ -augroup ft_text - au! - " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb - au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 -augroup END -augroup ft_report - au! - au BufNewFile,BufRead,BufEnter *.rpt setlocal nowrap - au BufNewFile,BufRead,BufEnter *.rpt call ColorRpt() - au BufNewFile,BufRead,BufEnter *.log call ColorRpt() -augroup END - -function! ColorRpt() - " Color numbers based on length - syn match String "\v<\d{1,3}>" - syn match Number "\v<\d{4,6}>" - syn match Statement "\v<\d{7,9}>" - - " Color errors - syn match Error "\v^ERROR:.*$" -endfunction -" }}} -" Git commit messages {{{ -augroup ft_git - au! - au FileType gitcommit setlocal spell spelllang=en_gb - autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete -augroup END -" }}} -" Ruby {{{ -augroup ft_ruby - au! - autocmd BufRead *_spec.rb set filetype=rspec -augroup END -" }}} -" Matlab {{{ -augroup ft_matlab - au! - autocmd FileType matlab setlocal commentstring=\%\ %s -augroup END -" }}} -" C {{{ -augroup ft_c - au! - au FileType c setlocal foldmethod=syntax -augroup END -" }}} -" TCL {{{ - -augroup ft_tcl - au! - autocmd FileType tcl setlocal commentstring=#\ %s - " autocmd FileType tcl compiler nagelfar - autocmd BufRead *.do set filetype=tcl - autocmd BufRead *.hal set filetype=tcl - autocmd FileType tcl setlocal iskeyword+=: - autocmd FileType tcl setlocal breakat-=: - autocmd FileType tcl setlocal suffixesadd+=.tcl,.do -augroup END -" shortcuts -iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; -" }}} -" GPG {{{ -" Don't save backups of gpg asc files -set backupskip+=*.asc - -" Convenient editing of ascii-armoured encrypted files -augroup GPGASCII - au! - au BufReadPost *.asc :%!gpg -q -d - au BufReadPost *.asc |redraw - au BufWritePre *.asc :%!gpg -q -e -a - au BufWritePost *.asc u - au VimLeave *.asc :!clear -augroup END -" }}} -" System Verilog {{{ -augroup ft_systemverilog - au! - au FileType systemverilog setlocal suffixesadd+=.sv,.v - au FileType systemverilog setlocal foldmethod=expr - au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr() - au FileType systemverilog,verilog call SVAlign() - au FileType systemverilog,verilog let b:delimitMate_quotes = "\"" - au FileType systemverilog,verilog set iskeyword+=' -augroup END - -function! SVAlign() - let g:easy_align_delimiters = { - \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} - \} -endfunction -" }}} -" Make {{{ -augroup ft_make - autocmd! - autocmd BufEnter *.make setlocal filetype=make - autocmd FileType make setlocal noexpandtab -augroup END -" JSON {{{ -augroup ft_json - autocmd! - autocmd FileType json setlocal equalprg=jq -augroup END -" }}} -" }}} -" Python {{{ -augroup f_python - autocmd! - autocmd FileType python setlocal shiftwidth=4 - au FileType python setlocal formatprg=autopep8\ - - autocmd FileType python setlocal path-=** - autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"] -augroup END - -let g:python_highlight_all=1 -" }}} -" }}} - -" Plugin settings {{{ -" Gundo tree {{{ -nnoremap u :GundoToggle -" }}} -" Projectionist {{{ -let g:projectionist_heuristics = { - \ "*.c": { - \ "*.c": { - \ "alternate": "{}.h", - \ "type": "source", - \ "template": ["#include \"{}.h\""], - \ "make": "make -wC {project}" - \ }, - \ "*.h": { - \ "alternate": "{}.c", - \ "type": "header", - \ "template": ["#ifndef {uppercase}_H", "#define {uppercase}_H", "", "#endif"] - \ }, - \ "Makefile": {"type": "makefile"}, - \ }, - \ "*.py": { - \ "*.py": { "make": "ipython {}" } - \ }, - \ } -" }}} -" Grep {{{ -let g:grepper = { - \ 'tools': ['ag', 'hg'], - \ 'highlight': 1, - \ 'ag': { - \ 'grepprg': 'rg --vimgrep', - \ }} - -nnoremap gs (GrepperOperator) -xnoremap gs (GrepperOperator) - - -command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep -" }}} -" Vinegar/NetRW {{{ -autocmd FileType netrw setl bufhidden=delete -" }}} -" NCM {{{ -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Auto close popup menu when finish completion -autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif - -" Use and to navigate through popup menu -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - -" Set completeopt to have a better completion experience -set completeopt=menuone,noinsert,noselect - -" Avoid showing message extra message when using completion -set shortmess+=c - -let g:completion_enable_snippet = 'UltiSnips' -let g:UltiSnipsJumpForwardTrigger="" -let g:UltiSnipsJumpBackwardTrigger="" -let g:completion_enable_auto_paren=0 - -imap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' -smap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' -imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' -smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' - -" }}} -" }}} -" }}} - -function! SendOSCClipboard(lines, regtype) - call SendViaOSC52(join(a:lines, "\n")) -endfunction - -let g:clipboard = { - \ 'name': 'TMUX', - \ 'copy': { - \ '+': function('SendOSCClipboard'), - \ '*': 'tmux load-buffer -', - \ }, - \ 'paste': { - \ '+': 'tmux save-buffer -', - \ '*': 'tmux save-buffer -', - \ }, - \ 'cache_enabled': 1, - \ } -" Load local vimrc -if filereadable($HOME . '/.vimrc.local') - source ~/.vimrc.local -endif - -" Load project local vimrc -if filereadable('.vimrc.local') - source .vimrc.local -endif - -augroup Chezmoi - autocmd! - autocmd BufWritePost ~/.local/share/chezmoi/* silent !chezmoi apply --source-path % - autocmd BufWritePost ~/.local/share/chezmoi/dot_config/nvim/init.lua source | PackerCompile -augroup END diff -r d99353d71702 -r 5c960b123cba dot_config/nvim/plugin/config.vim.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dot_config/nvim/plugin/config.vim.tmpl Sun Sep 12 11:09:22 2021 +0200 @@ -0,0 +1,1 @@ +{{- template "config.vim" -}}