Last active
December 8, 2024 18:50
-
-
Save devyassineh/e72402c14ce9b06f29134b13923c8982 to your computer and use it in GitHub Desktop.
neovim setup for termux
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
vim.g.mapleader = ' ' | |
vim.g.maplocalleader = ' ' | |
vim.opt.relativenumber = true | |
vim.o.number = true | |
vim.opt.mouse = 'a' | |
vim.schedule(function() | |
vim.opt.clipboard = 'unnamedplus' | |
end) | |
vim.opt.cursorline = true | |
vim.o.foldmethod = "expr" | |
vim.o.foldexpr = "v:lua.vim.lsp.foldexpr()" | |
vim.o.foldenable = false | |
vim.keymap.set("n", "<leader>d", function() vim.diagnostic.open_float() end) | |
vim.keymap.set("n", "<leader>w", "<C-w>") | |
vim.api.nvim_create_autocmd('TextYankPost', { | |
desc = 'Highlight when yanking (copying) text', | |
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
}) | |
local check_back_space = function() | |
local col = vim.fn.col('.') - 1 | |
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then | |
return true | |
else | |
return false | |
end | |
end | |
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | |
if not (vim.uv or vim.loop).fs_stat(lazypath) then | |
local lazyrepo = 'https://github.com/folke/lazy.nvim.git' | |
local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } | |
if vim.v.shell_error ~= 0 then | |
error('Error cloning lazy.nvim:\n' .. out) | |
end | |
end ---@diagnostic disable-next-line: undefined-field | |
vim.opt.rtp:prepend(lazypath) | |
require('lazy').setup({ | |
{ 'tpope/vim-sleuth' }, | |
{ 'windwp/nvim-autopairs', event = 'InsertEnter', opts = {} }, | |
{ | |
"nvim-telescope/telescope.nvim", | |
event = 'VimEnter', | |
branch = '0.1.x', | |
dependencies = { | |
'nvim-lua/plenary.nvim', | |
{ | |
'nvim-telescope/telescope-fzf-native.nvim', | |
build = 'make', | |
cond = function() | |
return vim.fn.executable 'make' == 1 | |
end, | |
}, | |
{ 'nvim-telescope/telescope-ui-select.nvim' }, | |
}, | |
config = function() | |
require('telescope').setup({}) | |
local builtin = require 'telescope.builtin' | |
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' }) | |
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) | |
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) | |
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) | |
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) | |
vim.keymap.set('n', '<leader>so', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) | |
vim.keymap.set('n', '<leader>sb', builtin.buffers, { desc = '[ ] Find existing buffers' }) | |
end | |
}, | |
{ | |
'neovim/nvim-lspconfig', | |
config = function() | |
local lspconfig = require('lspconfig') | |
local default_setup = function(server) | |
lspconfig[server].setup({ | |
capabilities = lsp_capabilities, | |
}) | |
end | |
require('mason').setup({}) | |
require('mason-lspconfig').setup({}) | |
end, | |
dependencies = { | |
{'williamboman/mason.nvim'}, | |
{'williamboman/mason-lspconfig.nvim'}, | |
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, | |
}, | |
}, | |
{ | |
'nvim-treesitter/nvim-treesitter', | |
build = ':TSUpdate', | |
config = function () | |
require('nvim-treesitter.configs').setup({ | |
auto_install = true, | |
highlight = {enable = true,}, | |
indent = { enable = true }, | |
incremental_selection = { | |
enable = true, | |
keymaps = { | |
node_incremental = "v", | |
node_decremental = "V", | |
} | |
}, | |
}) | |
end, | |
}, | |
{ | |
'neovim/nvim-lspconfig', | |
dependencies = { | |
{ 'williamboman/mason.nvim', config = true }, | |
'williamboman/mason-lspconfig.nvim', | |
'WhoIsSethDaniel/mason-tool-installer.nvim', | |
{ 'j-hui/fidget.nvim', opts = {} }, | |
'hrsh7th/cmp-nvim-lsp', | |
}, | |
config = function() | |
vim.api.nvim_create_autocmd('LspAttach', { | |
pattern = "*", | |
callback = function(args) | |
print("Lsp is attached") | |
vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]] | |
vim.lsp.completion.enable(true, args.data.client_id, args.buf, { autotrigger = false }) | |
end, | |
}) | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) | |
local servers = { | |
clangd = {}, | |
gopls = {}, | |
pyright = {}, | |
ts_ls = {}, | |
} | |
require('mason').setup() | |
require('mason-tool-installer').setup { ensure_installed = ensure_installed } | |
require('mason-lspconfig').setup { | |
handlers = { | |
function(server_name) | |
local server = servers[server_name] or {} | |
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) | |
require('lspconfig')[server_name].setup(server) | |
end, | |
}, | |
} | |
end, | |
}, | |
{ | |
'hrsh7th/nvim-cmp', | |
event = 'InsertEnter', | |
dependencies = { | |
'L3MON4D3/LuaSnip', | |
'saadparwaiz1/cmp_luasnip', | |
'hrsh7th/cmp-nvim-lsp', | |
'hrsh7th/cmp-path', | |
}, | |
config = function() | |
local cmp = require 'cmp' | |
local luasnip = require 'luasnip' | |
luasnip.config.setup {} | |
cmp.setup { | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
completion = { completeopt = 'menu,menuone,noinsert' }, | |
mapping = cmp.mapping.preset.insert { | |
['<CR>'] = cmp.mapping.confirm { select = true }, | |
['<C-Space>'] = cmp.mapping.complete {}, | |
['<Tab>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.confirm({select = true}) | |
elseif luasnip.jumpable(1) then | |
luasnip.jump(1) | |
elseif check_back_space() then | |
fallback() | |
else | |
cmp.complete() | |
end | |
end, {'i', 's'}), | |
['<S-Tab>'] = cmp.mapping(function() luasnip.jump(-1) end, {'i', 's'}), | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
{ name = 'path' }, | |
}, | |
} | |
end, | |
}, | |
{ | |
'echasnovski/mini.nvim', | |
config = function() | |
require('mini.ai').setup { n_lines = 500 } | |
require('mini.surround').setup() | |
local statusline = require 'mini.statusline' | |
statusline.setup { use_icons = vim.g.have_nerd_font } | |
statusline.section_location = function() | |
return '%2l:%-2v' | |
end | |
end, | |
}, | |
{ | |
'folke/tokyonight.nvim', | |
priority = 1000, | |
init = function() | |
vim.cmd.colorscheme 'tokyonight-night' | |
end, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment