current linux neovim config
this is my config on linux. It includes: - tmux/vim navigation shortcuts - venn diagram - markdown preview (not working?) not sure if this will work for macos. If not, I should create another branch with a working implementation.
This commit is contained in:
parent
f15af9b8be
commit
e4576e5c30
249
init.lua
249
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',
|
||||
|
@ -66,7 +67,14 @@ vim.opt.rtp:prepend(lazypath)
|
|||
-- as they will be available in your neovim runtime.
|
||||
require('lazy').setup({
|
||||
-- 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', '<leader>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 '<Ignore>'
|
||||
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 '<Ignore>'
|
||||
end, {expr=true, buffer = bufnr, desc = "Jump to previous hunk"})
|
||||
vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' })
|
||||
vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' })
|
||||
vim.keymap.set('n', '<leader>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 = "<C-h>",
|
||||
down = "<C-j>",
|
||||
up = "<C-k>",
|
||||
right = "<C-l>",
|
||||
last_active = "<C-\\>",
|
||||
next = "<C-Space>",
|
||||
}
|
||||
}
|
||||
|
||||
-- [[ Configure Telescope ]]
|
||||
-- See `:help telescope` and `:help telescope.setup()`
|
||||
require('telescope').setup {
|
||||
|
@ -317,15 +346,12 @@ vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc
|
|||
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
|
||||
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
|
||||
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
|
||||
vim.keymap.set('n', '<leader>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' },
|
||||
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,
|
||||
|
@ -386,7 +412,14 @@ vim.defer_fn(function()
|
|||
},
|
||||
},
|
||||
}
|
||||
end, 0)
|
||||
|
||||
-- Copy to clipboard
|
||||
-- vim.api.nvim_set_keymap('n', '<C-c>', '"+y', { noremap = true, silent = true })
|
||||
|
||||
-- Paste from clipboard
|
||||
-- this interferes with highlight
|
||||
-- I can use p instead
|
||||
-- vim.api.nvim_set_keymap('n', '<C-v>', '"+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('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
||||
nmap('<leader>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({
|
||||
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
|
||||
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
|
||||
['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
|
||||
['<leader>h'] = { name = 'More git', _ = 'which_key_ignore' },
|
||||
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
|
||||
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
|
||||
['<leader>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", "<C-v>j:VBox<CR>", {noremap = true})
|
||||
vim.api.nvim_buf_set_keymap(0, "n", "K", "<C-v>k:VBox<CR>", {noremap = true})
|
||||
vim.api.nvim_buf_set_keymap(0, "n", "L", "<C-v>l:VBox<CR>", {noremap = true})
|
||||
vim.api.nvim_buf_set_keymap(0, "n", "H", "<C-v>h:VBox<CR>", {noremap = true})
|
||||
-- draw a box by pressing "f" with visual selection
|
||||
vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<CR>", {noremap = true})
|
||||
else
|
||||
vim.cmd[[setlocal ve=]]
|
||||
vim.cmd[[mapclear <buffer>]]
|
||||
vim.b.venn_enabled = nil
|
||||
end
|
||||
end
|
||||
-- toggle keymappings for venn using <leader>v
|
||||
vim.api.nvim_set_keymap('n', '<leader>v', ":lua Toggle_venn()<CR>", { 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
|
||||
|
|
Loading…
Reference in New Issue