Last active
May 16, 2023 23:38
-
-
Save k3karthic/7776cfd8f9de2abc908924e714e1b924 to your computer and use it in GitHub Desktop.
Neovim Configuration
This file contains hidden or 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
-- Use :imap :nmap :vmap to view the current keybindings | |
-- clear search selection | |
vim.keymap.set('n', '<C-/>', ':let @/ = ""<CR>', {noremap = true, silent = true}) | |
-- Map <Leader> to backslash | |
vim.g.mapleader = "\\" | |
-- shortcuts to copy/paste to/from clipboard | |
vim.keymap.set('n', '<leader>y', '"+y', {noremap = true, silent = true}) | |
vim.keymap.set('n', '<leader>yy', '"+yy', {noremap = true, silent = true}) | |
vim.keymap.set('n', '<leader>p', '"+p', {noremap = true, silent = true}) | |
vim.opt.number = true | |
vim.opt.tabstop = 4 | |
vim.opt.shiftwidth = 4 | |
vim.opt.ignorecase = true | |
-- YAML - 2 space indent, no tabs | |
vim.api.nvim_create_autocmd("FileType", { | |
pattern = { "yaml" }, | |
callback = function() | |
vim.opt.tabstop = 2 | |
vim.opt.shiftwidth = 2 | |
vim.opt.expandtab = true | |
end | |
}) | |
-- Python - 4 space indent, no tabs | |
vim.api.nvim_create_autocmd("FileType", { | |
pattern = { "python" }, | |
callback = function() | |
vim.opt.tabstop = 4 | |
vim.opt.shiftwidth = 4 | |
vim.opt.expandtab = true | |
end | |
}) | |
-- Lua - 4 tab indent, no spaces | |
vim.api.nvim_create_autocmd("FileType", { | |
pattern = { "lua" }, | |
callback = function() | |
vim.opt.tabstop = 4 | |
vim.opt.shiftwidth = 4 | |
vim.opt.expandtab = false | |
end | |
}) | |
-- Disable backup files | |
vim.opt.backup = false | |
vim.opt.writebackup = false | |
-- :set guifont=* to trigger font chooser gui | |
-- :set guifont? to get the value to set below | |
vim.opt.guifont = "DroidSansM Nerd Font Mono:h10:l" | |
local ensure_packer = function() | |
local fn = vim.fn | |
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' | |
if fn.empty(fn.glob(install_path)) > 0 then | |
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) | |
vim.cmd [[packadd packer.nvim]] | |
return true | |
end | |
return false | |
end | |
local packer_bootstrap = ensure_packer() | |
return require('packer').startup(function(use) | |
use 'wbthomason/packer.nvim' | |
use { 'editorconfig/editorconfig-vim' } | |
use { 'folke/tokyonight.nvim', config = function() vim.cmd[[colorscheme tokyonight-storm]] end } | |
-- Fancy start screen | |
use { 'mhinz/vim-startify' } | |
use { | |
'nvim-treesitter/nvim-treesitter', | |
tag = 'v0.9.0', | |
requires = { | |
{ 'JoosepAlviste/nvim-ts-context-commentstring' }, | |
}, | |
run = function() | |
local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) | |
ts_update() | |
end, | |
config = function() | |
require'nvim-treesitter.configs'.setup { | |
ensure_installed = { "yaml", "lua", "python", "typescript", "tsx" }, | |
sync_install = true, | |
auto_install = true, | |
ignore_install = { "javascript" }, | |
highlight = { | |
enable = true, | |
additional_vim_regex_highlighting = false | |
}, | |
-- For nvim-ts-context-commentstring | |
context_commentstring = { | |
enable = true | |
} | |
} | |
-- vim.opt.foldmethod = 'expr' | |
-- vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' | |
---WORKAROUND | |
vim.api.nvim_create_autocmd({'BufEnter','BufAdd','BufNew','BufNewFile','BufWinEnter'}, { | |
group = vim.api.nvim_create_augroup('TS_FOLD_WORKAROUND', {}), | |
callback = function() | |
vim.opt.foldmethod = 'expr' | |
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' | |
vim.opt.foldenable = false | |
end | |
}) | |
---ENDWORKAROUND | |
end | |
} | |
use { | |
'lewis6991/gitsigns.nvim', | |
branch = 'release', | |
config = function() | |
require('gitsigns').setup() | |
end | |
} | |
use { | |
'nvim-telescope/telescope.nvim', | |
branch = '0.1.x', | |
requires = { | |
{ 'nvim-tree/nvim-web-devicons' }, | |
{ 'sharkdp/fd' }, | |
{ 'nvim-lua/plenary.nvim' }, | |
{ 'nvim-telescope/telescope-project.nvim' }, | |
{ 'nvim-telescope/telescope-file-browser.nvim' } | |
}, | |
config = function() | |
local builtin = require('telescope.builtin') | |
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) | |
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) | |
vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) | |
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) | |
vim.keymap.set('n', '<leader>gs', builtin.git_status, {}) | |
local telescope = require('telescope') | |
telescope.load_extension('project') | |
telescope.load_extension('file_browser') | |
vim.keymap.set('n', '<leader>w', ":lua require'telescope'.extensions.project.project{}<CR>", {noremap = true, silent = true}) | |
vim.api.nvim_set_keymap("n", "<space>fb", ":Telescope file_browser<CR>", { noremap = true, silent = true }) | |
vim.api.nvim_set_keymap("n", "<space>fs", ":Telescope lsp_document_symbols<CR>", { noremap = true, silent = true }) | |
end | |
} | |
use { | |
'neovim/nvim-lspconfig', | |
config = function() | |
-- 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) | |
-- 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, | |
}) | |
end | |
} | |
use { | |
'hrsh7th/nvim-cmp', | |
after = 'nvim-lspconfig', | |
config = function() | |
local cmp = require 'cmp' | |
cmp.setup { | |
mapping = cmp.mapping.preset.insert({ | |
['<C-b>'] = cmp.mapping.scroll_docs(-4), -- Up | |
['<C-f>'] = cmp.mapping.scroll_docs(4), -- Down | |
['<C-y>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.abort(), | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
['<C-j>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
else | |
fallback() | |
end | |
end, { 'i', 's' }), | |
['<C-k>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
else | |
fallback() | |
end | |
end, { 'i', 's' }), | |
}), | |
sources = { | |
{ name = 'nvim_lsp' }, | |
}, | |
} | |
end | |
} | |
use { | |
'hrsh7th/cmp-nvim-lsp', | |
after = 'nvim-cmp', | |
config = function() | |
local capabilities = require("cmp_nvim_lsp").default_capabilities() | |
local lspconfig = require('lspconfig') | |
lspconfig.tsserver.setup { | |
capabilities = capabilities, | |
autostart = true | |
} | |
lspconfig.pylsp.setup { | |
capabilities = capabilities, | |
autostart = true, | |
settings = { | |
pylsp = { | |
plugins = { | |
black = { enabled = true }, | |
ruff = { enabled = true } | |
} | |
} | |
} | |
} | |
end | |
} | |
use { | |
'jose-elias-alvarez/null-ls.nvim', | |
after = 'cmp-nvim-lsp', | |
requires = { | |
{ 'nvim-lua/plenary.nvim' } | |
}, | |
config = function() | |
local null_ls = require('null-ls') | |
null_ls.setup({ | |
sources = { | |
null_ls.builtins.formatting.prettier, | |
null_ls.builtins.code_actions.eslint, | |
null_ls.builtins.diagnostics.eslint | |
} | |
}) | |
end | |
} | |
-- Get platform dependant build script | |
local function tabnine_build_path() | |
if vim.loop.os_uname().sysname == "Windows_NT" then | |
return "pwsh.exe -file .\\dl_binaries.ps1" | |
else | |
return "./dl_binaries.sh" | |
end | |
end | |
use { | |
'codota/tabnine-nvim', | |
commit = 'cf22d7707263a0ff6f8a5bf47cda0a8a5d2d4238', | |
run = tabnine_build_path(), | |
config = function() | |
require('tabnine').setup({ | |
disable_auto_comment=true, | |
accept_keymap="<Tab>", | |
dismiss_keymap = "<C-]>", | |
debounce_ms = 800, | |
suggestion_color = {gui = "#808080", cterm = 244}, | |
exclude_filetypes = {"TelescopePrompt"}, | |
log_file_path = nil, -- absolute path to Tabnine log file | |
}) | |
end | |
} | |
use { | |
'numToStr/Comment.nvim', | |
config = function() | |
require('Comment').setup({ | |
pre_hook = function(ctx) | |
local U = require'Comment.utils' | |
-- For TSX | |
local location = nil | |
if ctx.ctype == U.ctype.block then | |
location = require("ts_context_commentstring.utils").get_cursor_location() | |
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then | |
location = require("ts_context_commentstring.utils").get_visual_start_location() | |
end | |
return require("ts_context_commentstring.internal").calculate_commentstring { | |
key = ctx.ctype == U.ctype.line and "__default" or "__multiline", | |
location = location | |
} | |
end | |
}) | |
end | |
} | |
use { | |
'nvim-lualine/lualine.nvim', | |
after = 'tabnine-nvim', | |
requires = { | |
{ 'nvim-tree/nvim-web-devicons', opt = true }, | |
{ 'arkav/lualine-lsp-progress' } | |
}, | |
config = function() | |
require('lualine').setup({ | |
tabline = { | |
lualine_a = {'searchcount', 'selectioncount'}, | |
lualine_b = {}, | |
lualine_c = {'filename'}, | |
lualine_x = {'encoding', 'fileformat', 'filetype'}, | |
lualine_y = {}, | |
lualine_z = {}, | |
}, | |
sections = { | |
lualine_c = {'lsp_progress'}, | |
lualine_x = {'tabnine'} | |
} | |
}) | |
end | |
} | |
use { | |
'mfussenegger/nvim-dap', | |
after = 'telescope.nvim', | |
requires = { | |
{ 'rcarriga/nvim-dap-ui' }, | |
{ 'mfussenegger/nvim-dap-python' }, | |
{ 'mxsdev/nvim-dap-vscode-js' }, | |
{ 'theHamsta/nvim-dap-virtual-text' }, | |
{ 'nvim-telescope/telescope-dap.nvim' } | |
}, | |
config = function() | |
require('telescope').load_extension('dap') | |
require("nvim-dap-virtual-text").setup() | |
local dap, dapui = require("dap"), require("dapui") | |
dapui.setup() | |
dap.listeners.after.event_initialized["dapui_config"] = function() | |
dapui.open() | |
end | |
dap.listeners.before.event_terminated["dapui_config"] = function() | |
dapui.close() | |
end | |
dap.listeners.before.event_exited["dapui_config"] = function() | |
dapui.close() | |
end | |
require('dap-python').setup() | |
end | |
} | |
use { | |
"mxsdev/nvim-dap-vscode-js", | |
after = 'nvim-dap', | |
opt = true, | |
run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out", | |
config = function() | |
require("dap-vscode-js").setup({ | |
-- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node" | |
-- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation. | |
-- debugger_cmd = { "js-debug-adapter" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`. | |
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap | |
-- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging | |
-- log_file_level = false -- Logging level for output to file. Set to false to disable file logging. | |
-- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output. | |
}) | |
vim.keymap.set( | |
'n', '<leader>lvl', | |
":lua require('dap.ext.vscode').load_launchjs(nil, { chrome = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact'} })<CR>", | |
{noremap = true, silent = true} | |
) | |
end | |
} | |
-- Automatically set up your configuration after cloning packer.nvim | |
-- Put this at the end after all plugins | |
if packer_bootstrap then | |
require('packer').sync() | |
end | |
end) |
This file contains hidden or 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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "chrome", | |
"request": "launch", | |
"name": "Launch Chrome against localhost", | |
"url": "http://localhost:3000", | |
"webRoot": "${workspaceFolder}" | |
} | |
] | |
} |
This file contains hidden or 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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Python: manage.py", | |
"type": "python", | |
"request": "launch", | |
"program": "${workspaceFolder}/manage.py", | |
"console": "integratedTerminal", | |
"justMyCode": true, | |
"args": ["runserver"] | |
}, | |
{ | |
"name": "Python: manage.py (no-reload)", | |
"type": "python", | |
"request": "launch", | |
"program": "${workspaceFolder}/manage.py", | |
"console": "integratedTerminal", | |
"justMyCode": true, | |
"args": ["runserver"], | |
"env": { | |
"DISABLE_HOT_RELOAD": "true" | |
} | |
}, | |
{ | |
"name": "Python: manage.py (attach)", | |
"type": "python", | |
"request": "attach", | |
"port": 50011 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment