Skip to content

Instantly share code, notes, and snippets.

@nachiketkanore
Created December 6, 2021 18:16
Show Gist options
  • Save nachiketkanore/b0d6f59f19845cdce89a9125265f380b to your computer and use it in GitHub Desktop.
Save nachiketkanore/b0d6f59f19845cdce89a9125265f380b to your computer and use it in GitHub Desktop.
-----------------------------------------------------------
-- Neovim settings
-----------------------------------------------------------
-----------------------------------------------------------
-- Neovim API aliases
-----------------------------------------------------------
--local map = vim.api.nvim_set_keymap -- set global keymap
local cmd = vim.cmd -- execute Vim commands
local exec = vim.api.nvim_exec -- execute Vimscript
local fn = vim.fn -- call Vim functions
local g = vim.g -- global variables
local opt = vim.opt -- global/buffer/windows-scoped options
-- testing issue
vim.lsp.set_log_level('debug')
-----------------------------------------------------------
-- General
-----------------------------------------------------------
opt.mouse = 'a' -- enable mouse support
opt.clipboard = 'unnamedplus' -- copy/paste to system clipboard
opt.swapfile = false -- don't use swapfile
-----------------------------------------------------------
-- Neovim UI
-----------------------------------------------------------
opt.number = true -- show line number
opt.relativenumber = true
opt.showmatch = true -- highlight matching parenthesis
opt.foldmethod = 'marker' -- enable folding (default 'foldmarker')
-- opt.colorcolumn = '80' -- line lenght marker at 80 columns
opt.splitright = true -- vertical split to the right
opt.splitbelow = true -- horizontal split to the bottom
opt.ignorecase = true -- ignore case letters when search
opt.smartcase = true -- ignore lowercase for the whole pattern
opt.linebreak = true -- wrap on word boundary
opt.hlsearch = false
-- gruvbox settings
g.gruvbox_contrast_dark='hard'
g.gruvbox_contrast_light='hard'
g.gruvbox_invert_selection='0'
-- remove whitespace on save
cmd [[au BufWritePre * :%s/\s\+$//e]]
-- highlight on yank
exec([[
augroup YankHighlight
autocmd!
autocmd TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=700}
augroup end
]], false)
-----------------------------------------------------------
-- Memory, CPU
-----------------------------------------------------------
opt.hidden = true -- enable background buffers
opt.history = 100 -- remember n lines in history
opt.lazyredraw = true -- faster scrolling
opt.synmaxcol = 240 -- max column for syntax highlight
-----------------------------------------------------------
-- Colorscheme
-----------------------------------------------------------
opt.termguicolors = true -- enable 24-bit RGB colors
-- cmd [[colorscheme rose-pine]]
cmd [[colorscheme gruvbox]]
-----------------------------------------------------------
-- Tabs, indent
-----------------------------------------------------------
opt.expandtab = true -- use spaces instead of tabs
opt.shiftwidth = 4 -- shift 4 spaces when tab
opt.tabstop = 4 -- 1 tab == 4 spaces
opt.smartindent = true -- autoindent new lines
opt.smarttab = true
opt.softtabstop = 4
-- don't auto commenting new lines
cmd [[au BufEnter * set fo-=c fo-=r fo-=o]]
-- remove line lenght marker for selected filetypes
cmd [[autocmd FileType text,markdown,html,xhtml,javascript setlocal cc=0]]
-- 4 spaces for selected filetypes
cmd [[
autocmd FileType xml,html,xhtml,css,scss,javascript,lua,yaml setlocal shiftwidth=4 tabstop=4
]]
-----------------------------------------------------------
-- Compile and Run shortcuts
-----------------------------------------------------------
cmd [[
autocmd filetype python nnoremap <C-c> :w <bar> exec '!python3 '.shellescape('%')<CR>
]]
cmd [[ autocmd filetype rust nnoremap <C-c> :w <bar> exec '!rustc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR> ]]
cmd [[ autocmd filetype c nnoremap <C-c> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
]]
cmd [[ command GO :w <bar> !g++ -D DEBUG -std=c++17 % -o %:r && ./%:r < in ]]
cmd [[ autocmd filetype cpp nnoremap <C-c> :w <bar> exec '!g++ -std=c++17 '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR> ]]
cmd [[ autocmd BufNewFile *.cpp 0r ~/.template/simple.cpp ]]
cmd [[ command GB :colorscheme gruvbox ]]
cmd [[ command RP :colorscheme rose-pine ]]
-----------------------------------------------------------
-- Autocompletion
-----------------------------------------------------------
-- insert mode completion options
opt.completeopt = 'menuone,noselect'
-----------------------------------------------------------
-- Terminal
-----------------------------------------------------------
-- open a terminal pane on the right using :Term
cmd [[command Term :botright vsplit term://$SHELL]]
-- Terminal visual tweaks
--- enter insert mode when switching to terminal
--- close terminal buffer on process exit
cmd [[
autocmd TermOpen * setlocal listchars= nonumber norelativenumber nocursorline
autocmd TermOpen * startinsert
autocmd BufLeave term://* stopinsert
]]
-----------------------------------------------------------
-- Startup
-----------------------------------------------------------
-- disable builtins plugins
local disabled_built_ins = {
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"gzip",
"zip",
"zipPlugin",
"tar",
"tarPlugin",
"getscript",
"getscriptPlugin",
"vimball",
"vimballPlugin",
"2html_plugin",
"logipat",
"rrhelper",
"spellfile_plugin",
"matchit"
}
for _, plugin in pairs(disabled_built_ins) do
g["loaded_" .. plugin] = 1
end
-- disable nvim intro
-- opt.shortmess:append "sI"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment