Last active
October 17, 2022 11:06
-
-
Save rybkinn/0adc33c19c3b640d0b9b3753c255b032 to your computer and use it in GitHub Desktop.
my neovim config
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
| " <space>rn - mass funciton rename | |
| set mouse=a " enable mouse | |
| set encoding=utf-8 | |
| set number | |
| set noswapfile | |
| set scrolloff=7 | |
| set tabstop=4 | |
| set softtabstop=4 | |
| set shiftwidth=4 | |
| set expandtab | |
| set autoindent | |
| set fileformat=unix | |
| filetype indent on " load filetype-specific indent files | |
| " for tabulation | |
| set smartindent | |
| set tabstop=2 | |
| set expandtab | |
| set shiftwidth=2 | |
| call plug#begin() | |
| Plug 'neovim/nvim-lspconfig' | |
| Plug 'hrsh7th/nvim-cmp' | |
| Plug 'hrsh7th/cmp-nvim-lsp' | |
| Plug 'saadparwaiz1/cmp_luasnip' | |
| Plug 'L3MON4D3/LuaSnip' | |
| " color schemas | |
| Plug 'morhetz/gruvbox' " colorscheme gruvbox | |
| Plug 'mhartington/oceanic-next' " colorscheme OceanicNext | |
| Plug 'kaicataldo/material.vim', { 'branch': 'main' } | |
| Plug 'ayu-theme/ayu-vim' | |
| Plug 'xiyaowong/nvim-transparent' | |
| Plug 'Pocco81/auto-save.nvim' | |
| Plug 'justinmk/vim-sneak' | |
| " JS/JSX/TS | |
| Plug 'pangloss/vim-javascript' | |
| Plug 'leafgarland/typescript-vim' | |
| Plug 'peitalin/vim-jsx-typescript' | |
| Plug 'maxmellon/vim-jsx-pretty' | |
| " TS from here https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c | |
| Plug 'jose-elias-alvarez/null-ls.nvim' | |
| Plug 'jose-elias-alvarez/nvim-lsp-ts-utils' | |
| Plug 'nvim-lua/plenary.nvim' | |
| Plug 'prettier/vim-prettier', { | |
| \ 'do': 'npm install --frozen-lockfile --production', | |
| \ 'for': ['javascript', 'typescript', 'typescriptreact', 'javascriptreact', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml', 'html'] } | |
| Plug 'bmatcuk/stylelint-lsp' | |
| Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' } | |
| Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' } | |
| " Convenient floating terminal window | |
| "Plug 'voldikss/vim-floaterm' | |
| " Discord Rich Presence for Neovim | |
| Plug 'andweeb/presence.nvim' | |
| Plug 'kdheepak/lazygit.nvim' | |
| Plug 'preservim/tagbar' | |
| Plug 'preservim/nerdtree' | |
| Plug 'tpope/vim-surround' | |
| Plug 'tpope/vim-commentary' | |
| Plug 'terryma/vim-multiple-cursors' | |
| Plug 'mattn/emmet-vim' | |
| Plug 'tpope/vim-repeat' | |
| call plug#end() | |
| " Leader bind | |
| let mapleader = "," | |
| " Tagbar settings | |
| nmap <F8> :TagbarToggle<CR> | |
| let g:tagbar_compact = 1 | |
| let g:tagbar_sort = 0 | |
| " # Copy text in buffer. WSL -> Windows | |
| vmap <F2> :'<,'>w !clip.exe | |
| nnoremap <leader><leader> :NERDTreeToggle<CR> | |
| " nnoremap <C-n> :NERDTreeFindFile<CR> | |
| let NERDTreeIgnore = ['\.pyc$'] | |
| " Vertical\Horisontal Split | |
| map <leader>vl :vsp<CR> | |
| map <leader>hl :sp<CR> | |
| " Map ctrl-movement keys to window switching | |
| map <C-k> <C-w><Up> | |
| map <C-j> <C-w><Down> | |
| map <C-l> <C-w><Right> | |
| map <C-h> <C-w><Left> | |
| " Do not use arrows | |
| nnoremap <Left> :echoe "Use h"<CR> | |
| nnoremap <Right> :echoe "Use l"<CR> | |
| nnoremap <Up> :echoe "Use k"<CR> | |
| nnoremap <Down> :echoe "Use j"<CR> | |
| " setup mapping to call :LazyGit | |
| nnoremap <leader>c :LazyGit<CR> | |
| imap <C-[> <Esc> | |
| " Netrw file explorer settings | |
| let g:netrw_banner = 0 " hide banner above files | |
| let g:netrw_liststyle = 3 " tree instead of plain view | |
| let g:netrw_browse_split = 3 " vertical split window when Enter pressed on file | |
| " Automatically format frontend files with prettier after file save | |
| let g:prettier#autoformat = 1 | |
| let g:prettier#autoformat_require_pragma = 0 | |
| " Disable quickfix window for prettier | |
| let g:prettier#quickfix_enabled = 0 | |
| " Turn on vim-sneak | |
| let g:sneak#label = 1 | |
| colorscheme gruvbox | |
| "colorscheme OceanicNext | |
| "let g:material_terminal_italics = 1 | |
| " variants: default, palenight, ocean, lighter, darker, default-community, | |
| " palenight-community, ocean-community, lighter-community, | |
| " darker-community | |
| "let g:material_theme_style = 'darker' | |
| "colorscheme material | |
| if (has('termguicolors')) | |
| set termguicolors | |
| endif | |
| " variants: mirage, dark, dark | |
| "let ayucolor="mirage" | |
| "colorscheme ayu | |
| " turn off search highlight | |
| nnoremap <leader><space> :nohlsearch<CR> | |
| lua << EOF | |
| -- Set completeopt to have a better completion experience | |
| vim.o.completeopt = 'menuone,noselect' | |
| -- luasnip setup | |
| local luasnip = require 'luasnip' | |
| local async = require "plenary.async" | |
| -- nvim-cmp setup | |
| local cmp = require 'cmp' | |
| cmp.setup { | |
| completion = { | |
| autocomplete = false | |
| }, | |
| snippet = { | |
| expand = function(args) | |
| require('luasnip').lsp_expand(args.body) | |
| end, | |
| }, | |
| mapping = { | |
| ['<C-p>'] = cmp.mapping.select_prev_item(), | |
| ['<C-n>'] = cmp.mapping.select_next_item(), | |
| ['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
| ['<C-f>'] = cmp.mapping.scroll_docs(4), | |
| ['<C-Space>'] = cmp.mapping.complete(), | |
| ['<C-e>'] = cmp.mapping.close(), | |
| ['<CR>'] = cmp.mapping.confirm { | |
| behavior = cmp.ConfirmBehavior.Replace, | |
| select = true, | |
| }, | |
| ['<Tab>'] = function(fallback) | |
| if vim.fn.pumvisible() == 1 then | |
| vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n') | |
| elseif luasnip.expand_or_jumpable() then | |
| vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '') | |
| else | |
| fallback() | |
| end | |
| end, | |
| ['<S-Tab>'] = function(fallback) | |
| if vim.fn.pumvisible() == 1 then | |
| vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n') | |
| elseif luasnip.jumpable(-1) then | |
| vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '') | |
| else | |
| fallback() | |
| end | |
| end, | |
| }, | |
| sources = { | |
| { name = 'nvim_lsp' }, | |
| { name = 'luasnip' }, | |
| }, | |
| } | |
| local nvim_lsp = require('lspconfig') | |
| -- 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) | |
| local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
| local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
| -- Enable completion triggered by <c-x><c-o> | |
| buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
| -- Mappings. | |
| local opts = { noremap=true, silent=true } | |
| -- See `:help vim.lsp.*` for documentation on any of the below functions | |
| buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
| buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
| buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
| buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
| buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
| buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
| buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
| buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
| buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
| buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
| buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
| buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
| buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
| buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
| buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
| buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
| buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
| end | |
| -- TS setup | |
| local buf_map = function(bufnr, mode, lhs, rhs, opts) | |
| vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or { | |
| silent = true, | |
| }) | |
| end | |
| nvim_lsp.tsserver.setup({ | |
| on_attach = function(client, bufnr) | |
| client.resolved_capabilities.document_formatting = false | |
| client.resolved_capabilities.document_range_formatting = false | |
| local ts_utils = require("nvim-lsp-ts-utils") | |
| ts_utils.setup({}) | |
| ts_utils.setup_client(client) | |
| buf_map(bufnr, "n", "gs", ":TSLspOrganize<CR>") | |
| buf_map(bufnr, "n", "gi", ":TSLspRenameFile<CR>") | |
| buf_map(bufnr, "n", "go", ":TSLspImportAll<CR>") | |
| on_attach(client, bufnr) | |
| end, | |
| }) | |
| local null_ls = require("null-ls") | |
| null_ls.setup({ | |
| sources = { | |
| null_ls.builtins.diagnostics.eslint, | |
| null_ls.builtins.code_actions.eslint, | |
| null_ls.builtins.formatting.prettier | |
| }, | |
| on_attach = on_attach | |
| }) | |
| -- Stylelint format after save | |
| require'lspconfig'.stylelint_lsp.setup{ | |
| settings = { | |
| stylelintplus = { | |
| --autoFixOnSave = true, | |
| --autoFixOnFormat = true, | |
| } | |
| } | |
| } | |
| -- Use a loop to conveniently call 'setup' on multiple servers and | |
| -- map buffer local keybindings when the language server attaches | |
| local servers = { 'pyright', 'rust_analyzer' } | |
| for _, lsp in ipairs(servers) do | |
| nvim_lsp[lsp].setup { | |
| on_attach = on_attach, | |
| flags = { | |
| debounce_text_changes = 150, | |
| } | |
| } | |
| end | |
| EOF | |
| " Delete buffer while keeping window layout (don't close buffer's windows). | |
| " Version 2008-11-18 from http://vim.wikia.com/wiki/VimTip165 | |
| if v:version < 700 || exists('loaded_bclose') || &cp | |
| finish | |
| endif | |
| let loaded_bclose = 1 | |
| if !exists('bclose_multiple') | |
| let bclose_multiple = 1 | |
| endif | |
| " Display an error message. | |
| function! s:Warn(msg) | |
| echohl ErrorMsg | |
| echomsg a:msg | |
| echohl NONE | |
| endfunction | |
| " Command ':Bclose' executes ':bd' to delete buffer in current window. | |
| " The window will show the alternate buffer (Ctrl-^) if it exists, | |
| " or the previous buffer (:bp), or a blank buffer if no previous. | |
| " Command ':Bclose!' is the same, but executes ':bd!' (discard changes). | |
| " An optional argument can specify which buffer to close (name or number). | |
| function! s:Bclose(bang, buffer) | |
| if empty(a:buffer) | |
| let btarget = bufnr('%') | |
| elseif a:buffer =~ '^\d\+$' | |
| let btarget = bufnr(str2nr(a:buffer)) | |
| else | |
| let btarget = bufnr(a:buffer) | |
| endif | |
| if btarget < 0 | |
| call s:Warn('No matching buffer for '.a:buffer) | |
| return | |
| endif | |
| if empty(a:bang) && getbufvar(btarget, '&modified') | |
| call s:Warn('No write since last change for buffer '.btarget.' (use :Bclose!)') | |
| return | |
| endif | |
| " Numbers of windows that view target buffer which we will delete. | |
| let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == btarget') | |
| if !g:bclose_multiple && len(wnums) > 1 | |
| call s:Warn('Buffer is in multiple windows (use ":let bclose_multiple=1")') | |
| return | |
| endif | |
| let wcurrent = winnr() | |
| for w in wnums | |
| execute w.'wincmd w' | |
| let prevbuf = bufnr('#') | |
| if prevbuf > 0 && buflisted(prevbuf) && prevbuf != btarget | |
| buffer # | |
| else | |
| bprevious | |
| endif | |
| if btarget == bufnr('%') | |
| " Numbers of listed buffers which are not the target to be deleted. | |
| let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != btarget') | |
| " Listed, not target, and not displayed. | |
| let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0') | |
| " Take the first buffer, if any (could be more intelligent). | |
| let bjump = (bhidden + blisted + [-1])[0] | |
| if bjump > 0 | |
| execute 'buffer '.bjump | |
| else | |
| execute 'enew'.a:bang | |
| endif | |
| endif | |
| endfor | |
| execute 'bdelete'.a:bang.' '.btarget | |
| execute wcurrent.'wincmd w' | |
| endfunction | |
| command! -bang -complete=buffer -nargs=? Bclose call <SID>Bclose(<q-bang>, <q-args>) | |
| nnoremap <silent> <Leader>bd :Bclose<CR> | |
| map gn :bn<cr> | |
| map gp :bp<cr> | |
| map gw :Bclose<cr> | |
| " Run Python and C files by Ctrl+h | |
| autocmd FileType python map <buffer> <F9> :w<CR>:exec '!python3.10' shellescape(@%, 1)<CR> | |
| autocmd FileType python imap <buffer> <F9> <esc>:w<CR>:exec '!python3.10' shellescape(@%, 1)<CR> | |
| autocmd FileType c map <buffer> <F9> :w<CR>:exec '!gcc' shellescape(@%, 1) '-o out; ./out'<CR> | |
| autocmd FileType c imap <buffer> <F9> <esc>:w<CR>:exec '!gcc' shellescape(@%, 1) '-o out; ./out'<CR> | |
| autocmd FileType python set colorcolumn=79 | |
| set relativenumber | |
| set rnu | |
| let g:transparent_enabled = v:true | |
| " Telescope bindings | |
| nnoremap <leader>f <cmd>Telescope find_files<cr> | |
| nnoremap <leader>g <cmd>Telescope live_grep<cr> | |
| " Go to next or prev tab by H and L accordingly | |
| nnoremap J gT | |
| nnoremap K gt | |
| " Autosave plugin | |
| lua << EOF | |
| require("auto-save").setup({ | |
| enabled = true, | |
| execution_message = { | |
| message = function() -- message to print on save | |
| return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) | |
| end, | |
| dim = 0.18, -- dim the color of `message` | |
| cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea | |
| }, | |
| events = {"InsertLeave", "TextChanged"}, | |
| conditions = { | |
| exists = true, | |
| filename_is_not = {}, | |
| filetype_is_not = {}, | |
| modifiable = true | |
| }, | |
| write_all_buffers = false, | |
| on_off_commands = true, | |
| clean_command_line_interval = 0, | |
| debounce_delay = 135, | |
| }) | |
| EOF | |
| " Telescope fzf plugin | |
| lua << EOF | |
| require('telescope').load_extension('fzf') | |
| EOF | |
| " Fast component creating for React app | |
| command CreateComponent :terminal '/Users/Nikita/code/lms/frontend/createcomponent.py' | |
| " White colors for LSP messages in code | |
| set termguicolors | |
| hi DiagnosticError guifg=White | |
| hi DiagnosticWarn guifg=White | |
| hi DiagnosticInfo guifg=White | |
| hi DiagnosticHint guifg=White |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment