Skip to content

Instantly share code, notes, and snippets.

@sei0o
Created August 19, 2022 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sei0o/9fad8356b11a4f018a1c9e7615b6a1bd to your computer and use it in GitHub Desktop.
Save sei0o/9fad8356b11a4f018a1c9e7615b6a1bd to your computer and use it in GitHub Desktop.
neovim config as of Aug 19, 2022
set completeopt=menuone,noinsert,noselect
set shortmess+=c
"" lightline
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ],
\ 'right': [
\ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileencoding', 'filetype']
\ ],
\ },
\ 'tabline': {
\ 'left': [ ['buffers'] ],
\ 'right': [ ['close'] ]
\ },
\ 'component_expand': {
\ 'buffers': 'lightline#bufferline#buffers',
\ },
\ 'component_type': {
\ 'buffers': 'tabsel',
\ 'linter_checking': 'right',
\ 'linter_infos': 'right',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'right',
\ }
\ }
call plug#begin(expand('~/.config/nvim/plugged'))
" ================= looks and GUI stuff ================== "{{{
Plug 'luochen1990/rainbow' " rainbow parenthesis
Plug 'hzchirs/vim-material' " material color themes
Plug 'gregsexton/MatchTag' " highlight matching html tags
Plug 'Jorengarenar/vim-MvVis' " move visual selection
" ================= Functionalities ================= "{{{
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " fzf itself
Plug 'junegunn/fzf.vim' " fuzzy search integration
Plug 'honza/vim-snippets' " actual snippets
Plug 'Yggdroot/indentLine' " show indentation lines
Plug 'numirias/semshi', {'do': ':UpdateRemotePlugins'} " better python
Plug 'tpope/vim-commentary' " better commenting
Plug 'tpope/vim-fugitive' " git support
Plug 'psliwka/vim-smoothie' " some very smooth ass scrolling
Plug 'tpope/vim-eunuch' " run common Unix commands inside Vim
Plug 'machakann/vim-sandwich' " make sandwiches
Plug 'itchyny/lightline.vim'
Plug 'cespare/vim-toml'
Plug 'rust-lang/rust.vim'
Plug 'mengelbrecht/lightline-bufferline'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-unimpaired'
Plug 'nvim-lua/plenary.nvim'
Plug 'windwp/nvim-spectre'
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/nvim-lsp-installer'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
Plug 'simrat39/rust-tools.nvim'
Plug 'akinsho/flutter-tools.nvim'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
"Plug 'rlue/vim-barbaric'
Plug 'h-hg/fcitx.nvim'
call plug#end()
"}}}
" ==================== general config ======================== "{{{
set termguicolors " Opaque Background
set mouse=a " enable mouse scrolling
"set clipboard+=unnamedplus " use system clipboard by default
set tabstop=2 softtabstop=2 shiftwidth=2 autoindent " tab width
set expandtab smarttab " tab key actions
set incsearch ignorecase smartcase hlsearch " highlight text while searching
set list listchars=trail:»,tab:»- " use tab to navigate in list mode
set fillchars+=vert:\▏ " requires a patched nerd font (try FiraCode)
set wrap breakindent " wrap long lines to the width set by tw
set encoding=utf-8 " text encoding
set number " enable numbers on the left
set relativenumber " current line is 0
set title " tab title as file name
set noshowmode " dont show current mode below statusline
set noshowcmd " to get rid of display of last command
set conceallevel=2 " set this so we wont break indentation plugin
set splitright " open vertical split to the right
set splitbelow " open horizontal split to the bottom
set tw=90 " auto wrap lines that are longer than that
set emoji " enable emojis
set history=1000 " history limit
set backspace=indent,eol,start " sensible backspacing
set undofile " enable persistent undo
set undodir=/tmp " undo temp file directory
set foldlevel=0 " open all folds by default
set inccommand=nosplit " visual feedback while substituting
set showtabline=0 " always show tabline
set laststatus=2
set grepprg=rg\ --vimgrep " use rg as default grepper
" performance tweaks
set cursorline
set nocursorcolumn
set scrolljump=5
set lazyredraw
set redrawtime=10000
set synmaxcol=180
set re=1
set showtabline=2
" required by coc
set hidden
set cmdheight=1
set updatetime=300
set shortmess+=c
set signcolumn=yes
" Themeing
let g:material_style = 'oceanic'
colorscheme vim-material
hi Pmenu guibg='#00010a' guifg=white " popup menu colors
hi Comment gui=italic cterm=italic " italic comments
hi Search guibg=#b16286 guifg=#ebdbb2 gui=NONE " search string highlight color
hi NonText guifg=bg " mask ~ on empty lines
hi clear CursorLineNr " use the theme color for relative number
hi CursorLineNr gui=bold " make relative number bold
hi SpellBad guifg=NONE gui=bold,undercurl " misspelled words
" colors for git (especially the gutter)
hi DiffAdd guibg=#0f111a guifg=#43a047
hi DiffChange guibg=#0f111a guifg=#fdd835
hi DiffRemoved guibg=#0f111a guifg=#e53935
" ======================== Plugin Configurations ======================== "{{{
"" built in plugins
let loaded_netrw = 0
let loaded_netrwPlugin = 1
let g:omni_sql_no_default_maps = 1 " disable sql omni completion
let g:loaded_python_provider = 0
let g:loaded_perl_provider = 0
let g:loaded_ruby_provider = 0
if glob('~/.python3') != ''
let g:python3_host_prog = expand('~/.python3/bin/python')
else
let g:python3_host_prog = systemlist('which python3')[0]
endif
" rust.vim
let g:rustfmt_autosave = 1
" indentLine
let g:indentLine_char_list = ['▏', '¦', '┆', '┊']
let g:indentLine_setColors = 0
let g:indentLine_setConceal = 0 " actually fix the annoying markdown links conversion
" rainbow brackets
let g:rainbow_active = 1
" semshi settings
let g:semshi#error_sign = v:false " let ms python lsp handle this
"" FZF
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let g:fzf_layout = {'up':'~90%', 'window': { 'width': 0.9, 'height': 0.9,'yoffset':0.5,'xoffset': 0.5, 'border': 'sharp' } }
let g:fzf_tags_command = 'ctags -R'
let $FZF_DEFAULT_OPTS = '--layout=reverse --inline-info'
let $FZF_DEFAULT_COMMAND = "rg --files --hidden --glob '!.git/**' --glob '!build/**' --glob '!.dart_tool/**' --glob '!.idea' --glob '!node_modules'"
"}}}
" ======================== Commands ============================= "{{{
au BufEnter * set fo-=c fo-=r fo-=o " stop annoying auto commenting on new lines
au FileType help wincmd L " open help in vertical split
au BufWritePre * :%s/\s\+$//e " remove trailing whitespaces before saving
" enable spell only if file type is normal text
let spellable = ['markdown', 'gitcommit', 'txt', 'text', 'liquid', 'rst']
autocmd BufEnter * if index(spellable, &ft) < 0 | set nospell | else | set spell | endif
" fzf if passed argument is a folder
augroup folderarg
" change working directory to passed directory
autocmd VimEnter * if argc() != 0 && isdirectory(argv()[0]) | execute 'cd' fnameescape(argv()[0]) | endif
" start fzf on passed directory
autocmd VimEnter * if argc() != 0 && isdirectory(argv()[0]) | execute 'Files ' fnameescape(argv()[0]) | endif
augroup END
" Return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" python renaming
autocmd FileType python nnoremap <leader>rn :Semshi rename <CR>
" files in fzf
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--inline-info']}), <bang>0)
" advanced grep
command! -nargs=* -bang Rg call RipgrepFzf(<q-args>, <bang>0)
"}}}
" ================== Custom Functions ===================== "{{{
" advanced grep(faster with preview)
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
" check if last inserted char is a backspace (used by coc pmenu)
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" ======================== Custom Mappings ====================== "{{{
"" the essentials
let mapleader=","
nnoremap ; :
nmap \ <leader>q
nmap <leader>q :bd<CR>
nmap <leader>w :w<CR>
"nmap <Tab> :bnext<CR>
"nmap <S-Tab> :bprevious<CR>
nnoremap <silent> <C-PageUp> :bprev<CR>
nnoremap <silent> <C-PageDown> :bnext<CR>
noremap <leader>e :PlugInstall<CR>
noremap <C-q> :q<CR>
" new line in normal mode and back
map <Enter> o<ESC>
map <S-Enter> O<ESC>
" use a different register for delete and paste
"nnoremap d "_d
"vnoremap d "_d
"vnoremap p "_dP
"nnoremap x "_x
" emulate windows copy, cut behavior
vnoremap <LeftRelease> "+y<LeftRelease>
vnoremap <C-c> "+y<CR>
vnoremap <C-x> "+d<CR>
" switch between splits using ctrl + {h,j,k,l}
inoremap <C-h> <C-\><C-N><C-w>h
inoremap <C-j> <C-\><C-N><C-w>j
inoremap <C-k> <C-\><C-N><C-w>k
inoremap <C-l> <C-\><C-N><C-w>l
nnoremap <C-h> <C-w>h
noremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" disable hl with 2 esc
noremap <silent><esc> <esc>:noh<CR><esc>
" trim white spaces
nnoremap <F2> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
"" FZF
nnoremap <C-p> :Files<CR>
nmap <leader>b :Buffers<CR>
nmap <leader>c :Commands<CR>
nmap <leader>t :BTags<CR>
nmap <C-f> :Rg<CR>
nmap <leader>gc :Commits<CR>
nmap <leader>gs :GFiles?<CR>
nmap <leader>sh :History/<CR>
" show mapping on all modes with F1
nmap <F1> <plug>(fzf-maps-n)
imap <F1> <plug>(fzf-maps-i)
vmap <F1> <plug>(fzf-maps-x)
" fugitive mappings
nmap <leader>gd :Gdiffsplit<CR>
nmap <leader>gb :Git blame<CR>
" nvim-spectre
nnoremap <leader>S :lua require('spectre').open()<CR>
" search current word
nnoremap <leader>sw :lua require('spectre').open_visual({select_word=true})<CR>
vnoremap <leader>s :lua require('spectre').open_visual()<CR>
" search in current file
nnoremap <leader>sp viw:lua require('spectre').open_file_search()<cr>
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <leader>r <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <leader>f <cmd>lua vim.lsp.buf.formatting()<CR>
" Debugging
nnoremap <leader>db <cmd>lua require('dap').toggle_breakpoint()<CR>
nnoremap <leader>dc <cmd>lua require('dap').continue()<CR>
nnoremap <leader>ds <cmd>lua require('dap').step_into()<CR>
nnoremap <leader>da <cmd>lua require('dap').run({
autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.diagnostic.open_float()
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.diagnostic.goto_next()<CR>
" Configure LSP through rust-tools.nvim plugin.
" rust-tools will configure and enable certain LSP features for us.
" See https://github.com/simrat39/rust-tools.nvim#configuration
lua <<EOF
local nvim_lsp = require'lspconfig'
local opts = {
tools = {
autoSetHints = true,
hover_with_actions = true,
inlay_hints = {
show_parameter_hints = true,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
},
}
}
},
}
require('rust-tools').setup(opts)
require("flutter-tools").setup{}
local cmp = require'cmp'
cmp.setup({
snippet = {
-- expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body)
-- end,
},
mapping = {
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = 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.Insert,
select = true,
})
},
sources = {
{ name = 'nvim_lsp' },
--{ name = 'vsnip' },
--{ name = 'path' },
--{ name = 'buffer' },
},
})
local lspi = require 'nvim-lsp-installer'
lspi.on_server_ready(function(server)
local opts = {}
server:setup(opts)
end)
local dap = require 'dap'
dap.adapters.lldb = {
type = 'executable',
command = '/usr/bin/lldb-vscode', -- adjust as needed
name = "lldb"
}
dap.configurations.rust = {
{
name = "Launch",
type = "lldb",
request = 'launch',
program = '${workspaceFolder}/target/debug/${workspaceFolderBasename}',
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},
runInTerminal = false,
},
}
-- dap.configurations.c = dap.configurations.cpp
local dapui = require 'dapui'
dapui.setup({
icons = { expanded = "▾", collapsed = "▸" },
mappings = {
expand = { "<CR>", "<2-LeftMouse>" },
open = "o",
remove = "d",
edit = "e",
repl = "r",
},
sidebar = {
-- You can change the order of elements in the sidebar
elements = {
-- Provide as ID strings or tables with "id" and "size" keys
{
id = "scopes",
size = 0.25, -- Can be float or integer > 1
},
{ id = "breakpoints", size = 0.25 },
{ id = "stacks", size = 0.25 },
{ id = "watches", size = 00.25 },
},
size = 40,
position = "left", -- Can be "left", "right", "top", "bottom"
},
tray = {
elements = { "repl" },
size = 10,
position = "bottom", -- Can be "left", "right", "top", "bottom"
},
floating = {
max_height = nil, -- These can be integers or a float between 0 and 1.
max_width = nil, -- Floats will be treated as percentage of your screen.
border = "single", -- Border style. Can be "single", "double" or "rounded"
mappings = {
close = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
})
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment