Last active
November 30, 2021 07:13
-
-
Save lessmost/ed4d8a69e8b566e903b5a07760a896b5 to your computer and use it in GitHub Desktop.
neovim config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- vim: set ts=2 sw=2 tw=2 et : | |
-- vim api helper | |
local helper = {} | |
helper.map = function(mode, lhs, rhs, opts) | |
local options = {noremap = true, silent = true} | |
if opts then | |
options = vim.tbl_extend("force", options, opts) | |
end | |
vim.api.nvim_set_keymap(mode, lhs, rhs, options) | |
end | |
helper.bufMap = function(buf, mode, lhs, rhs, opts) | |
local options = {noremap = true, silent = true} | |
if opts then | |
options = vim.tbl_extend("force", options, opts) | |
end | |
vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options) | |
end | |
helper.autocmd = function(event, triggers, operations) | |
local cmd = string.format("autocmd %s %s %s", event, triggers, operations) | |
vim.cmd(cmd) | |
end | |
-- map <leader> to <space> | |
vim.g.mapleader = " " | |
vim.g.override_nvim_web_devicons = true | |
vim.g.material_style = "deep ocean" | |
vim.g.neoformat_try_node_exe = 1 | |
vim.g.clipboard = { | |
name = "macOS-clipboard", | |
copy = {["+"] = "pbcopy", ["*"] = "pbcopy"}, | |
paste = {["+"] = "pbpaste", ["*"] = "pbpaste"}, | |
cache_enabled = false | |
} | |
-- vim options | |
vim.o.termguicolors = true | |
vim.o.showcmd = true | |
vim.o.clipboard = "unnamedplus" | |
vim.o.mouse = "a" | |
vim.o.modeline = true | |
vim.o.number = true | |
vim.o.relativenumber = true | |
vim.o.list = true | |
vim.o.listchars = "tab:>-,trail:.,extends:#" | |
vim.o.completeopt = "menu,menuone,noselect" | |
vim.o.foldmethod = "expr" | |
vim.o.foldexpr = "nvim_treesitter#foldexpr()" | |
vim.o.foldlevel = 99 | |
-- theme | |
require("material").setup({}) | |
vim.cmd("colorscheme dracula") | |
-- vim.cmd("colorscheme github_dark"); | |
-- let vim jump to the last position when reopening a file. | |
helper.autocmd("BufReadPost", "*", [[if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]]) | |
-- reset folding after telescope open files | |
-- helper.autocmd("BufReadPost", "*.js,*.jsx,*.ts,*.tsx,*.json", [[exe ":normal! xz"]]) | |
-- auto format with Neoforma | |
vim.cmd( | |
[[ | |
augroup fmt | |
autocmd! | |
autocmd BufWritePre *.lua,*.js,*.jsx,*.ts,*.tsx,*.json,*.css,*.less,*.r undojoin | Neoformat | |
augroup END | |
]] | |
) | |
helper.map("n", "<leader>,", ":edit $MYVIMRC<CR>") | |
helper.map("n", "<leader>w", ":update<CR>") | |
helper.map("n", "<leader>cc", ":noh <bar> cclose <bar> lclose<CR>") | |
helper.map("n", "<A-j>", ":m .+1<CR>==") | |
helper.map("n", "<A-k>", ":m .-2<CR>==") | |
helper.map("i", "<A-j>", "<ESC>:m .+1<CR>==gi") | |
helper.map("i", "<A-k>", "<ESC>:m .-2<CR>==gi") | |
helper.map("v", "<A-j>", ":m '>+1<CR>gv=gv") | |
helper.map("v", "<A-k>", ":m '<-2<CR>gv=gv") | |
-- neorg | |
-- require("neorg").setup( | |
-- { | |
-- load = { | |
-- ["core.defaults"] = {}, -- Load all the default modules | |
-- ["core.norg.concealer"] = {} -- Allow for use of icons | |
-- } | |
-- } | |
-- ) | |
-- nvim-web-devicons | |
require("nvim-web-devicons").setup( | |
{ | |
default = true | |
} | |
) | |
-- lualine | |
require("lualine").setup({}) | |
-- bufferline | |
helper.map("n", "<leader>b]", ":BufferLineCycleNext<CR>") | |
helper.map("n", "<leader>b[", ":BufferLineCyclePrev<CR>") | |
helper.map("n", "<leader>bj", ":BufferLineCycleNext<CR>") | |
helper.map("n", "<leader>bk", ":BufferLineCyclePrev<CR>") | |
helper.map("n", "<leader>]b", ":BufferLineMoveNext<CR>") | |
helper.map("n", "<leader>[b", ":BufferLineMovePrev<CR>") | |
helper.map("n", "<leader>bx", ":bd<CR>") | |
helper.map("n", "<leader>blx", ":BufferLineCloseLeft<CR>") | |
helper.map("n", "<leader>brx", ":BufferLineCloseRight<CR>") | |
for i = 1, 9 do | |
helper.map("n", "<leader>" .. i, ":BufferLineGoToBuffer " .. i .. "<CR>") | |
end | |
require("bufferline").setup( | |
{ | |
options = { | |
numbers = "ordinal" | |
} | |
} | |
) | |
-- todo-comments | |
require("todo-comments").setup({}) | |
-- harpoon | |
-- require("harpoon").setup({}) | |
-- nvim-tree | |
vim.cmd([[ | |
let g:nvim_tree_icons = { | |
\ 'default': '' | |
\ } | |
]]) | |
helper.map("n", "<leader>n", ":NvimTreeToggle<CR>") | |
helper.map("n", "<leader>r", ":NvimTreeRefresh<CR>") | |
-- helper.map("n", "<leader>n", ":NvimTreeFindFile<CR>") | |
require("nvim-tree").setup( | |
{ | |
update_focused_file = { | |
enable = true | |
} | |
} | |
) | |
-- nvim-treesitter | |
require("nvim-treesitter.install").command_extra_args = { | |
curl = {"--proxy", "socks5://127.0.0.1:1086"} | |
} | |
require("nvim-treesitter.configs").setup( | |
{ | |
context_commentstring = {enable = true}, | |
highlight = { | |
enable = true, | |
use_languagetree = true | |
}, | |
indent = { | |
enable = true | |
} | |
} | |
) | |
require("nvim-treesitter.parsers").get_parser_configs().norg = { | |
install_info = { | |
url = "https://github.com/nvim-neorg/tree-sitter-norg", | |
files = {"src/parser.c", "src/scanner.cc"}, | |
branch = "main" | |
} | |
} | |
-- telescope | |
helper.map("n", "<leader>ff", ":Telescope find_files<CR>") | |
helper.map("n", "<leader>fg", ":Telescope live_grep<CR>") | |
helper.map("n", "<leader>fs", ":Telescope grep_string<CR>") | |
helper.map("n", "<leader>fb", ":Telescope buffers<CR>") | |
helper.map("n", "<leader>ft", ":Telescope lsp_document_symbols<CR>") | |
helper.map("n", "<leader>fr", ":Telescope lsp_workspace_symbols<CR>") | |
-- lspconfig & nvim-lsp-installer | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local on_attach = function(client, bufnr) | |
local function buf_set_keymap(...) | |
vim.api.nvim_buf_set_keymap(bufnr, ...) | |
end | |
local function buf_set_option(...) | |
vim.api.nvim_buf_set_option(bufnr, ...) | |
end | |
-- Enable completion triggered by <c-x><c-o> | |
-- buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings. | |
local opts = {noremap = true, silent = true} | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) | |
buf_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) | |
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) | |
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) | |
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) | |
-- buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts) | |
-- buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts) | |
-- buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts) | |
buf_set_keymap("n", "<leader>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts) | |
buf_set_keymap("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) | |
buf_set_keymap("n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts) | |
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) | |
buf_set_keymap("n", "<leader>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts) | |
buf_set_keymap("n", "d[", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) | |
buf_set_keymap("n", "d]", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) | |
buf_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts) | |
-- buf_set_keymap("n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
-- helper.autocmd("CursorHold", "<buffer>", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>") | |
buf_set_keymap("n", "<leader>gs", ":TSLspOrganize<CR>", opts) | |
buf_set_keymap("n", "<leader>gr", ":TSLspRenameFile<CR>", opts) | |
buf_set_keymap("n", "<leader>gi", ":TSLspImportAll<CR>", opts) | |
-- additional | |
require("lsp_signature").on_attach() | |
end | |
local lsp_installer = require("nvim-lsp-installer") | |
-- Provide settings first! | |
lsp_installer.settings( | |
{ | |
ui = { | |
icons = { | |
server_installed = "✓", | |
server_pending = "➜", | |
server_uninstalled = "✗" | |
} | |
} | |
} | |
) | |
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) | |
-- Register a handler that will be called for all installed servers. | |
-- Alternatively, you may also register handlers on specific server instances instead (see example below). | |
lsp_installer.on_server_ready( | |
function(server) | |
local opts = { | |
on_attach = on_attach, | |
capabilities = capabilities, | |
flags = { | |
debounce_text_changes = 250 | |
} | |
} | |
-- (optional) Customize the options passed to the server | |
-- if server.name == "tsserver" then | |
-- opts.root_dir = function() ... end | |
-- end | |
if server.name == "sumneko_lua" then | |
opts.settings = { | |
Lua = { | |
diagnostics = {globals = {"vim"}} | |
} | |
} | |
end | |
if server.name == "jsonls" then | |
opts.settings = { | |
json = { | |
schemas = require("schemastore").json.schemas() | |
} | |
} | |
end | |
if server.name == "tsserver" then | |
opts.on_attach = function(client, bufnr) | |
on_attach(client, bufnr) | |
local ts_utils = require("nvim-lsp-ts-utils") | |
ts_utils.setup({}) | |
ts_utils.setup_client(client) | |
end | |
end | |
-- This setup() function is exactly the same as lspconfig's setup function. | |
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md | |
server:setup(opts) | |
end | |
) | |
-- nvim-cmp | |
-- Setup nvim-cmp. | |
local cmp = require("cmp") | |
cmp.setup( | |
{ | |
snippet = { | |
-- REQUIRED - you must specify a snippet engine | |
expand = function(args) | |
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. | |
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. | |
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. | |
-- require'snippy'.expand_snippet(args.body) -- For `snippy` users. | |
end | |
}, | |
mapping = { | |
["<C-n>"] = cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Insert}), | |
["<C-p>"] = cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Insert}), | |
["<Down>"] = cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), | |
["<Up>"] = cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), | |
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), {"i", "c"}), | |
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), {"i", "c"}), | |
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), {"i", "c"}), | |
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping. | |
["<C-e>"] = cmp.mapping( | |
{ | |
i = cmp.mapping.abort(), | |
c = cmp.mapping.close() | |
} | |
), | |
["<CR>"] = cmp.mapping.confirm({select = true}), | |
["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), {"i", "s"}), | |
["<S-Tab>"] = cmp.mapping(cmp.mapping.select_prev_item(), {"i", "s"}) | |
}, | |
sources = cmp.config.sources( | |
{ | |
{name = "nvim_lsp"}, | |
{name = "vsnip"} -- For vsnip users. | |
-- { name = 'luasnip' }, -- For luasnip users. | |
-- { name = 'ultisnips' }, -- For ultisnips users. | |
-- { name = 'snippy' }, -- For snippy users. | |
}, | |
{ | |
{name = "buffer"} | |
} | |
) | |
} | |
) | |
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline( | |
"/", | |
{ | |
sources = { | |
{name = "buffer"} | |
} | |
} | |
) | |
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline( | |
":", | |
{ | |
sources = cmp.config.sources( | |
{ | |
{name = "path"} | |
}, | |
{ | |
{name = "cmdline"} | |
} | |
) | |
} | |
) | |
-- rust-toolts | |
require("rust-tools").setup({}) | |
-- diffview | |
require("diffview").setup({}) | |
-- lazygit | |
helper.map("n", "<leader>lg", ":LazyGit<CR>") | |
-- marks | |
require("marks").setup( | |
{ | |
default_mappings = true, | |
mappings = { | |
toggle = "mm" | |
} | |
} | |
) | |
-- indent | |
require("indent_blankline").setup( | |
{ | |
char = "¦" | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" vim: set ts=2 sw=2 tw=2 et : | |
call plug#begin(stdpath('data') . '/plugged') | |
" icon & theme | |
Plug 'kyazdani42/nvim-web-devicons' | |
Plug 'dracula/vim', { 'as': 'dracula' } | |
Plug 'arzg/vim-colors-xcode' | |
Plug 'tomasiser/vim-code-dark' | |
Plug 'bluz71/vim-nightfly-guicolors' | |
Plug 'projekt0n/github-nvim-theme' | |
Plug 'mhartington/oceanic-next' | |
Plug 'marko-cerovac/material.nvim' | |
" general | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'nvim-lua/popup.nvim' | |
Plug 'tpope/vim-surround' | |
Plug 'godlygeek/tabular' | |
Plug 'plasticboy/vim-markdown' | |
Plug 'editorconfig/editorconfig-vim' | |
Plug 'lukas-reineke/indent-blankline.nvim' | |
" Plug 'nvim-neorg/neorg' | |
" tab/buffer/aireline | |
" Plug 'vim-airline/vim-airline' | |
Plug 'akinsho/bufferline.nvim' | |
Plug 'nvim-lualine/lualine.nvim' | |
" file manager | |
Plug 'kyazdani42/nvim-tree.lua' | |
Plug 'nvim-telescope/telescope.nvim' | |
Plug 'kyazdani42/nvim-tree.lua' | |
" Plug 'ThePrimeagen/harpoon' | |
" comment | |
Plug 'tpope/vim-commentary' | |
Plug 'folke/todo-comments.nvim' | |
" lsp | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'williamboman/nvim-lsp-installer' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'hrsh7th/cmp-buffer' | |
Plug 'hrsh7th/cmp-path' | |
Plug 'hrsh7th/cmp-cmdline' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-vsnip' | |
Plug 'hrsh7th/vim-vsnip' | |
Plug 'rafamadriz/friendly-snippets' | |
Plug 'simrat39/symbols-outline.nvim' | |
" Plug 'nvim-lua/lsp-status.nvim' | |
Plug 'simrat39/rust-tools.nvim' | |
Plug 'b0o/schemastore.nvim' | |
Plug 'ray-x/lsp_signature.nvim' | |
Plug 'jose-elias-alvarez/nvim-lsp-ts-utils' | |
" formatting | |
Plug 'sbdchd/neoformat' | |
Plug 'tpope/vim-fugitive' | |
Plug 'sindrets/diffview.nvim' | |
Plug 'kdheepak/lazygit.nvim' | |
" rust | |
Plug 'rust-lang/rust.vim' | |
" frontend | |
Plug 'yuezk/vim-js' | |
Plug 'HerringtonDarkholme/yats.vim' | |
Plug 'maxmellon/vim-jsx-pretty' | |
Plug 'ap/vim-css-color' | |
" Plug 'jremmen/vim-ripgrep' | |
" marks | |
Plug 'chentau/marks.nvim' | |
call plug#end() | |
" lua entry | |
lua << EOF | |
require("init") | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment