diff --git a/init.lua b/init.lua index e5bc576e..fe7f853d 100644 --- a/init.lua +++ b/init.lua @@ -47,6 +47,7 @@ vim.g.maplocalleader = ' ' -- https://github.com/folke/lazy.nvim -- `:help lazy.nvim.txt` for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +-- print(lazypath) if not vim.loop.fs_stat(lazypath) then vim.fn.system { 'git', @@ -65,8 +66,15 @@ vim.opt.rtp:prepend(lazypath) -- You can also configure plugins after the setup call, -- as they will be available in your neovim runtime. require('lazy').setup({ - -- NOTE: First, some plugins that don't require any configuration - + -- NOTE: First, some plugins that don't require any configuration + { + 'iamcco/markdown-preview.nvim', + cmd = 'MarkdownPreview' + }, + 'dhruvasagar/vim-table-mode', + 'jbyuki/venn.nvim', + 'preservim/nerdtree', + 'alexghergh/nvim-tmux-navigation', -- Git related plugins 'tpope/vim-fugitive', 'tpope/vim-rhubarb', @@ -124,20 +132,9 @@ require('lazy').setup({ changedelete = { text = '~' }, }, on_attach = function(bufnr) - vim.keymap.set('n', 'hp', require('gitsigns').preview_hunk, { buffer = bufnr, desc = 'Preview git hunk' }) - - -- don't override the built-in and fugitive keymaps - local gs = package.loaded.gitsigns - vim.keymap.set({'n', 'v'}, ']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) - return '' - end, {expr=true, buffer = bufnr, desc = "Jump to next hunk"}) - vim.keymap.set({'n', 'v'}, '[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) - return '' - end, {expr=true, buffer = bufnr, desc = "Jump to previous hunk"}) + vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) + vim.keymap.set('n', 'gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) + vim.keymap.set('n', 'ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) end, }, }, @@ -170,8 +167,10 @@ require('lazy').setup({ 'lukas-reineke/indent-blankline.nvim', -- Enable `lukas-reineke/indent-blankline.nvim` -- See `:help indent_blankline.txt` - main = "ibl", - opts = {}, + opts = { + char = '┊', + show_trailing_blankline_indent = false, + }, }, -- "gc" to comment visual regions/lines @@ -226,8 +225,26 @@ require('lazy').setup({ -- See `:help vim.o` -- NOTE: You can change these options as you wish! +-- Use spaces instead of tabs +vim.o.expandtab = true + +-- Number of spaces a tab counts for +vim.o.tabstop = 4 + +-- Number of spaces to use for auto-indent +vim.o.shiftwidth = 4 + +-- Disable backup files +vim.o.backup = false + +-- Disable swap files +vim.o.swapfile = false + +-- relative line numbering +vim.o.relativenumber = true + -- Set highlight on search -vim.o.hlsearch = false +vim.o.hlsearch = true -- Make line numbers default vim.wo.number = true @@ -284,6 +301,18 @@ vim.api.nvim_create_autocmd('TextYankPost', { pattern = '*', }) +require'nvim-tmux-navigation'.setup { + disable_when_zoomed = true, -- defaults to false + keybindings = { + left = "", + down = "", + up = "", + right = "", + last_active = "", + next = "", + } +} + -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { @@ -317,76 +346,80 @@ vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` --- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' -vim.defer_fn(function() - require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' }, - - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = false, - - highlight = { enable = true }, - indent = { enable = true }, - incremental_selection = { +require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim', 'haskell' }, + + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, + + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + textobjects = { + select = { enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', + -- You can use the capture groups defined in textobjects.scm + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', }, }, - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', }, }, - } -end, 0) + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, + }, +} + +-- Copy to clipboard +-- vim.api.nvim_set_keymap('n', '', '"+y', { noremap = true, silent = true }) + +-- Paste from clipboard +-- this interferes with highlight +-- I can use p instead +-- vim.api.nvim_set_keymap('n', '', '"+p', { noremap = true, silent = true }) -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) @@ -416,7 +449,7 @@ local on_attach = function(_, bufnr) nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') @@ -439,17 +472,6 @@ local on_attach = function(_, bufnr) end, { desc = 'Format current buffer with LSP' }) end --- document existing key chains -require('which-key').register({ - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, - ['h'] = { name = 'More git', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, -}) - -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- @@ -547,5 +569,162 @@ cmp.setup { }, } +-- jbyuki/venn.nvim configuration: enable or disable keymappings +function _G.Toggle_venn() + local venn_enabled = vim.inspect(vim.b.venn_enabled) + if venn_enabled == "nil" then + vim.b.venn_enabled = true + vim.cmd[[setlocal ve=all]] + -- draw a line on HJKL keystokes + vim.api.nvim_buf_set_keymap(0, "n", "J", "j:VBox", {noremap = true}) + vim.api.nvim_buf_set_keymap(0, "n", "K", "k:VBox", {noremap = true}) + vim.api.nvim_buf_set_keymap(0, "n", "L", "l:VBox", {noremap = true}) + vim.api.nvim_buf_set_keymap(0, "n", "H", "h:VBox", {noremap = true}) + -- draw a box by pressing "f" with visual selection + vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox", {noremap = true}) + else + vim.cmd[[setlocal ve=]] + vim.cmd[[mapclear ]] + vim.b.venn_enabled = nil + end +end +-- toggle keymappings for venn using v +vim.api.nvim_set_keymap('n', 'v', ":lua Toggle_venn()", { noremap = true}) + +-- markdown preview config + +vim.cmd [[ +" set to 1, nvim will open the preview window after entering the markdown buffer +" default: 0 +let g:mkdp_auto_start = 0 + +" set to 1, the nvim will auto close current preview window when change +" from markdown buffer to another buffer +" default: 1 +let g:mkdp_auto_close = 1 + +" set to 1, the vim will refresh markdown when save the buffer or +" leave from insert mode, default 0 is auto refresh markdown as you edit or +" move the cursor +" default: 0 +let g:mkdp_refresh_slow = 0 + +" set to 1, the MarkdownPreview command can be use for all files, +" by default it can be use in markdown file +" default: 0 +let g:mkdp_command_for_global = 0 + +" set to 1, preview server available to others in your network +" by default, the server listens on localhost (127.0.0.1) +" default: 0 +let g:mkdp_open_to_the_world = 0 + +" use custom IP to open preview page +" useful when you work in remote vim and preview on local browser +" more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9 +" default empty +let g:mkdp_open_ip = '' + +" specify browser to open preview page +" for path with space +" valid: `/path/with\ space/xxx` +" invalid: `/path/with\\ space/xxx` +" default: '' +let g:mkdp_browser = '' + +" set to 1, echo preview page url in command line when open preview page +" default is 0 +let g:mkdp_echo_preview_url = 0 + +" a custom vim function name to open preview page +" this function will receive url as param +" default is empty +let g:mkdp_browserfunc = '' + +" options for markdown render +" mkit: markdown-it options for render +" katex: katex options for math +" uml: markdown-it-plantuml options +" maid: mermaid options +" disable_sync_scroll: if disable sync scroll, default 0 +" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle' +" middle: mean the cursor position alway show at the middle of the preview page +" top: mean the vim top viewport alway show at the top of the preview page +" relative: mean the cursor position alway show at the relative positon of the preview page +" hide_yaml_meta: if hide yaml metadata, default is 1 +" sequence_diagrams: js-sequence-diagrams options +" content_editable: if enable content editable for preview page, default: v:false +" disable_filename: if disable filename header for preview page, default: 0 +let g:mkdp_preview_options = { + \ 'mkit': {}, + \ 'katex': {}, + \ 'uml': {}, + \ 'maid': {}, + \ 'disable_sync_scroll': 0, + \ 'sync_scroll_type': 'middle', + \ 'hide_yaml_meta': 1, + \ 'sequence_diagrams': {}, + \ 'flowchart_diagrams': {}, + \ 'content_editable': v:false, + \ 'disable_filename': 0, + \ 'toc': {} + \ } + +" use a custom markdown style must be absolute path +" like '/Users/username/markdown.css' or expand('~/markdown.css') +let g:mkdp_markdown_css = '' + +" use a custom highlight style must absolute path +" like '/Users/username/highlight.css' or expand('~/highlight.css') +let g:mkdp_highlight_css = '' + +" use a custom port to start server or empty for random +let g:mkdp_port = '' + +" preview page title +" ${name} will be replace with the file name +let g:mkdp_page_title = '「${name}」' + +" recognized filetypes +" these filetypes will have MarkdownPreview... commands +let g:mkdp_filetypes = ['markdown'] + +" set default theme (dark or light) +" By default the theme is define according to the preferences of the system +let g:mkdp_theme = 'dark' +]] +-- Setting global variables in Lua for Neovim +-- vim.g.mkdp_auto_start = 0 +-- vim.g.mkdp_auto_close = 1 +-- vim.g.mkdp_refresh_slow = 0 +-- vim.g.mkdp_command_for_global = 0 +-- vim.g.mkdp_open_to_the_world = 0 +-- vim.g.mkdp_open_ip = '' +-- vim.g.mkdp_browser = '' +-- vim.g.mkdp_echo_preview_url = 0 +-- vim.g.mkdp_browserfunc = '' +-- vim.g.mkdp_port = '' +-- vim.g.mkdp_page_title = '「${name}」' +-- vim.g.mkdp_filetypes = {'markdown'} +-- vim.g.mkdp_theme = 'dark' +-- +-- vim.g.mkdp_preview_options = { +-- mkit = {}, +-- katex = {}, +-- uml = {}, +-- maid = {}, +-- disable_sync_scroll = 0, +-- sync_scroll_type = 'middle', +-- hide_yaml_meta = 1, +-- sequence_diagrams = {}, +-- flowchart_diagrams = {}, +-- content_editable = false, +-- disable_filename = 0, +-- toc = {} +-- } +-- +-- vim.g.mkdp_markdown_css = '' +-- vim.g.mkdp_highlight_css = '' + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et