Last active
December 11, 2022 08:00
-
-
Save khozaei/a85c11acbabd9534941e2ee82148f567 to your computer and use it in GitHub Desktop.
nvim config for c
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
-- .config/nvim/lua/cclsconfig.lua | |
require('ccls').setup({ | |
lsp = { | |
use_defaults = true, | |
codelens = { | |
enable = true, | |
events = {"BufWritePost", "InsertLeave"} | |
} | |
} | |
}) |
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
-- .config/nvim/lua/cmpconfig.lua | |
local cmp = require 'cmp' | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
['<C-b>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.abort(), | |
['<CR>'] = cmp.mapping.confirm({ select = true }), | |
}), | |
sources = cmp.config.sources({ | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
}, { | |
{ name = 'buffer' }, | |
}) | |
}) | |
-- Set configuration for specific filetype. | |
cmp.setup.filetype('gitcommit', { | |
sources = cmp.config.sources({ | |
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. | |
}, { | |
{ name = 'buffer' }, | |
}) | |
}) | |
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline('/', { | |
mapping = cmp.mapping.preset.cmdline(), | |
sources = { | |
{ name = 'buffer' } | |
} | |
}) | |
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline(':', { | |
mapping = cmp.mapping.preset.cmdline(), | |
sources = cmp.config.sources({ | |
{ name = 'path' } | |
}, { | |
{ name = 'cmdline' } | |
}) | |
}) |
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
call plug#begin('~/.nvim/plugged') | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'williamboman/nvim-lsp-installer' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'saadparwaiz1/cmp_luasnip' | |
Plug 'L3MON4D3/LuaSnip' | |
Plug 'hrsh7th/cmp-buffer' | |
Plug 'hrsh7th/cmp-path' | |
Plug 'hrsh7th/cmp-cmdline' | |
Plug 'junegunn/fzf', { 'dir': '~/.nvim/.fzf', 'do': './install --all' } | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'nvim-telescope/telescope.nvim' | |
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' } | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} | |
Plug 'nvim-treesitter/playground' | |
Plug 'flazz/vim-colorschemes' | |
Plug 'itchyny/lightline.vim' | |
Plug 'BurntSushi/ripgrep' | |
Plug 'szw/vim-maximizer' | |
"Plug 'markwoodhall/vim-codelens' | |
Plug 'ranjithshegde/ccls.nvim' | |
Plug 'sakhnik/nvim-gdb', { 'do': ':!./install.sh' } | |
"Plug 'nathanaelkane/vim-indent-guides' | |
Plug 'lukas-reineke/indent-blankline.nvim' | |
call plug#end() | |
lua require('lsp') | |
lua require('cmpconfig') | |
lua require('telescopeconfig') | |
lua require('treesitterconfig') | |
lua require('indent') | |
set number relativenumber | |
set termguicolors | |
set enc=utf-8 | |
set fenc=utf-8 | |
set termencoding=utf-8 | |
set termbidi | |
set noexpandtab | |
set tabstop=2 | |
set softtabstop=2 | |
set shiftwidth=2 | |
set list | |
set lcs+=space:·,eol:↴ | |
let g:neodark#terminal_transparent = 1 | |
let g:neodark#solid_vertsplit = 1 | |
let g:neodark#italics = 1 | |
"let g:lightline = {} | |
"let g:lightline.colorscheme = 'neodark' | |
let g:neodark#use_custom_terminal_theme = 1 | |
colorscheme neodark | |
nnoremap <silent> <C-f> :Telescope find_files<CR> | |
nnoremap <silent> <C-b> :Telescope buffers<CR> | |
let g:fzf_action = { | |
\ 'ctrl-t': 'tab split', | |
\ 'ctrl-e': 'split', | |
\ 'ctrl-v': 'vsplit' } | |
noremap <C-t> :tabnew<CR>:Telescope find_files<CR> | |
"noremap <silent> <C-S-1> 1gt | |
"noremap <silent> <C-S-2> 2gt | |
"noremap <silent> <C-S-3> 3gt | |
"noremap <silent> <C-S-4> 4gt | |
"noremap <silent> <C-S-5> 5gt | |
"noremap <silent> <C-S-6> 6gt | |
"noremap <silent> <C-S-7> 7gt | |
"noremap <silent> <C-8> 8gt | |
nnoremap <S-p>v :wincmd v<bar> :Ex <bar> :vertical resize 30<CR> | |
nnoremap <S-p>s :Telescope live_grep<CR> | |
nnoremap <silent><F3> :MaximizerToggle<CR> | |
nnoremap <silent><F4> <esc>:w<CR> | |
inoremap <silent><F4> <esc>:w<CR> | |
vnoremap <silent><F4> <esc>:w<CR> | |
"vim-indent-guides | |
"let g:indent_guides_enable_on_vim_startup = 1 | |
"hi IndentGuidesOdd guibg=gray ctermbg=5 | |
"hi IndentGuidesEven guibg=lightgray ctermbg=5 | |
"end vim-indent-guides | |
"codelense | |
"let g:codelens_auto = 1 | |
"let g:codelens_show_references = 1 | |
"let g:codelens_show_tests = 1 | |
"let g:codelens_allow_same_line = 1 | |
"end codelense |
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
-- .config/nvim/lua/lsp.lua | |
-- Mappings. | |
-- See `:help vim.diagnostic.*` for documentation on any of the below functions | |
local opts = { noremap=true, silent=true } | |
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) | |
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) | |
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) | |
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local on_attach = function(client, bufnr) | |
-- Enable completion triggered by <c-x><c-o> | |
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings. | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
local bufopts = { noremap=true, silent=true, buffer=bufnr } | |
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) | |
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) | |
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) | |
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) | |
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) | |
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) | |
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) | |
vim.keymap.set('n', '<space>wl', function() | |
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | |
end, bufopts) | |
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) | |
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) | |
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) | |
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) | |
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts) | |
end | |
local lsp_flags = { | |
-- This is the default in Nvim 0.7+ | |
debounce_text_changes = 150, | |
} | |
require('lspconfig')['ccls'].setup{ | |
on_attach = on_attach, | |
flags = lsp_flags, | |
init_options = { | |
cache = { | |
directory = ".ccls-cache"; | |
}; | |
} | |
} | |
require('lspconfig')['tsserver'].setup{ | |
on_attach = on_attach, | |
flags = lsp_flags, | |
} | |
require('lspconfig')['rust_analyzer'].setup{ | |
on_attach = on_attach, | |
flags = lsp_flags, | |
-- Server-specific settings... | |
settings = { | |
["rust-analyzer"] = {} | |
} | |
} |
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
-- .config/nvim/lua/telescopeconfig.lua | |
require('telescope').setup { | |
defaults = { | |
prompt_prefix = "$ " | |
}, | |
extensions = { | |
fzf = { | |
fuzzy = true, -- false will only do exact matching | |
override_generic_sorter = true, -- override the generic sorter | |
override_file_sorter = true, -- override the file sorter | |
case_mode = "smart_case", -- or "ignore_case" or "respect_case" | |
} | |
} | |
} | |
require('telescope').load_extension('fzf') |
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
-- .config/nvim/lua/treesitterconfig.lua | |
require 'nvim-treesitter.configs'.setup { | |
ensure_installed = {'vue','c'}, | |
highlight = { | |
enable = true | |
}, | |
context_commentstring = { | |
enable = true, | |
enable_autocmd = false, | |
additional_vim_regex_highlighting = true | |
}, | |
indent = { enable = true }, | |
playground = { | |
enable = true, | |
disable = {}, | |
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code | |
persist_queries = false, -- Whether the query persists across vim sessions | |
keybindings = { | |
toggle_query_editor = 'o', | |
toggle_hl_groups = 'i', | |
toggle_injected_languages = 't', | |
toggle_anonymous_nodes = 'a', | |
toggle_language_display = 'I', | |
focus_language = 'f', | |
unfocus_language = 'F', | |
update = 'R', | |
goto_node = '<cr>', | |
show_help = '?', | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment