Skip to content

Instantly share code, notes, and snippets.

@rapando
Last active November 7, 2024 11:36
Show Gist options
  • Select an option

  • Save rapando/10c25397fe58eacf18736e072886d0bb to your computer and use it in GitHub Desktop.

Select an option

Save rapando/10c25397fe58eacf18736e072886d0bb to your computer and use it in GitHub Desktop.
# ____ _ _____ _ _
# | _ \ ___ __ _ __| | |_ _| |__ (_)___
# | |_) / _ \/ _` |/ _` | | | | '_ \| / __|
# | _ < __/ (_| | (_| | | | | | | | \__ \
# |_| \_\___|\__,_|\__,_| |_| |_| |_|_|___/
# Extra:
brew install neovim fd ripgrep lua luarocks fzf
call plug#begin('~/.config/nvim/plugged')
" Split mutliple files
Plug 'tpope/vim-projectionist'
" LSP and autocompletion
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'williamboman/nvim-lsp-installer'
" Nvim tree
Plug 'nvim-tree/nvim-tree.lua'
" Git
Plug 'kdheepak/lazygit.nvim'
" floating windows for cmds
Plug 'MunifTanjim/nui.nvim'
Plug 'rcarriga/nvim-notify'
Plug 'folke/noice.nvim'
" Go development
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'mfussenegger/nvim-lint'
" Rust Development
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'L3MON4D3/LuaSnip'
Plug 'simrat39/rust-tools.nvim'
Plug 'rust-lang/rust.vim'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'nvim-lua/plenary.nvim'
" Theme
Plug 'olimorris/onedarkpro.nvim'
Plug 'ellisonleao/gruvbox.nvim'
Plug 'scottmckendry/cyberdream.nvim'
Plug 'catppuccin/nvim', { 'as': 'catppuccin' }
" Autoclose brackets
Plug 'jiangmiao/auto-pairs'
" Global search in project
Plug 'nvim-lua/plenary.nvim' " Required dependency
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.8' }
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release' }
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Latex
Plug 'lervag/vimtex'
call plug#end()
" Enable LSP for Go
lua << EOF
local nvim_lsp = require'lspconfig'
nvim_lsp.gopls.setup {
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
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
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) -- Equivalent of Ctrl+Click
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) -- Function documentation
buf_set_keymap('n', '<C-k>', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts) -- Parameter info
buf_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<leader>wa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>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', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<Cmd>lua vim.lsp.buf.code_action()<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>so', [[<Cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]], opts)
vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
end,
flags = {
debounce_text_changes = 150,
}
}
EOF
" nvim-cmp setup
lua << EOF
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-b>'] = 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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<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 = 'luasnip' },
}, {
{ name = 'buffer' },
})
})
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline('?', {
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
require('lspconfig')['gopls'].setup {
capabilities = capabilities
}
EOF
" NVIM TREE STARTS
" Disable netrw (default file explorer) at the start
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" Configure nvim-tree
lua << EOF
require("nvim-tree").setup({
view = {
width = 30,
side = "left",
},
filters = {
dotfiles = false, -- Show hidden files
},
git = {
ignore = false,
},
renderer = {
icons = {
show = {
file = true,
folder = true,
folder_arrow = true,
},
},
},
})
EOF
" Keybinding to toggle nvim-tree
nnoremap <C-n> :NvimTreeToggle<CR>
" NVIM TREE END
" Theme settings
let g:onedark_config = {
\ 'style': 'darker',
\}
" ----theme
" colorscheme onedark_dark
" colorscheme onelight
" set background=dark " or light if you want light mode
" colorscheme gruvbox
colorscheme cyberdream
" colorscheme catppuccin-macchiato " catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha
" split screen behaviour
let g:projectionist_heuristics = {
\ "*": {
\ "*.js": { "alternate": "test/{}.spec.js", "type": "source" },
\ "test/*.spec.js": { "alternate": "src/{}.js", "type": "test" },
\ "*.py": { "alternate": "test_{}.py", "type": "source" },
\ "test_*.py": { "alternate": "{}.py", "type": "test" },
\ }
\}
" Customize the split behavior
autocmd BufReadPost,BufNewFile *.py :wincmd H
autocmd BufReadPost,BufNewFile *.js :wincmd L
" other settings
set tabstop=4
set mouse=a
set cursorline
set number
set shiftwidth=4
set expandtab
set guicursor=
set softtabstop=4
filetype plugin indent on
syntax enable
" use the system clipboard
set clipboard+=unnamedplus
" Go Linting
lua << EOF
require('lint').linters_by_ft = {
go = {'golangcilint'},
}
EOF
autocmd BufWritePost *.go lua require('lint').try_lint()
lua << EOF
require'lspconfig'.gopls.setup{}
EOF
" latex
let g:vimtex_view_method = 'zathura'
let g:vimtex_compiler_method = 'latexmk'
" let g:vimtex_view_general_viewer = 'open'
" let g:vimtex_view_general_options = ''
let g:vimtex_compiler_latexmk = {
\ 'build_dir' : '',
\ 'callback' : 1,
\ 'continuous' : 1,
\ 'executable' : 'latexmk',
\ 'options' : [
\ '-xelatex',
\ '-file-line-error',
\ '-interaction=nonstopmode',
\ '-synctex=1',
\ ],
\}
" fzf
set rtp+=/opt/homebrew/opt/fzf
" enable incremental search
set incsearch
" =====================
" Rust language server
" LSP settings for rust-analyzer
lua << EOF
local rt = require('rust-tools')
local null_ls = require("null-ls")
-- Setup rust-analyzer with rust-tools
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Enable keybindings for Rust tools
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-space>', '<Cmd>RustHoverActions<CR>', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>a', '<Cmd>RustCodeAction<CR>', { noremap = true, silent = true })
end,
},
})
-- Setup null-ls for diagnostics and code actions
null_ls.setup({
sources = {
-- Rust linting via Clippy
null_ls.builtins.diagnostics.clippy,
-- Code actions for refactoring, like removing unused imports
null_ls.builtins.code_actions.refactoring,
},
})
EOF
" map space to be the leader key
let mapleader = " "
" to global search do Leader+f
nnoremap <leader>f :Telescope live_grep<CR>
" Floating window configs
lua << EOF
require("noice").setup({
cmdline = {
enabled = true,
view = "cmdline_popup", -- Floating view for the command-line
},
popupmenu = {
enabled = true,
backend = "nui",
},
messages = {
enabled = true,
view = "mini", -- Optional: floating mini messages
},
lsp = {
progress = {enabled = true},
hover = {enabled = true},
signature = {enabled = true},
},
notify = {
enabled = true,
view = "notify",
},
presets = {
bottom_search = true, -- Bottom search
command_palette = true, -- Command palette view
},
})
EOF
" Git config, use <leader>gg
nnoremap <leader>gg :LazyGit<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment