Last active
June 7, 2024 14:49
-
-
Save shanzi/4604361 to your computer and use it in GitHub Desktop.
This configuration use vundle to arrange vim plugins
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
" install vundle first: | |
" git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim | |
set hidden | |
set nocompatible " do not compatible with vi | |
set backspace=indent,eol,start " allow backspace to delete char | |
set modeline | |
set shiftwidth=4 " set tab width to 4 space | |
set tabstop=4 | |
set expandtab | |
set softtabstop=4 | |
set laststatus=2 " always show status line | |
set t_Co=256 " use 256 color | |
set nu " show line number | |
set nowrap " stop line break | |
set colorcolumn=+1 | |
syntax on " show syntax with color | |
set completeopt=longest,menuone " disable docstring showing and show one item menu | |
filetype off | |
set backupdir=/tmp// | |
set directory=/tmp// | |
set scrolloff=5 | |
set fillchars+=vert:│ | |
set textwidth=100 | |
set signcolumn=yes | |
" install vim-plug first for nvim | |
" sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ | |
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | |
call plug#begin() | |
" my bundles here: | |
" +-- general plugins | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'kshenoy/vim-signature' | |
Plug 'kylechui/nvim-surround' | |
Plug 'phaazon/hop.nvim' | |
Plug 'AndrewRadev/splitjoin.vim' | |
Plug 'mg979/vim-visual-multi' | |
Plug 'roxma/nvim-yarp' | |
Plug 'roxma/vim-hug-neovim-rpc' | |
Plug 'lukas-reineke/indent-blankline.nvim' | |
Plug 'kyazdani42/nvim-web-devicons' | |
Plug 'kyazdani42/nvim-tree.lua' | |
Plug 'windwp/nvim-autopairs' | |
" +-- LSP | |
Plug 'williamboman/mason.nvim' | |
Plug 'williamboman/mason-lspconfig.nvim' | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'hrsh7th/cmp-buffer' | |
Plug 'hrsh7th/cmp-path' | |
Plug 'saadparwaiz1/cmp_luasnip' | |
Plug 'hrsh7th/cmp-nvim-lsp-signature-help' | |
Plug 'https://git.sr.ht/~whynothugo/lsp_lines.nvim' | |
Plug 'j-hui/fidget.nvim', {'tag': 'legacy'} | |
" +-- snips | |
Plug 'L3MON4D3/LuaSnip' | |
Plug 'rafamadriz/friendly-snippets' | |
" +-- Git | |
Plug 'tpope/vim-fugitive' | |
Plug 'lewis6991/gitsigns.nvim' | |
" +-- UI | |
Plug 'MunifTanjim/nui.nvim' | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'EdenEast/nightfox.nvim' | |
Plug 'onsails/lspkind-nvim' | |
Plug 'stevearc/dressing.nvim' | |
Plug 'folke/trouble.nvim' | |
Plug 'nvim-telescope/telescope.nvim' | |
Plug 'nvim-telescope/telescope-ui-select.nvim' | |
Plug 'folke/which-key.nvim' | |
" +-- languages plugins | |
" Plug 'derekwyatt/vim-scala' | |
Plug 'pangloss/vim-javascript' | |
Plug 'mattn/emmet-vim' | |
" +-- Rust | |
Plug 'rust-lang/rust.vim' | |
Plug 'mrcjkb/rustaceanvim' | |
Plug 'Saecki/crates.nvim' | |
" +-- AI | |
Plug 'Exafunction/codeium.nvim' | |
call plug#end() | |
filetype plugin indent on | |
" + configuration | |
" | |
" --+ vim-airline | |
let g:airline_powerline_fonts = 1 | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#show_buffers = 1 | |
let g:airline_theme = 'murmur' | |
let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}' | |
" --+ vim-rust | |
let g:rustfmt_autosave = 1 | |
" --+ Window resizer | |
let g:winresizer_start_key='' | |
let g:winresizer_gui_start_key='' | |
" --+ rainbow_parentheses | |
let g:rbpt_colorpairs = [ | |
\ ['red', 'firebrick3'], | |
\ ['darkred', 'DarkOrchid3'], | |
\ ['brown', 'RoyalBlue3'], | |
\ ['Darkblue', 'SeaGreen3'], | |
\ ['darkgreen', 'firebrick3'], | |
\ ['darkcyan', 'RoyalBlue3'], | |
\ ['darkred', 'SeaGreen3'], | |
\ ['darkmagenta', 'DarkOrchid3'], | |
\ ['brown', 'firebrick3'], | |
\ ['darkcyan', 'SeaGreen3'], | |
\ ['lightblue', 'lightblue'], | |
\ ['darkmagenta', 'DarkOrchid3'], | |
\ ['Darkblue', 'firebrick3'], | |
\ ['darkgreen', 'RoyalBlue3'], | |
\ ['gray', 'RoyalBlue3'], | |
\ ['darkgray', 'DarkOrchid3'], | |
\ ] | |
" --+ restore cursor position | |
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
" --+ tab setings | |
" autocmd FileType ruby,jade,html,htmldjango,javascript,stylus,less setlocal sw=2 sts=2 et | |
autocmd FileType proto,typescript,javascript,tsx,typescriptreact,scss,sass,java,html setlocal sw=2 sts=2 et | |
autocmd FileType cpp setlocal sw=4 noexpandtab | |
autocmd CmdwinEnter * map <ESC> :quit<CR> | |
" C-A to the start of linen | |
map <C-A> ^ | |
imap <C-A> <ESC>^i | |
" C-E to the end of line | |
map <C-E> $ | |
imap <C-E> <ESC>$a | |
" C-D to delete current | |
nmap <C-D> diw | |
imap <C-D> <ESC>ciw | |
imap <C-W> <ESC>ea | |
imap <C-B> <ESC>bi | |
imap <M-CR> <ESC>:ChatGPTCompleteCode<CR> | |
nmap gt :bn<CR> | |
nmap gT :bp<CR> | |
noremap <silent> <C-T> :NvimTreeFindFileToggle<CR> | |
nnoremap <silent> <C-G>b :Telescope buffers<CR> | |
nnoremap <silent> <C-G>c :Telescope commands<CR> | |
nnoremap <silent> <C-G><C-G> :Telescope find_files<CR> | |
nnoremap <silent> gi :Telescope lsp_implementations<CR> | |
nnoremap <silent> gr :Telescope lsp_references<CR> | |
nnoremap <silent> !! :TroubleLinesToggle<CR> | |
nnoremap <silent> <Leader><Leader>w <cmd>HopWordAC<CR> | |
nnoremap <silent> <Leader><Leader>b <cmd>HopWordBC<CR> | |
nnoremap <silent> <Leader><Leader>l <cmd>HopLine<CR> | |
nnoremap <silent> <Leader><Leader>s <cmd>HopLineStart<CR> | |
cabbrev nf NvimTreeFindFile | |
cabbrev wm WinResizerStartResize | |
lua <<EOF | |
-- themes | |
require('nvim-web-devicons').setup({default = true;}) | |
require('nightfox').setup { | |
options = { | |
transparent = true, | |
styles = { | |
comments = "italic", | |
keywords = "italic", | |
}, | |
inverse = { | |
match_paren = true, | |
}, | |
} | |
} | |
vim.cmd("colorscheme nightfox") | |
vim.cmd("highlight LspInlayHint cterm=NONE ctermfg=grey guifg=#445566 guibg=NONE") | |
-- nvim tree | |
require('nvim-tree').setup({ | |
view = { | |
adaptive_size = true, | |
}, | |
filters = { | |
dotfiles = true | |
}, | |
on_attach = function(bufnr) | |
local api = require('nvim-tree.api') | |
local function opts(desc) | |
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } | |
end | |
api.config.mappings.default_on_attach(bufnr) | |
vim.keymap.set('n', '<C-t>', api.tree.close, opts('Close')) | |
end | |
}) | |
-- gitsigns | |
require('gitsigns').setup({ | |
signs = { | |
add = { text = '▌' }, | |
change = { text = '▌' }, | |
delete = { text = '▌' }, | |
topdelete = { text = '▌' }, | |
changedelete = { text = '▌' }, | |
untracked = { text = '▌' }, | |
} | |
}) | |
-- codeium.nvim | |
require("codeium").setup() | |
-- mason | |
require("mason").setup() | |
require("mason-lspconfig").setup({ ensure_installed = { "rust_analyzer", "taplo", "pylsp", "tsserver" } }) | |
-- neovim-lspconfig | |
-- Mappings. | |
-- See `:help vim.diagnostic.*` for documentation on any of the below functions | |
local opts = { noremap=true, silent=true } | |
-- vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | |
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | |
vim.api.nvim_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
vim.api.nvim_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
vim.api.nvim_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
vim.api.nvim_set_keymap('n', 'rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '<M-CR>', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '<C-k>', '<cmd>lua vim.diagnostic.open_float()<CR>', opts) | |
local luasnip = require("luasnip") | |
local lspkind = require('lspkind') | |
local cmp = require('cmp') | |
cmp.setup { | |
formatting = { | |
format = lspkind.cmp_format({ | |
mode = 'symbol', | |
maxwidth = 50, | |
ellipsis_char = '...', | |
symbol_map = { | |
Codeium = "", | |
} | |
}), | |
}, | |
snippet = { | |
expand = function(args) | |
require("luasnip").lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
['<CR>'] = cmp.mapping(function(fallback) | |
if cmp.get_selected_entry() then | |
cmp.confirm() | |
elseif cmp.visible() then | |
cmp.close() | |
else | |
fallback() | |
end | |
end), | |
['<Tab>'] = cmp.mapping(function(fallback) | |
if luasnip.jumpable(1) then | |
luasnip.jump(1) | |
else | |
fallback() | |
end | |
end, {'i',}), | |
}, | |
sources = cmp.config.sources({ | |
{ name = 'codeium' }, | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, -- For luasnip users. | |
{ name = 'nvim_lsp_signature_help' }, | |
}, { | |
{ name = 'buffer' }, | |
}), | |
} | |
vim.api.nvim_create_autocmd("BufRead", { | |
group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), | |
pattern = "Cargo.toml", | |
callback = function() | |
vim.api.nvim_set_keymap('n', 'K', '<cmd>lua require(\'crates\').show_popup()<CR>', opts) | |
cmp.setup.buffer({ sources = { { name = "crates" } } }) | |
end, | |
}) | |
-- lsp servers | |
require("lspconfig").taplo.setup {} | |
require("lspconfig").pylsp.setup {} | |
require("lspconfig").tsserver.setup {} | |
vim.g.rustaceanvim = { | |
tools = {}, | |
server = { | |
on_attach = function(client, bufnr) | |
vim.lsp.inlay_hint.enable() | |
end, | |
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), | |
settings = { | |
["rust-analyzer"] = { | |
checkOnSave = { | |
command = "clippy" | |
}, | |
procMacro = { | |
enable = true | |
} | |
} | |
} | |
} | |
}; | |
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } | |
for type, icon in pairs(signs) do | |
local hl = "DiagnosticSign" .. type | |
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) | |
end | |
vim.g.trouble_lines_enabled = false | |
function set_trouble_lines(enabled) | |
vim.diagnostic.config { | |
virtual_text = not enabled, | |
virtual_lines = enabled, | |
} | |
end | |
set_trouble_lines(vim.g.trouble_lines_enabled) | |
vim.api.nvim_create_user_command( | |
'TroubleLinesToggle', | |
function(opts) | |
vim.g.trouble_lines_enabled = not vim.g.trouble_lines_enabled | |
set_trouble_lines(vim.g.trouble_lines_enabled) | |
end, | |
{ nargs = 0 } | |
) | |
-- luasnips | |
require("luasnip.loaders.from_vscode").lazy_load() | |
-- telescope | |
require("telescope").setup { | |
extensions = { | |
["ui-select"] = { | |
require("telescope.themes").get_dropdown {} | |
} | |
} | |
} | |
require("telescope").load_extension("ui-select") | |
-- which-key | |
local wk = require("which-key") | |
-- miscs | |
require("nvim-autopairs").setup() | |
require("trouble").setup() | |
require("hop").setup() | |
require('dressing').setup() | |
require('crates').setup() | |
require("nvim-surround").setup() | |
require("lsp_lines").setup() | |
require("fidget").setup() | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment