Skip to content

Instantly share code, notes, and snippets.

@malikbenkirane
Created June 25, 2022 18:03
Show Gist options
  • Save malikbenkirane/2da6811a27e174dd8ad8dbc1b592f580 to your computer and use it in GitHub Desktop.
Save malikbenkirane/2da6811a27e174dd8ad8dbc1b592f580 to your computer and use it in GitHub Desktop.
" Essentials
let mapleader = ","
syntax on
set nu ru et
set ts=2 sts=2 sw=2
set cursorline
set hlsearch
set nocompatible
filetype off
" plug!
call plug#begin('~/.config/nvim/plugged')
" new themes!
Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
" new plugs!
Plug 'TimUntersberger/neogit'
Plug 'nvim-lua/plenary.nvim'
Plug 'prabirshrestha/vim-lsp'
"lsp
Plug 'neovim/nvim-lspconfig'
Plug 'glepnir/lspsaga.nvim', { 'branch': 'main' }
"cmp
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
"taboo tabs
Plug 'gcmt/taboo.vim'
"ident-blankline
Plug 'lukas-reineke/indent-blankline.nvim'
" mature plugs
Plug 'dhruvasagar/vim-table-mode'
Plug 'ThePrimeagen/git-worktree.nvim'
"Plug 'hoob3rt/lualine.nvim'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'fannheyward/telescope-coc.nvim'
Plug 'altercation/vim-colors-solarized'
Plug 'rafamadriz/neon'
Plug 'NLKNguyen/papercolor-theme'
" automatic sessions
Plug 'natecraddock/sessions.nvim'
"git
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
Plug 'jreybert/vimagit'
" coc
"Plug 'neoclide/coc.nvim', {'branch': 'release'}
" colors
Plug 'overcache/NeoSolarized'
Plug 'morhetz/gruvbox'
Plug 'sainnhe/sonokai'
Plug 'shaunsingh/nord.nvim'
" others
Plug 'nvim-lua/plenary.nvim'
Plug 'tpope/vim-fugitive'
"Plug 'preservim/nerdtree'
"Plug 'kien/ctrlp.vim'
"Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'ggandor/lightspeed.nvim'
Plug 'evanleck/vim-svelte'
Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'kyazdani42/nvim-tree.lua'
" end of plugs
call plug#end()
" cmp opt
set completeopt=menu,menuone,noselect
lua<<EOF
-- 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', vim.lsp.buf.formatting, bufopts)
end
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
require('lspconfig')['pyright'].setup{
on_attach = on_attach,
flags = lsp_flags,
}
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"] = {}
}
}
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ 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' }
})
})
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['gopls'].setup {
capabilities = capabilities,
cmd={'gopls'},
settings = {
gopls = {
experimentalPostfixCompletions = true,
analyses = {
unusedparams = true,
shadow = true,
},
staticcheck = true,
},
},
on_attach = on_attach,
}
local saga = require 'lspsaga'
saga.init_lsp_saga()
EOF
nnoremap <silent> gh <cmd>lua require'lspsaga.provider'.lsp_finder()<CR>
let g:svelte_preprocessor_tags = [
\ { 'name': 'ts', 'tag': 'script', 'as': 'typescript' }
\ ]
let g:svelte_preprocessors = ['ts']
" background light button
nnoremap <leader>sl :set bg=light<cr>
nnoremap <leader>sd :set bg=dark<cr>
" Coc.nvim
nmap <silent> ge <Plug>(coc-definition)
nmap <silent> gs :sp<CR><Plug>(coc-definition)
nmap <silent> gv :vsp<CR><Plug>(coc-definition)
nmap <silent> gt :vsp<CR><Plug>(coc-definition)<C-W>T
nmap <silent> g/ :CocList symbols<cr>
" relative line numbers
set rnu
" telescope
nnoremap <leader>/ <cmd>Telescope<cr>
nnoremap <leader>// <cmd>Telescope live_grep<cr>
nnoremap <leader>/f <cmd>Telescope find_files<cr>
nnoremap <leader>/b <cmd>Telescope buffers<cr>
" :-)
"nnoremap <leader><leader>s :w<cr>
nnoremap <leader><leader> <C-W>g<Tab>
set mouse=a
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
"nnoremap <leader>tn :tabnext<cr>
"nnoremap <leader>tb :tabprev<cr>
" ,m (prev) ,. (next)
nnoremap <leader>. :tabnext<cr>
nnoremap <leader>m :tabprev<cr>
" nnoremap <leader>tn :NERDTreeClose<cr>:tabnext<cr>
" nnoremap <leader>tp :NERDTreeClose<cr>:tabprev<cr>
" nnoremap <leader>a :Magit<cr><c-W>K<c-W>_
"nnoremap <leader>c :new<cr>p:% !pbcopy<cr>:bw!<cr>
nnoremap <leader>y :new<cr>p:% !pbcopy<cr>:bw!<cr>
nnoremap <leader>p :.r !pbpaste<cr>
nnoremap <leader>t <C-w>s<C-w>j:lcd %:h<cr>:term<cr>i
" underline hash comment
" nnoremap <leader>uhc yyp:.s/./-/g|.s/^--/# /
set cc=72
nnoremap <leader>gf :w<cr>:!go fmt %<cr>:e<cr><cr>
nnoremap <leader>of :w<cr>:!go fmt %<cr>:e<cr><cr>
nnoremap <leader>gv :w<cr>:!go vet %<cr>:e<cr>
nnoremap <leader>gt :w<cr>:!go vet %<cr>:e<cr>
nnoremap <leader>r :w<cr>:CocRestart<cr><cr>
""
" netrw
"
let g:netrw_banner=0
" lualine
"
"require('lualine').setup {
" options = {
" icons_enabled = true,
" theme = 'auto',
" component_separators = { left = ' ', right = ' '},
" section_separators = { left = ' ', right = ' '},
" disabled_filetypes = {},
" always_divide_middle = true,
" globalstatus = false,
" },
" sections = {
" lualine_a = {'mode'},
" lualine_b = {'branch', 'diff', 'diagnostics'},
" lualine_c = {'filename'},
" lualine_x = {'location'},
" lualine_y = {},
" lualine_z = {}
" },
" inactive_sections = {},
" tabline = {},
" extensions = {}
"}
"kolor color and prettyness liebestraum
let g:sonokai_style = 'maia'
let g:sonokai_enable_italic = 1
let g:sonokai_disable_italic_comment = 1
" defaults reset
nnoremap <leader>ce :tabnew<cr>:tcd ~/.ss<cr>:e init.vim<cr>GG
nnoremap <leader>cs :w<cr>:so ~/.config/nvim/init.vim<cr>
nnoremap <leader>ci :PlugInstall<cr><C-W>J
nnoremap <leader>dp :pwd<cr>
nnoremap <leader>dd :tcd<space>
nnoremap <leader>dh :tcd<cr>
nnoremap <leader>d. :tcd ..<cr>
nnoremap <leader>df :!ls -pF<cr>
nnoremap <leader>dk :!mkdir -p<space>
nnoremap <leader>dt :!touch<space>
nnoremap <leader>dc :Git clone [email protected]:
nnoremap <leader>w :w<cr>
nnoremap <leader>bww :bw!<cr>
nnoremap <leader>bn :new<cr>
nnoremap <leader>bv <C-w>v
nnoremap <leader>bs <C-w>s
nnoremap <leader>gg :Gw<cr>:Git commit<cr>
nnoremap <leader>ga :Gw<cr>:Git commit --amend<cr>
nnoremap <leader>gwa :Git worktree add<space>
nnoremap <leader>gp :Git push<cr>
" spAce tab(oo)
nnoremap <leader>ao :TabooOpen<space>
nnoremap <leader>ar :TabooRename<space>
nnoremap <leader>ap :tab sp<cr>
nnoremap <leader><cr> :term<cr>i
set sessionoptions+=tabpages,globals
syntax enable
set nocul
"set tw=68
set t_Co=256
colorscheme PaperColor
set termguicolors
set background=light
nnoremap <silent> gh <cmd>lua require'lspsaga.provider'.lsp_finder()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment