Skip to content

Instantly share code, notes, and snippets.

@rtt63
Last active December 22, 2024 20:39
Show Gist options
  • Save rtt63/04fe3ddcfc6ca257c77c8be16cdd7dac to your computer and use it in GitHub Desktop.
Save rtt63/04fe3ddcfc6ca257c77c8be16cdd7dac to your computer and use it in GitHub Desktop.
Initial vim config (lua & vimplug)
-- GUI Cursor
vim.o.guicursor = 'n-v-c-i:block'
-- Line Numbers
vim.wo.number = true vim.wo.relativenumber = true
-- <vleader> key
vim.g.mapleader = "\\"
-- Mouse Support
vim.o.mouse = 'a'
-- Autoindent
vim.o.autoindent = true
-- Tab Setting
vim.o.tabstop = 2
vim.o.shiftwidth = 2
vim.o.smarttab = true
vim.o.softtabstop = 2
vim.o.expandtab = true
-- Background
vim.o.background = 'dark'
-- Having offtop when pressing z + enter from the bottom of the screen
vim.o.scrolloff = 4
-- Plugins
vim.cmd [[call plug#begin()]]
vim.cmd [[Plug 'https://github.com/preservim/nerdtree']]
vim.cmd [[Plug 'neoclide/coc.nvim', {'branch': 'release'}]]
vim.cmd [[Plug 'https://github.com/bluz71/vim-moonfly-colors']]
vim.cmd [[Plug 'https://github.com/nvim-telescope/telescope.nvim']]
vim.cmd [[Plug 'nvim-lua/plenary.nvim']] -- required by telescope, checkhealth 'plenary not found ERROR'
vim.cmd [[Plug 'rust-lang/rust.vim']]
vim.cmd [[Plug 'neovim/nvim-lspconfig']]
vim.cmd [[Plug 'jose-elias-alvarez/null-ls.nvim']]
-- vim.cmd [[Plug 'prettier/vim-prettier', { 'do': 'yarn install' }]]
vim.cmd [[Plug 'https://github.com/tpope/vim-commentary']] -- For Commenting gcc & gc
vim.cmd [[Plug 'kabouzeid/nvim-lspinstall']]
-- eslint
vim.cmd [[Plug 'jose-elias-alvarez/null-ls.nvim']]
vim.cmd [[Plug 'MunifTanjim/eslint.nvim']]
vim.cmd [[Plug 'nvim-lualine/lualine.nvim']]
vim.cmd [[Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}]]
-- If you want to have icons in your statusline choose one of these
vim.cmd [[Plug 'nvim-tree/nvim-web-devicons']]
vim.cmd [[Plug 'm4xshen/autoclose.nvim']]
vim.cmd [[Plug 'williamboman/mason-lspconfig.nvim']]
vim.cmd [[Plug 'williamboman/mason.nvim']]
vim.cmd [[Plug 'sondrele/rust-src']] -- Rust autocompletion
vim.cmd [[Plug 'tpope/vim-fugitive']]
vim.cmd [[Plug 'lewis6991/gitsigns.nvim']]
vim.cmd [[Plug 'sindrets/diffview.nvim']]
vim.cmd [[call plug#end()]]
vim.api.nvim_create_user_command('Prettier', function()
vim.fn.CocAction('runCommand', 'prettier.formatFile')
end, {})
-- NERDTree Keybindings
vim.api.nvim_set_keymap('n', '<C-f>', ':NERDTreeFocus<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-n>', ':NERDTree<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-t>', ':NERDTreeToggle<CR>', { noremap = true, silent = true })
-- Telescope Keybinding
vim.api.nvim_set_keymap('n', '<C-q>', ':Telescope<CR>', { noremap = true, silent = true })
-- Gitsigns Keybindings
vim.api.nvim_set_keymap('n', '<leader>hs', ':Gitsigns stage_hunk<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>hP', ':Gitsigns preview_hunk<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>hu', ':Gitsigns undo_stage_hunk<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>hp', ':Gitsigns preview_hunk_inline<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>hd', ':Gitsigns diffthis<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>hD', ':lua require"gitsigns".diffthis("~")<CR>', { noremap = true, silent = true })
-- Diffview Keybinding
vim.api.nvim_set_keymap('n', '<leader>do', ':DiffviewOpen<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>ds', ':DiffviewOpen --cached<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>dc', ':DiffviewClose<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>dtf', ':DiffviewToggleFiles<CR>', { noremap = true, silent = true })
-- Figutive Keybinding
vim.api.nvim_set_keymap('n', '<leader>stg', ':Git add -p<CR>', { noremap = true, silent = true })
vim.cmd [[colorscheme moonfly]]
-- Rust and Prettier Settings
vim.g.rustfmt_autosave = 1
-- vim.g['prettier#autoformat'] = 1
-- vim.g['prettier#autoformat_require_pragma'] = 0
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'moonfly',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding',
-- 'fileformat',
'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
local eslint = require("eslint")
local null_ls = require("null-ls")
eslint.setup({
bin = 'eslint', -- or `eslint_d`
code_actions = {
enable = true,
apply_on_save = {
enable = true,
types = { "directive", "problem", "suggestion", "layout" },
},
disable_rule_comment = {
enable = true,
location = "separate_line", -- or `same_line`
},
},
diagnostics = {
enable = true,
report_unused_disable_directives = false,
run_on = "type", -- or `save`
},
})
local lspconfig = require("lspconfig")
require("autoclose").setup()
local lsp_capabilities = vim.lsp.protocol.make_client_capabilities()
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "rust_analyzer", "ts_ls", "eslint" },
handlers = {
function(server)
lspconfig[server].setup({
capabilities = lsp_capabilities,
})
end,
['ts_ls'] = function()
lspconfig.ts_ls.setup({
capabilities = lsp_capabilities,
settings = {
completions = {
completeFunctionCalls = true
}
}
})
end
}
})
-- copypaste from nvim-lspconfig repo
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
require('gitsigns').setup{
current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame`
-- enhanced_diff_hl = true
signs = {
add = { text = ' ' },
change = { text = ' ' },
delete = { text = ' ' },
topdelete = { text = ' ' },
changedelete = { text = ' ' },
}
}
vim.api.nvim_set_hl(0, 'GitSignsAdd', { bg = '#0ade00', fg = '#ffffff' })
vim.api.nvim_set_hl(0, 'GitSignsChange', { bg = '#debc00', fg = '#ffffff' })
vim.api.nvim_set_hl(0, 'GitSignsDelete', { bg = '#ff0000', fg = '#ffffff' })
vim.api.nvim_set_hl(0, 'GitSignsAddNr', { bg = '#0ade00', fg = '#ffffff' })
vim.api.nvim_set_hl(0, 'GitSignsChangeNr', { bg = '#debc00', fg = '#ffffff' })
vim.api.nvim_set_hl(0, 'GitSignsDeleteNr', { bg = '#ff0000', fg = '#ffffff' })
-- vim.diagnostic.config({
-- virtual_text = false
-- })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment