-
-
Save sunliang711/fad86c3afada356737ad3293d1fc5600 to your computer and use it in GitHub Desktop.
Full Neovim init.vim
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-plug setup ---- | |
let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim') | |
if has('win32')&&!has('win64') | |
let curl_exists=expand('C:\Windows\Sysnative\curl.exe') | |
else | |
let curl_exists=expand('curl') | |
endif | |
if !filereadable(vimplug_exists) | |
if !executable(curl_exists) | |
echoerr "You have to install curl or first install vim-plug yourself!" | |
execute "q!" | |
endif | |
echo "Installing Vim-Plug..." | |
echo "" | |
silent exec "!"curl_exists" -fLo " . shellescape(vimplug_exists) . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" | |
let g:not_finish_vimplug = "yes" | |
autocmd VimEnter * PlugInstall | |
endif | |
"-------- end vim-plug setup ---- | |
set nocompatible | |
call plug#begin('~/.config/nvim/plugged') | |
" Sensible default | |
Plug 'tpope/vim-sensible' | |
" Color schemes | |
Plug 'sainnhe/edge' | |
" LSP | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'nvim-lua/completion-nvim' | |
" Code snippets | |
Plug 'SirVer/ultisnips' | |
Plug 'honza/vim-snippets' | |
" Fuzzy finder | |
Plug 'nvim-lua/popup.nvim' | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'nvim-telescope/telescope.nvim' | |
" Syntax | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} | |
Plug 'nvim-treesitter/playground' | |
" File explorer | |
Plug 'kyazdani42/nvim-web-devicons' " for file icons | |
Plug 'kyazdani42/nvim-tree.lua' | |
" Status line | |
Plug 'glepnir/galaxyline.nvim' | |
" Debugging | |
Plug 'nvim-telescope/telescope-dap.nvim' | |
Plug 'mfussenegger/nvim-dap' | |
Plug 'mfussenegger/nvim-dap-python' | |
" Github integration | |
Plug 'pwntester/octo.nvim' | |
call plug#end() | |
" Automatically install missing plugins on startup | |
autocmd VimEnter * | |
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | |
\| PlugInstall --sync | q | |
\| endif | |
if has('termguicolors') | |
set termguicolors | |
endif | |
let g:edge_style = 'aura' | |
let g:edge_enable_italic = 1 | |
let g:edge_disable_italic_comment = 1 | |
colorscheme edge | |
syntax enable | |
filetype plugin indent on | |
set nu rnu | |
set completeopt=menuone,noinsert,noselect | |
set shortmess+=c | |
set expandtab | |
set smartindent | |
set tabstop=4 softtabstop=4 | |
set cmdheight=2 | |
set updatetime=50 | |
set signcolumn=yes | |
set clipboard=unnamed,unnamedplus | |
augroup highlight_yank | |
autocmd! | |
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() | |
augroup END | |
nnoremap <Space>v :e ~/.config/nvim/init.exp2.vim<CR> | |
" -------------------- LSP --------------------------------- | |
:lua << EOF | |
local nvim_lsp = require('lspconfig') | |
local on_attach = function(client, bufnr) | |
require('completion').on_attach() | |
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 | |
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings | |
local opts = { noremap=true, silent=true } | |
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', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
buf_set_keymap('n', '<space>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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
-- Set some keybinds conditional on server capabilities | |
if client.resolved_capabilities.document_formatting then | |
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
elseif client.resolved_capabilities.document_range_formatting then | |
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
end | |
-- Set autocommands conditional on server_capabilities | |
if client.resolved_capabilities.document_highlight then | |
require('lspconfig').util.nvim_multiline_command [[ | |
:hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow | |
:hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow | |
:hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow | |
augroup lsp_document_highlight | |
autocmd! | |
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() | |
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() | |
augroup END | |
]] | |
end | |
end | |
local servers = {'pyright', 'gopls', 'rust_analyzer'} | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { | |
on_attach = on_attach, | |
} | |
end | |
EOF | |
" Completion | |
let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy'] | |
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
" -------------------- LSP --------------------------------- | |
" Code snippets | |
let g:completion_enable_snippet = 'UltiSnips' | |
" Fuzzy finder | |
nnoremap <leader>ff <cmd>Telescope find_files<cr> | |
nnoremap <leader>fg <cmd>Telescope live_grep<cr> | |
nnoremap <leader>fb <cmd>Telescope buffers<cr> | |
nnoremap <leader>fh <cmd>Telescope help_tags<cr> | |
nnoremap <leader>fl <cmd>Telescope git_files<cr> | |
" Syntax | |
lua <<EOF | |
require'nvim-treesitter.configs'.setup { | |
highlight = { | |
enable = true | |
}, | |
playground = { | |
enable = true, | |
disable = {}, | |
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code | |
persist_queries = false -- Whether the query persists across vim sessions | |
} | |
} | |
EOF | |
" File explorer | |
nnoremap <leader>tt :NvimTreeToggle<CR> | |
nnoremap <leader>tr :NvimTreeRefresh<CR> | |
nnoremap <leader>tn :NvimTreeFindFile<CR> | |
" NvimTreeOpen and NvimTreeClose are also available if you need them | |
" Status line | |
luafile ~/.config/nvim/eviline.lua | |
" Debugging | |
lua <<EOF | |
require('telescope').load_extension('dap') | |
require('dap-python').setup('~/miniconda3/bin/python') | |
EOF | |
nnoremap <silent> <F5> :lua require'dap'.continue()<CR> | |
nnoremap <silent> <leader>dd :lua require('dap').continue()<CR> | |
nnoremap <silent> <F10> :lua require'dap'.step_over()<CR> | |
nnoremap <silent> <F11> :lua require'dap'.step_into()<CR> | |
nnoremap <silent> <F12> :lua require'dap'.step_out()<CR> | |
nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR> | |
nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR> | |
nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR> | |
nnoremap <silent> <leader>dr :lua require'dap'.repl.open()<CR> | |
nnoremap <silent> <leader>dl :lua require'dap'.repl.run_last()<CR>` | |
nnoremap <silent> <leader>dn :lua require('dap-python').test_method()<CR> | |
vnoremap <silent> <leader>ds <ESC>:lua require('dap-python').debug_selection()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment