Last active
August 27, 2023 10:21
-
-
Save shelepuginivan/3c200f1368ce646fc38817f263caaa11 to your computer and use it in GitHub Desktop.
My nvim config for older neovim versions
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
| " === Common === | |
| set mouse=a " enable mouse | |
| set encoding=utf-8 | |
| set fileformat=unix | |
| set number | |
| set noswapfile | |
| set scrolloff=7 | |
| set expandtab | |
| set copyindent | |
| set softtabstop=4 | |
| set shiftwidth=4 | |
| set tabstop=4 | |
| filetype indent on | |
| " === Mappings === | |
| function! PrevChar() | |
| return getline('.')[col('.') - 2] | |
| endfunction | |
| function! NextChar() | |
| return getline('.')[col('.') - 1] | |
| endfunction | |
| inoremap <expr> ' PrevChar() == " " ? "''\<left>" : "'" | |
| inoremap <expr> " PrevChar() == ' ' ? '""<left>' : '"' | |
| inoremap <expr> ` PrevChar() == ' ' ? '``<left>' : '`' | |
| inoremap ( ()<left> | |
| inoremap [ []<left> | |
| inoremap { {}<left> | |
| inoremap <expr> ) NextChar() == ')' ? '<right>' : ')' | |
| inoremap <expr> ] NextChar() == ']' ? '<right>' : ']' | |
| inoremap <expr> } NextChar() == '}' ? '<right>' : '}' | |
| inoremap jk <esc> | |
| inoremap <C-z> <C-o>u | |
| nnoremap <C-z> u | |
| vnoremap <C-z> <C-o>u | |
| vnoremap { di{}<left><esc>p | |
| vnoremap ( di()<left><esc>p | |
| vnoremap [ di[]<left><esc>p | |
| vnoremap ' di''<left><esc>p | |
| vnoremap " di""<left><esc>p | |
| vnoremap ` di``<left><esc>p | |
| " === Markdown === | |
| if expand('%:e') == 'md' | |
| inoremap * **<left> | |
| inoremap _ __<left> | |
| inoremap ~~ ~~~~<left><left> | |
| inoremap == ====<left><left> | |
| inoremap <C-i> **<left> | |
| inoremap <C-b> ****<left><left> | |
| vnoremap <C-i> di**<left><left><esc>p | |
| vnoremap <C-b> di****<left><left><esc>p | |
| endif | |
| " === VimPlug === | |
| call plug#begin() | |
| Plug 'itchyny/lightline.vim' | |
| Plug 'tpope/vim-fugitive' | |
| Plug 'Pocco81/auto-save.nvim' | |
| Plug 'preservim/nerdtree' | |
| Plug 'neovim/nvim-lspconfig' | |
| Plug 'L3MON4D3/LuaSnip' | |
| Plug 'jose-elias-alvarez/nvim-lsp-ts-utils' | |
| Plug 'nvim-lua/plenary.nvim' | |
| Plug 'ms-jpq/coq_nvim', {'branch': 'coq'} | |
| Plug 'ms-jpq/coq.artifacts', {'branch': 'artifacts'} | |
| Plug 'mattn/emmet-vim' | |
| Plug 'morhetz/gruvbox' | |
| Plug 'xiyaowong/transparent.nvim' | |
| Plug 'ryanoasis/vim-devicons' | |
| call plug#end() | |
| " === Theme === | |
| colorscheme gruvbox | |
| if has('termguicolors') | |
| set termguicolors | |
| endif | |
| let g:transparent_enabled = v:true " enable transparency | |
| " === 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.2, -- dim the color of `message` | |
| cleaning_interval = 1000, -- (ms) automatically clean MsgArea after displaying `message` | |
| }, | |
| 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 | |
| " === Status line === | |
| function! LighlineFilename() | |
| let file_icon = WebDevIconsGetFileTypeSymbol() | |
| return file_icon . ' ' . expand('%') | |
| endfunction | |
| function! LightlineGitbranch() | |
| return FugitiveHead() != '' ? ' ' . FugitiveHead() : '' | |
| endfunction | |
| let g:lightline = { | |
| \ 'colorscheme': 'gruvbox', | |
| \ 'active': { | |
| \ 'left': [ | |
| \ ['mode', 'paste'], | |
| \ ['gitbranch', 'readonly', 'filename', 'modified'] | |
| \ ] | |
| \ }, | |
| \ 'component_function': { | |
| \ 'filename': 'LighlineFilename', | |
| \ 'gitbranch': 'LightlineGitbranch' | |
| \ } | |
| \ } | |
| " === NERDTree === | |
| let NERDTreeShowHidden=1 | |
| nnoremap <C-a> :NERDTreeToggle<CR> | |
| " Close nvim if NERDTree is the last window | |
| autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif | |
| " === Emmet === | |
| let g:user_emmet_settings = { | |
| \ 'snippets': { | |
| \ '!': '<!DOCTYPE html>\n' . | |
| \ '<html lang="en">\n' . | |
| \ '<head>\n' . | |
| \ ' <meta charset="UTF-8">\n' . | |
| \ ' <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' . | |
| \ ' <title></title>\n' . | |
| \ '</head>\n' . | |
| \ '<body>\n' . | |
| \ ' \n' . | |
| \ '</body>\n' . | |
| \ '</html>' | |
| \ } | |
| \ } | |
| " === LSP & Autocomplete === | |
| lua << EOF | |
| local luasnip = require 'luasnip' | |
| local async = require 'plenary.async' | |
| local lsp = require 'lspconfig' | |
| local coq = require 'coq' | |
| -- 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 | |
| -- 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 | |
| -- TypeScript | |
| local buf_map = function(bufnr, mode, lhs, rhs, opts) | |
| vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or { | |
| silent = true | |
| }) | |
| end | |
| lsp.tsserver.setup(coq.lsp_ensure_capabilities({ | |
| 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 default_options = { | |
| on_attach = on_attach, | |
| flags = { | |
| debounce_text_changes = 150 | |
| } | |
| } | |
| -- Python | |
| lsp.pyright.setup(coq.lsp_ensure_capabilities(default_options)) | |
| -- Rust | |
| lsp.rust_analyzer.setup(coq.lsp_ensure_capabilities(default_options)) | |
| vim.cmd('COQnow -s') | |
| EOF | |
| hi DiagnosticError guifg=Red | |
| hi DiagnosticWarn guifg=#ffe533 | |
| hi DiagnosticInfo guifg=#2eccfe | |
| hi DiagnosticHint guifg=White |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment