Skip to content

Instantly share code, notes, and snippets.

@tokers
Created April 3, 2023 08:28
Show Gist options
  • Save tokers/0a8c874208f08cf28ad9c2ea50d34024 to your computer and use it in GitHub Desktop.
Save tokers/0a8c874208f08cf28ad9c2ea50d34024 to your computer and use it in GitHub Desktop.
" Copyright (C) Alex Zhang (tokers)
"
" This is my own VIM/NVIM configuration file.
"
set nocompatible
set noshowmode
filetype plugin indent on
" for nvim
set runtimepath^=~/.vim runtimepath+=~/.vim/after
" relative number is important to locate the precise target line
" number.
set relativenumber
set number
set autoindent
set cindent
set smartindent
set hidden
syntax on
syntax enable
set history=1000
set showtabline=0
set t_Co=256
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
set shiftround
set textwidth=79
set fileformat=unix
set noshowcmd
set mouse=a
set nobackup
set noshowcmd
set encoding=UTF-8
set noswapfile
set autowrite
set backspace=2
set foldmethod=indent
set foldlevel=99
set tags=tags;/
set tags+=.tags;/
set completeopt=longest,menu
set laststatus=2
set updatetime=1000
"abbreviations
iabbrev slef self
iabbrev adn and
iabbrev tpye type
iabbrev aelx alex
iabbrev rertun return
iabbrev exprie expire
" Vim Tmux compatible
if exists('$TMUX') && !has("nvim")
set term=screen-256color
endif
" I like the silm vertical split line :).
set fillchars=vert:│
set hlsearch
set ignorecase smartcase
set incsearch
" discard the highlight insearch part.
nnoremap <silent> <C-y> :nohlsearch<Bar>:echo<CR>
nnoremap <C-h> <C-w>h " goto the left window <
nnoremap <C-j> <C-w>j " goto the next window V
nnoremap <C-k> <C-w>k " goto the preivous windows ^
nnoremap <C-l> <C-w>l " goto the right window >
nnoremap <C-=> <C-w>= " let all windows have the same width
nnoremap <C-x> <C-w>x " switch window's position
nnoremap <C-q> <C-w>q " quit current window
nnoremap <C-c> <C-w>c " close current window
nnoremap gl :tabs<CR>
if has("nvim")
set guicursor=
nnoremap <C-p> :FloatermToggle<CR>
" nnoremap <C-P> :botright 15sp term://zsh<CR>
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
endif
nnoremap H ^
nnoremap L $
noremap ^L ^wL
noremap ^J ^wJ
noremap ^K ^wK
noremap ^H ^wH
let mapleader = '`'
nnoremap <leader>ev :tabnew $MYVIMRC<CR>
nnoremap <leader>sv :source $MYVIMRC<CR>
nnoremap <leader>pv :set paste!<CR>
nnoremap <leader>t : shell<CR>
nnoremap <leader>" bi"<ESC>ea"<ESC>
nnoremap <leader>' bi'<ESC>ea'<ESC>
nnoremap <leader>{ bi{<ESC>ea}<ESC>
nnoremap <leader>[ bi[<ESC>ea]<ESC>
tnoremap <Esc> <C-\><C-n>
nnoremap <F4> :vertical resize +10<CR>
nnoremap <F5> :vertical resize -10<CR>
nnoremap {: i"<Esc>ea}<Esc>
nnoremap <space> za
nnoremap ]h <Plug>GitGutterNextHunk
nnoremap [h <Plug>GitGutterPrevHunk
noremap <C-\> :NeoTreeShowToggle <CR>
inoremap <C-\> <ESC>:NeoTreeShowToggle <CR>
"==================================================Plugin Settings=================================================="
filetype off
set termguicolors
call plug#begin("~/.vim/plugged")
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'godlygeek/tabular'
Plug 'tpope/vim-commentary'
Plug 'ryanoasis/vim-devicons'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' }
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-tree/nvim-web-devicons' " not strictly required, but recommended
Plug 'MunifTanjim/nui.nvim'
Plug 'nvim-neo-tree/neo-tree.nvim'
Plug 'mkitt/tabline.vim'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'nvim-tree/nvim-web-devicons' " Recommended (for coloured icons)
Plug 'nvim-lualine/lualine.nvim'
Plug 'RRethy/vim-illuminate'
Plug 'airblade/vim-gitgutter'
let g:gitgutter_max_signs = 500
Plug 'spf13/vim-autoclose'
let g:autoclose_vim_commentmode = 1
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.1' }
Plug 'voldikss/vim-floaterm'
Plug 'L3MON4D3/LuaSnip', {'tag': 'v1.2.1', 'do': 'make install_jsregexp'}
" Plug '~/.vim/plugged/float-preview'
Plug 'rking/ag.vim'
Plug 'mfussenegger/nvim-dap'
Plug 'leoluz/nvim-dap-go'
Plug 'mhinz/vim-startify'
" For conceal markers.
if has('conceal')
set conceallevel=2 concealcursor=niv
endif
call plug#end()
let g:float_preview#docked = 0
set hidden
lua << END
require('lualine').setup()
require('dap-go').setup {
dap_configurations = {
-- Must be "go" or it will be ignored by the plugin
type = "go",
name = "go-delve",
request = "launch",
},
-- delve configurations
delve = {
-- time to wait for delve to initialize the debug session.
-- default to 20 seconds
initialize_timeout_sec = 20,
-- a string that defines the port to start delve debugger.
-- default to string "${port}" which instructs nvim-dap
-- to start the process in a random available port
port = "${port}"
},
}
END
lua <<EOF
-- vim.opt.termguicolors = true
-- require("bufferline").setup{
-- options = {
-- diagnostics = "nvim_lsp",
-- numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string,
-- close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
-- right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
-- left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
-- middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
-- -- NOTE: this plugin is designed with this icon in mind,
-- -- and so changing this is NOT recommended, this is intended
-- -- as an escape hatch for people who cannot bear it for whatever reason
-- indicator = {
-- icon == "▎",
-- style = "icon",
-- },
-- buffer_close_icon = "",
-- -- buffer_close_icon = '',
-- modified_icon = "●",
-- close_icon = "",
-- -- close_icon = '',
-- left_trunc_marker = "",
-- right_trunc_marker = "",
-- max_name_length = 30,
-- max_prefix_length = 30, -- prefix used when a buffer is de-duplicated
-- tab_size = 21,
-- diagnostics = false, -- | "nvim_lsp" | "coc",
-- diagnostics_update_in_insert = false,
-- offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
-- show_buffer_icons = true,
-- show_buffer_close_icons = true,
-- show_close_icon = true,
-- show_tab_indicators = true,
-- persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
-- separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' },
-- enforce_regular_tabs = true,
-- always_show_bufferline = true,
-- },
-- highlights = {
-- fill = {
-- fg = { attribute = "fg", highlight = "#ff0000" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- background = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- -- buffer_selected = {
-- -- guifg = {attribute='fg',highlight='#ff0000'},
-- -- guibg = {attribute='bg',highlight='#0000ff'},
-- -- gui = 'none'
-- -- },
-- buffer_visible = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- close_button = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- close_button_visible = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- tab_selected = {
-- fg = { attribute = "fg", highlight = "Normal" },
-- bg = { attribute = "bg", highlight = "Normal" },
-- },
-- tab = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- tab_close = {
-- -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'},
-- fg = { attribute = "fg", highlight = "TabLineSel" },
-- bg = { attribute = "bg", highlight = "Normal" },
-- },
-- duplicate_selected = {
-- fg = { attribute = "fg", highlight = "TabLineSel" },
-- bg = { attribute = "bg", highlight = "TabLineSel" },
-- },
-- duplicate_visible = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- duplicate = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- modified = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- modified_selected = {
-- fg = { attribute = "fg", highlight = "Normal" },
-- bg = { attribute = "bg", highlight = "Normal" },
-- },
-- modified_visible = {
-- fg = { attribute = "fg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- separator = {
-- fg = { attribute = "bg", highlight = "TabLine" },
-- bg = { attribute = "bg", highlight = "TabLine" },
-- },
-- separator_selected = {
-- fg = { attribute = "bg", highlight = "Normal" },
-- bg = { attribute = "bg", highlight = "Normal" },
-- },
-- -- separator_visible = {
-- -- guifg = {attribute='bg',highlight='TabLine'},
-- -- guibg = {attribute='bg',highlight='TabLine'}
-- -- },
-- indicator_selected = {
-- fg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" },
-- bg = { attribute = "bg", highlight = "Normal" },
-- },
-- },
-- }
EOF
" I want to highlight nginx config
autocmd BufRead,BufNewFile *.conf set filetype=nginx
" If last position is valid, just jump to that position.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ execute "normal! g`\"" |
\ endif
let mapleader = '-'
nnoremap <leader>f <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>g <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>b <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>h <cmd>lua require('telescope.builtin').help_tags()<cr>
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
autocmd Filetype lua setlocal iskeyword+=:
autocmd Filetype lua setlocal iskeyword+=\.
autocmd FileType go setlocal noexpandtab
autocmd InsertLeave,WinEnter * set cursorline
autocmd InsertEnter,WinLeave * set nocursorline
noremap <leader>gn :GitGutterNextHunk<CR>
noremap <leader>gp :GitGutterPrevHunk<CR>
let g:gitgutter_sign_added = '•'
let g:gitgutter_sign_modified = '•'
let g:gitgutter_sign_removed = '•'
let g:gitgutter_sign_removed_first_line = '•'
let g:gitgutter_sign_modified_removed = '•'
" Hack the GitGutter
highlight GitGutterAddDefault ctermfg=2 ctermbg=None guibg=None
highlight GitGutterAddDefault ctermfg=3 ctermbg=None guibg=None
highlight GitGutterDeleteDefault ctermfg=1 ctermbg=None guibg=None
colorscheme dracula
let g:WebDevIconsUnicodeDecorateFolderNodes = 1
function! MyFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype . ' ' . WebDevIconsGetFileTypeSymbol() : 'no ft') : ''
endfunction
function! MyFileformat()
return winwidth(0) > 70 ? (&fileformat . ' ' . WebDevIconsGetFileFormatSymbol()) : ''
endfunction
" floating window
function! DisableExtras()
call nvim_win_set_option(g:float_preview#win, 'number', v:false)
call nvim_win_set_option(g:float_preview#win, 'relativenumber', v:false)
call nvim_win_set_option(g:float_preview#win, 'cursorline', v:false)
endfunction
autocmd User FloatPreviewWinOpen call DisableExtras()
hi TabLine ctermfg=Black ctermbg=Green cterm=NONE
hi TabLineFill ctermfg=Black ctermbg=Green cterm=NONE
hi TabLineSel ctermfg=White ctermbg=DarkBlue cterm=NONE
lua <<EOF
-- Set up nvim-cmp.
vim.opt.termguicolors = true
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.
["<Tab>"] = cmp.mapping(function(fallback)
local luasnip = require("luasnip")
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {"i", "s"}),
}),
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 `/` and `?` (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' }
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['gopls'].setup {
capabilities = capabilities,
cmd = {"gopls", "serve"},
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
single_file_support = true,
}
require'lspconfig'.clangd.setup{}
require'lspconfig'.lua_ls.setup {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
}
vim.api.nvim_create_autocmd('LspAttach', {
desc = 'LSP actions',
callback = function()
local bufmap = function(mode, lhs, rhs)
local opts = {buffer = true}
vim.keymap.set(mode, lhs, rhs, opts)
end
-- Displays hover information about the symbol under the cursor
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
-- Jump to the definition
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
end
})
EOF
autocmd BufWritePre *.go lua vim.lsp.buf.format(nil, 1000)
lua <<EOF
-- default configuration
require('illuminate').configure({
-- providers: provider used to get references in the buffer, ordered by priority
providers = {
'lsp',
'treesitter',
'regex',
},
-- delay: delay in milliseconds
delay = 100,
-- filetype_overrides: filetype specific overrides.
-- The keys are strings to represent the filetype while the values are tables that
-- supports the same keys passed to .configure except for filetypes_denylist and filetypes_allowlist
filetype_overrides = {},
-- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist
filetypes_denylist = {
'dirvish',
'fugitive',
},
-- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist
filetypes_allowlist = {},
-- modes_denylist: modes to not illuminate, this overrides modes_allowlist
-- See `:help mode()` for possible values
modes_denylist = {},
-- modes_allowlist: modes to illuminate, this is overriden by modes_denylist
-- See `:help mode()` for possible values
modes_allowlist = {},
-- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist
-- Only applies to the 'regex' provider
-- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
providers_regex_syntax_denylist = {},
-- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist
-- Only applies to the 'regex' provider
-- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
providers_regex_syntax_allowlist = {},
-- under_cursor: whether or not to illuminate under the cursor
under_cursor = true,
-- large_file_cutoff: number of lines at which to use large_file_config
-- The `under_cursor` option is disabled when this cutoff is hit
large_file_cutoff = nil,
-- large_file_config: config to use for large files (based on large_file_cutoff).
-- Supports the same keys passed to .configure
-- If nil, vim-illuminate will be disabled for large files.
large_file_overrides = nil,
-- min_count_to_highlight: minimum number of matches required to perform highlighting
min_count_to_highlight = 1,
})
EOF
" press <Tab> to expand or jump in a snippet. These can also be mapped separately
" via <Plug>luasnip-expand-snippet and <Plug>luasnip-jump-next.
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>'
" -1 for jumping backwards.
inoremap <silent> <S-Tab> <cmd>lua require'luasnip'.jump(-1)<Cr>
snoremap <silent> <Tab> <cmd>lua require('luasnip').jump(1)<Cr>
snoremap <silent> <S-Tab> <cmd>lua require('luasnip').jump(-1)<Cr>
" For changing choices in choiceNodes (not strictly necessary for a basic setup).
imap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
smap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment