Last active
October 16, 2023 20:52
-
-
Save pluskid/2de23aea09470e985a33899ed154dc95 to your computer and use it in GitHub Desktop.
~/.config/nvim/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
"================================================================================ | |
" Setups | |
" 1. Install vim-plug | |
" 2. Run `:PlugInstall` in NeoVim | |
"================================================================================: | |
"================================================================================ | |
" Install Plugins | |
"================================================================================ | |
" Specify a directory for plugins | |
call plug#begin(stdpath('data') . '/plugged') | |
" Make sure you use single quotes | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'tami5/lspsaga.nvim' | |
Plug 'ray-x/lsp_signature.nvim' | |
Plug 'windwp/nvim-autopairs' | |
Plug 'simrat39/rust-tools.nvim' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'hrsh7th/cmp-path' | |
Plug 'hrsh7th/cmp-buffer' | |
Plug 'hrsh7th/cmp-cmdline' | |
Plug 'hrsh7th/cmp-vsnip' | |
Plug 'hrsh7th/vim-vsnip' | |
Plug 'nvim-lua/popup.nvim' | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'nvim-telescope/telescope.nvim' | |
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' } | |
Plug 'ggandor/lightspeed.nvim' | |
Plug 'nvim-lualine/lualine.nvim' | |
Plug 'kyazdani42/nvim-web-devicons' " need nerd-font patched fonts | |
Plug 'kyazdani42/nvim-tree.lua' | |
Plug 'folke/which-key.nvim' | |
Plug 'numToStr/Comment.nvim' | |
" Color Schemes | |
Plug 'folke/tokyonight.nvim' | |
Plug 'olimorris/onedarkpro.nvim' | |
Plug 'EdenEast/nightfox.nvim' | |
Plug 'sainnhe/everforest' | |
Plug 'catppuccin/nvim', {'as': 'catppuccin'} | |
Plug 'bluz71/vim-nightfly-guicolors' | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update | |
Plug 'lukas-reineke/indent-blankline.nvim' " Vertical lines for indentation | |
call plug#end() | |
"================================================================================ | |
" Basic Configurations | |
"================================================================================ | |
set visualbell " disable sound bell | |
set noshowmatch " do not jump to the matched bracket | |
set cursorline " highlight current line | |
set nu " line number | |
set mouse=a " enable mouse support | |
" Set completeopt to have a better completion experience | |
" :help completeopt | |
" menuone: popup even when there's only one match | |
" noinsert: Do not insert text until a selection is made | |
" noselect: Do not select, force user to select one from the menu | |
set completeopt=menuone,noinsert,noselect | |
" Color Schemes | |
if exists("g:neovide") || has("gui_vimr") | |
lua << END | |
-- Random Fonts | |
local font_list = {'CaskaydiaCove Nerd Font:h12', 'Migu 2M:h13', 'FiraCode Nerd Font:h12', | |
'Cartograph CF', 'Dank Mono'} | |
vim.opt.guifont = font_list[1 + os.time() % #font_list] | |
END | |
endif | |
colorscheme nightfox | |
" colorscheme tokyonight | |
" lua require('catppuccin').setup(); vim.cmd[[colorscheme catppuccin]] | |
let mapleader = "\<Space>" " space as the <leader> | |
set ignorecase " case insensitive search | |
set smartcase " case sensitive when typing capital letters | |
set shiftwidth=2 " indent is 2 spaces | |
set expandtab " expand tab into spaces | |
set tabstop=2 | |
set softtabstop=2 " let backspace delete indent | |
set scrolloff=8 " show this many lines of context while scrolling | |
" visual shifting (does not exit Visual mode) | |
vnoremap < <gv | |
vnoremap > >gv | |
" Find files using Telescope command-line sugar. | |
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>fs <cmd>Telescope lsp_document_symbols<cr> | |
nnoremap <leader>t <cmd>NvimTreeFindFile<cr> | |
" LSP key bindings | |
nnoremap <leader>gd <cmd>lua vim.lsp.buf.definition()<CR> | |
nnoremap <leader>gp <cmd>Lspsaga preview_definition<CR> | |
nnoremap <leader>ge <cmd>Lspsaga show_line_diagnostics<CR> | |
nnoremap <leader>gk <cmd>Lspsaga hover_doc<CR> | |
nnoremap <leader>gf <cmd>lua vim.lsp.buf.formatting()<CR> | |
nnoremap <leader>gn <cmd>Lspsaga rename<CR> | |
nnoremap <leader>ga <cmd>Lspsaga code_action<CR> | |
" have a fixed column for the diagnostics to appear in | |
" this removes the jitter when warnings/errors flow in | |
set signcolumn=yes | |
" Set updatetime for CursorHold | |
" 1000ms of no cursor movement to trigger CursorHold | |
"set updatetime=1000 | |
" Show diagnostic popup on cursor hold | |
"autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics() | |
" vim-vsnip Jump forward or backward | |
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
lua << END | |
require('lualine').setup({ | |
options = { icons_enabled = false, section_separators = '', component_separators = '' } | |
}) | |
require('nvim-tree').setup() | |
require('ibl').setup() | |
require('Comment').setup() | |
require('telescope').load_extension('fzf') | |
require('telescope').setup({ | |
pickers = { | |
buffers = { | |
ignore_current_buffer = true, | |
sort_mru = true, | |
}, | |
}, | |
}) | |
-- 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. | |
end, | |
}, | |
mapping = { | |
["<Tab>"] = cmp.mapping(function(fallback) | |
-- This little snippet will confirm with tab, and if no entry is selected, | |
-- will confirm the first item | |
if cmp.visible() then | |
local entry = cmp.get_selected_entry() | |
if not entry then | |
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) | |
end | |
cmp.confirm() | |
else | |
fallback() | |
end | |
end, {"i","s","c",}), | |
['<CR>'] = cmp.mapping.confirm({ select = false }), | |
}, | |
sources = cmp.config.sources({ | |
{ name = 'nvim_lsp' }, | |
}, { | |
{ 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' } | |
}) | |
}) | |
require('nvim-autopairs').setup({ | |
disable_filetype = { "TelescopePrompt" }, | |
}) | |
-- If you want insert `(` after select function or method item | |
local cmp_autopairs = require('nvim-autopairs.completion.cmp') | |
-- Smart CR from autopairs | |
cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) | |
-- Setup lspconfig. | |
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. | |
local capabilities = require('cmp_nvim_lsp').default_capabilities() | |
require('lspconfig')['rust_analyzer'].setup { | |
capabilities = capabilities, | |
settings = { | |
['rust-analyzer'] = { | |
checkOnSave = { | |
command = "clippy" | |
}, | |
}, | |
}, | |
} | |
require('nvim-treesitter.configs').setup { | |
ensure_installed = {"rust"}, | |
highlight = { enable = true }, | |
indent = { enable = false }, -- it seems this is not very compatible with autoindent for now | |
} | |
require('rust-tools').setup() | |
require('which-key').setup() | |
require('lsp_signature').setup() | |
require('lspsaga').setup() | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment