let mapleader=" " set mouse=a set number set relativenumber set autoindent set smarttab set ignorecase set smartcase set termguicolors syntax on " Autocompletion set wildmode=longest,list,full " Fix splitting set splitbelow splitright "Tab settings set expandtab set shiftwidth=4 set softtabstop=4 set tabstop=4 set clipboard+=unnamedplus call plug#begin() Plug 'andweeb/presence.nvim' Plug 'ap/vim-css-color' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/nvim-cmp' Plug 'jiangmiao/auto-pairs' Plug 'kyazdani42/nvim-web-devicons' Plug 'L3MON4D3/LuaSnip' Plug 'lewis6991/gitsigns.nvim' Plug 'lukas-reineke/indent-blankline.nvim' Plug 'mattn/emmet-vim' Plug 'Mofiqul/dracula.nvim' Plug 'neovim/nvim-lspconfig' Plug 'norcalli/nvim-colorizer.lua' Plug 'numToStr/Comment.nvim' Plug 'nvim-lualine/lualine.nvim' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'preservim/nerdtree' Plug 'rafi/awesome-vim-colorschemes' Plug 'ryanoasis/vim-devicons' Plug 'saadparwaiz1/cmp_luasnip' Plug 'tomasiser/vim-code-dark' Plug 'vimwiki/vimwiki' call plug#end() colorscheme dracula set cursorline set cursorcolumn highlight CursorLine ctermbg=Yellow cterm=bold guibg=#2b2b2b highlight CursorColumn ctermbg=Yellow cterm=bold guibg=#2b2b2b nnoremap :NERDTreeToggle " Verticaly center document when entering insert mode autocmd InsertEnter * norm zz " Remove trailing whitespace on save autocmd BufWritePre * %s/\s\+$//e " Enable Disable auto comment map c :setlocal formatoptions-=cro map C :setlocal formatoptions=cro " Enable spell checking, s for spell check map s :setlocal spell! spelllang=en_us " Enable Disable auto indent map i :setlocal autoindent map I :setlocal noautoindent " Shortcutting split navigation map h map j map k map l " Moving line up or down by one line nmap :m -2 nmap :m -2 nmap :m +1 nmap :m +1 " Alias replace all to S nnoremap S :%s//gI lua << END require('Comment').setup() require('lualine').setup { options = { icons_enabled = true, theme = 'dracula', 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 = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = {'filename'}, lualine_x = {'location'}, lualine_y = {}, lualine_z = {} }, tabline = {}, extensions = {} } END lua << EOF -- Set completeopt to have a better completion experience vim.o.completeopt = 'menuone,noselect' -- luasnip setup local luasnip = require 'luasnip' -- nvim-cmp setup local cmp = require 'cmp' cmp.setup { completion = { autocomplete = false }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, mapping = { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, [''] = function(fallback) if vim.fn.pumvisible() == 1 then vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') elseif luasnip.expand_or_jumpable() then vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') else fallback() end end, [''] = function(fallback) if vim.fn.pumvisible() == 1 then vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') elseif luasnip.jumpable(-1) then vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-jump-prev', true, true, true), '') else fallback() end end, }, sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, }, } EOF lua << EOF 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 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', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) end -- 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 Bclose(, ) nnoremap bd :Bclose map gn :bn map gp :bp map gw :Bclose " run current script with python3 by CTRL+R in command and insert mode autocmd FileType python map :w:exec '!python3' shellescape(@%, 1) autocmd FileType python imap :w:exec '!python3' shellescape(@%, 1)