Skip to content

Instantly share code, notes, and snippets.

@pwang2
Last active August 5, 2024 18:26
Show Gist options
  • Save pwang2/d3c6cdf14d4495b5b34e36e4b4ebf537 to your computer and use it in GitHub Desktop.
Save pwang2/d3c6cdf14d4495b5b34e36e4b4ebf537 to your computer and use it in GitHub Desktop.
neovim init.lua
-- vm: ft=lua ts=2 sw=2 expandtab
vim.loader.enable()
local config_path = vim.fn.stdpath('config')
local gist_map_table = {
['33797ca5e8eec8c4ac32c79c05b9b499'] = 'init-prev.vim',
['72cbbb413ef272e29cf912d5a7de67ad'] = 'lua/nvim-tree-config.lua',
['5660dd151ecc9ae091e418d1e4239e2b'] = 'lua/startup-screen.lua',
['e1d1a276c4746fc034a2eb6bb2a594db'] = 'lua/nvim-cmp-config.lua',
['075c027cc334550046b75cc58ba44fb9'] = 'lua/nvim-lsp-config.lua'
}
local function gist(force)
for id, path in pairs(gist_map_table) do
local dest = config_path .. '/' .. path
if (force == false) and vim.fn.filereadable(dest) == 1 then
return
end
local url = "https://gist.github.com/pwang2/" .. id .. '/raw'
os.execute("curl -sSL --create-dirs -o " .. dest .. " " .. url)
end
end
--when open $MYVIMRC, gist sync all files in the gist_map_table
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
pattern = vim.fn.expand('$MYVIMRC'),
callback = function() gist(true) end,
group = vim.api.nvim_create_augroup('gist', { clear = true })
})
gist(false)
vim.cmd('source ' .. config_path .. '/init-prev.vim')
require 'Comment'.setup()
require 'mason'.setup {}
require 'startup-screen'
require "nvim-tree-config"
require "nvim-cmp-config"
require "nvim-lsp-config"
local trouble = require('trouble.sources.telescope')
local troublemaker = trouble.open
require 'nvim-web-devicons'.setup {}
require 'nvim-ts-autotag'.setup {}
require 'colorizer'.setup { '*' }
require 'bufferline'.setup {}
require 'lualine'.setup { options = { theme = 'onedark', globalstatus = true } }
require 'mini.indentscope'.setup { symbol = '│' }
require 'mini.cursorword'.setup { delay = 1000 }
require 'mini.bufremove'.setup {}
require 'mini.pairs'.setup {}
require 'gitsigns'.setup {
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, o)
o = o or {}
o.buffer = bufnr
vim.keymap.set(mode, l, r, o)
end
-- Navigation
map('n', ']c', function()
if vim.wo.diff then return ']c' end
vim.schedule(function() gs.next_hunk() end)
return '<Ignore>'
end, { expr = true })
map('n', '[c', function()
if vim.wo.diff then return '[c' end
vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>'
end, { expr = true })
-- Actions
map({ 'n', 'v' }, '<space>hs', ':Gitsigns stage_hunk<CR>')
map({ 'n', 'v' }, '<space>hr', ':Gitsigns reset_hunk<CR>')
map('n', '<space>hS', gs.stage_buffer)
map('n', '<space>hu', gs.undo_stage_hunk)
map('n', '<space>hR', gs.reset_buffer)
map('n', '<space>hp', gs.preview_hunk)
map('n', '<space>hb', function() gs.blame_line { full = true } end)
map('n', '<space>tb', gs.toggle_current_line_blame)
map('n', '<space>hd', gs.diffthis)
map('n', '<space>hD', function() gs.diffthis('~') end)
map('n', '<space>td', gs.toggle_deleted)
-- Text object
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end,
}
require 'trouble'.setup {
mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
}
if not vim.g.vscode then
require 'telescope'.setup {
defaults = {
mappings = {
i = { ['<leader>t'] = troublemaker },
n = { ['<leader>t'] = troublemaker },
},
},
pickers = {
find_files = {
hidden = true,
file_ignore_patterns = { '.git', 'node_modules' },
},
},
}
end
require 'nvim-treesitter.configs'.setup {
ensure_installed = {
"vue",
"lua",
"bash",
"todotxt",
"javascript",
"css",
"jsonc",
"typescript",
"html",
"yaml",
"rust",
},
indent = {
enable = true, disable = { "python", "c" },
},
highlight = {
enable = true,
disable = { "c" },
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<space>nn',
node_incremental = '<space>ni',
scope_incremental = '<space>si',
node_decremental = '<space>nd',
},
},
refactor = {
highlight_definitions = { enable = true, clear_on_cursor_move = true },
-- smart_rename = { enable = true, keymaps = { smart_rename = 'grr' } },
-- highlight_current_scope = { enable = true },
},
}
require('smartyank').setup {
highlight = {
enabled = true, -- highlight yanked text
higroup = "IncSearch", -- highlight group of yanked text
timeout = 200, -- timeout for clearing the highlight
},
clipboard = {
enabled = true
},
tmux = {
enabled = true,
-- remove `-w` to disable copy to host client's clipboard
cmd = { 'tmux', 'set-buffer', '-w' }
},
osc52 = {
enabled = true,
ssh_only = true, -- false to OSC52 yank also in local sessions
silent = false, -- true to disable the "n chars copied" echo
echo_hl = "Directory", -- highlight group of the OSC52 echo message
}
}
vim.api.nvim_set_keymap('n', '<leader>qt', ':%!quicktype -l ts --just-types --top-level Root<cr>',
{ noremap = true, silent = true })
-- firenvim_config
vim.g.firenvim_config = {
localSettings = {
["*"] = {
cmdline = "neovim",
content = "text",
priority = 0,
selector = "textarea",
takeover = "never"
}
}
}
if vim.g.started_by_firenvim == true then
vim.o.laststatus = 0
vim.o.showtabline = 0
require('cmp').setup { enabled = false }
end
-- GistID: d3c6cdf14d4495b5b34e36e4b4ebf537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment