Skip to content

Instantly share code, notes, and snippets.

@zach-is-my-name
Created May 9, 2023 21:15
Show Gist options
  • Save zach-is-my-name/836220f7b5e73c50ea77f57ae87c51dc to your computer and use it in GitHub Desktop.
Save zach-is-my-name/836220f7b5e73c50ea77f57ae87c51dc to your computer and use it in GitHub Desktop.
":set termguicolors
set notermguicolors
set noshowmode
" Appearence
set guicursor=n:blinkwait0-blinkon0-blinkoff0
set guicursor=n-v-c:block,i-ci-ve:block-Cursor/lCursor
set shell=/usr/bin/zsh
filetype plugin indent on " required
"color default
"set t_Co=256
"set laststatus=2
set timeoutlen=500
" General
set nocompatible " be iMproved, required
filetype off " required
set nohlsearch
let loaded_matchit = 0
set noincsearch
set nojoinspaces
set nowildmenu
set noruler
set mouse=a
set hidden
set tabstop=2 shiftwidth=2 expandtab
set breakindent
set splitbelow
set splitright
set showbreak=""
"set paste
"no filename visable
set laststatus=0
set statusline=_
set fillchars+=vert:│
set fillchars+=stl:_
set fillchars+=stlnc:_
set wmw=0
set matchtime=0
let g:repl_config = { 'javascript': { 'cmd': 'node' } }
let g:context_enabled = 0
" vim-obsession configuration
let g:obsession_no_bufenter = 1
" vim-prosession configuration
let g:prosession_dir = $HOME . "/.vim_sessions/"
let g:prosession_on_startup = 0
" Clipboard
vmap <C-c> "+y
inoremap <C-P> <C-R>"
set clipboard=unnamed
set clipboard=unnamedplus
set clipboard^=unnamed,unnamedplus
"Repeat paste in visual mode
xnoremap p pgvy
"Easy cmd
nnoremap ; :
"Easy registers
nnoremap ' "
nnoremap " '
vnoremap ' "
vnoremap " '
"Twilight Toggle
nmap <leader>l :Twilight<CR>
"File/Buffer Info
nnoremap <leader>g 1<C-g>
nmap <M-g> 1<C-g>
"pwd
nnoremap <leader>x :pwd<CR>
"B
cabbrev bd <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Bclose' : 'e')<CR>
"cnext
nn <c-n> :cnext<cr>
map <leader>y :ZenMode<CR><c-l>
" copy current file name (relative/absolute) to system clipboard (Linux version)
if has("gui_gtk") || has("gui_gtk2") || has("gui_gnome") || has("unix")
" relative path (src/foo.txt)
nnoremap <leader>cf :let @+=expand("%")<CR>
" absolute path (/something/src/foo.txt)
nnoremap <leader>ca :let @+=expand("%:p")<CR>
" filename (foo.txt)
nnoremap <leader>ct :let @+=expand("%:t")<CR>
" directory name (/something/src)
nnoremap <leader>cd :let @+=expand("%:p:h")<CR>
endif
" not sure
nnoremap <expr><silent> <leader>, &showtabline ? ":set showtabline=0\<cr>" : ":set showtabline=2\<cr>"
"nnn
nnoremap <leader>5 <cmd>NnnPicker %:p:h<CR>
nnoremap <leader>t <cmd>NnnPicker %:p:h<CR>
nnoremap <M-t> <cmd>NnnPicker %:p:h<CR>
nnoremap <C-t> <cmd>NnnExplorer %:p:h<CR>
:map [[ ?{<CR>w99[{
:map ][ /}<CR>b99]}
:map ]] j0[[%/{<CR>
:map [] k$][%?}<CR>
" surround word with quotes
:nnoremap <Leader>q ciw''<Esc>P
:nnoremap <Leader>qq ciw""<Esc>P
:nnoremap <Leader>qqq daW"=substitute(@@,"'\\\|\"","","g")<CR>P
:vnoremap <Leader>q ciw''<Esc>P
:vnoremap <Leader>qq ciw""<Esc>P
:vnoremap <Leader>qqq daW"=substitute(@@,"'\\\|\"","","g")<CR>P
"paste on line below the cursor
:nmap <Leader>p o<ESC>p<ESC>
:nmap <Leader>P O<ESC>p<ESC>
" insert mode: console.log({<cursor>})
:inoremap <Leader>c console.log({})<Esc>==f}i
" normal mode: put line above the cursor
nmap <S-Enter> O<Esc>
" normal mode: put line below the cursor
nmap <CR> o<Esc>
" save modified files and exit (no prompt)
nmap <Leader>z :confirm xa<CR>
:nn <Leader>so :source ~/.config/nvim/init.vim<CR>
" spectre: search and replace nvim-spectre
nnoremap <leader>S <cmd>lua require('spectre').open()<CR>
" spectre: search current word
nnoremap <leader>sw <cmd>lua require('spectre').open_visual({select_word=true})<CR>
" spectre: search visual current word
vnoremap <leader>s <esc>:lua require('spectre').open_visual()<CR>
" search in current file
nnoremap <leader>sp viw:lua require('spectre').open_file_search()<cr>
" close buffer
nmap <Leader>w ;bd<CR>
" prev buffer
nmap <M-j> :bprev<CR>:f<CR>
" next buffer
nmap <M-k> :bnext<CR>:f<CR>
"prev file
nnoremap <M-a> <C-6>
inoremap <D-a> <C-6>
" zenmode
nmap <M-y> :ZenMode<CR>;mode<CR>
" redraw
nmap <M-h> :redraw<CR>
"open nvim config dir
nn <Leader>v :e ~/.config/nvim<CR>
" toggle cursor
nnoremap <leader>cc :call HideCursorToggle()<CR><c-l>
" nrrw region
vnoremap <leader>r :NR!<CR>
" widen region
nnoremap <leader>4 :WR<CR>
" context.vim (breadcrumbs)
nnoremap <leader>e :ContextToggle<CR>
" format text
vnoremap C-s :Strikethrough<CR>
vnoremap C-u :Underline<CR>
" paste default copy register
xnoremap p "0p
xnoremap p "0p
"Plugin: VimPlug
call plug#begin()
" Declare the list of plugins.
" Editing / Navigation
Plug 'tpope/vim-commentary'
Plug 'andymass/vim-matchup'
Plug 'luukvbaal/nnn.nvim'
Plug 'tpope/vim-unimpaired'
Plug 'machakann/vim-sandwich'
Plug 'vim-scripts/Rename2'
Plug 'folke/which-key.nvim'
" Search / Replace
Plug 'windwp/nvim-spectre'
Plug 'stefandtw/quickfix-reflector.vim'
" 'View' managment
Plug 'wellle/context.vim'
Plug 'folke/twilight.nvim'
Plug 'folke/zen-mode.nvim'
Plug 'chrisbra/NrrwRgn'
Plug 'rbgrouleff/bclose.vim'
Plug 'szw/vim-maximizer'
Plug 'dhruvasagar/vim-zoom'
Plug 'stevearc/aerial.nvim'
Plug 'AndrewRadev/linediff.vim'
" Telescope
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
Plug 'nvim-telescope/telescope-project.nvim'
Plug 'kiyoon/telescope-insert-path.nvim'
Plug 'tpope/vim-obsession'
Plug 'dhruvasagar/vim-prosession'
Plug 'norcalli/nvim-colorizer.lua'
" LSP Support
Plug 'neovim/nvim-lspconfig'
Plug 'onsails/lspkind.nvim'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'VonHeikemen/lsp-zero.nvim'
" Autocompletion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'hrsh7th/cmp-nvim-lua'
" Snippets
Plug 'L3MON4D3/LuaSnip'
Plug 'rafamadriz/friendly-snippets'
" Syntax
Plug 'tomlion/vim-solidity'
Plug 'arzg/vim-colors-xcode'
Plug 'leafgarland/typescript-vim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'fxn/vim-monochrome'
Plug 'hardselius/warlock'
Plug 'danishprakash/vim-yami'
" Marks and Highlights
Plug 'inkarkat/vim-mark'
Plug 'inkarkat/vim-ingo-library'
Plug 'bpstahlman/txtfmt'
Plug 'Pocco81/HighStr.nvim'
" Sessions
Plug 'olimorris/persisted.nvim'
" Repl
Plug 'axvr/zepl.vim'
Plug 'jpalardy/vim-slime'
" Misc
Plug 'yuratomo/w3m.vim'
Plug 'nvim-lua/plenary.nvim'
" Graveyard
"Plug 'ryanoasis/vim-devicons'
"Plug 'nvim-tree/nvim-web-devicons'
"Plug 'azabiong/vim-highlighter'
"Plug 'mikewest/vimroom'
"Plug './Downloads/Tabmerge.vim'
"Plug 'regedarek/ZoomWin'
"Plug 'AndrewRadev/linediff.vim'
"Plug 'mattboehm/vim-unstack'
"Plug 'xolox/vim-session'
"Plug 'preservim/vim-colors-pencil'
"Plug 'xolox/vim-misc'
"Plug 'godlygeek/tabular'
"Plug 'junegunn/fzf.vim'
"Plug 'plasticboy/vim-markdown'
"Plug 'dhruvasagar/vim-prosession'
"Plug 'yegappan/taglist'
"Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
"Plug 'junegunn/fzf.vim'
"Plug 'ms-jpq/coq_nvim', {'branch': 'coq'}
" 9000+ Snippets
"Plug 'ms-jpq/coq.artifacts', {'branch': 'artifacts'}
"Plug 'kyazdani42/nvim-web-devicons'
"Plug 'ActivityWatch/aw-watcher-vim'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()
call plug#helptags()
lua << EOF
require("mason").setup()
require("mason-lspconfig").setup()
EOF
"get the highlight group under the cursor
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunction
command! SynStack call SynStack()
function! HideCursorToggle()
if &guicursor == "n-v-c:block,i-ci-ve:block-Cursor/lCursor"
hi Cursor blend=100
set guicursor+=a:Cursor/lCursor
elseif &guicursor == "n-v-c:block,i-ci-ve:block-Cursor/lCursor,a:Cursor/lCursor"
hi Cursor blend=30
set guicursor=n-v-c:block,i-ci-ve:block-Cursor/lCursor
endif
endfunction
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
" Get the current visual block for search and replaces
" This function passed the visual block through a string escape function
" Based on this - https://stackoverflow.com/questions/676600/vim-replace-selected-text/677918#677918
function! GetVisual() range
" Save the current register and clipboard
let reg_save = getreg('"')
let regtype_save = getregtype('"')
let cb_save = &clipboard
set clipboard&
" Put the current visual selection in the " register
normal! ""gvy
let selection = getreg('"')
" Put the saved registers and clipboards back
call setreg('"', reg_save, regtype_save)
let &clipboard = cb_save
"Escape any special characters in the selection
let escaped_selection = EscapeString(selection)
return escaped_selection
endfunction
" Start the find and replace command across the entire file
vmap <C-r> <Esc>:%s/<c-r>=GetVisual()<cr>//g<left><left>
" underline text, strikethrough, etc, selected text using combining diacritics
command! -range -nargs=0 Overline call s:CombineSelection(<line1>, <line2>, '0305')
command! -range -nargs=0 Underline call s:CombineSelection(<line1>, <line2>, '0332')
command! -range -nargs=0 DoubleUnderline call s:CombineSelection(<line1>, <line2>, '0333')
command! -range -nargs=0 Strikethrough call s:CombineSelection(<line1>, <line2>, '0336')
function! s:CombineSelection(line1, line2, cp)
execute 'let char = "\u'.a:cp.'"'
execute a:line1.','.a:line2.'s/\%V[^[:cntrl:]]/&'.char.'/ge'
endfunction
" Plugin: Mark
let g:mw_no_mappings = 1
nmap <leader>m <Plug>MarkSet
nmap <Leader>N <Plug>MarkAllClear
" Plugin: Vimroom
let g:vimroom_width=100
let g:vimroom_sidebar_height=0
"Slime with tmux
let g:slime_target = "tmux"
"Syntax and color
syntax enable
syntax on
set background="dark"
colorscheme 1989
set termguicolors
"hi EndOfBuffer ctermbg=None ctermfg=249
if exists("g:neovide")
set background=light
colorscheme xcodelight
set guifont=DejaVu\ Sans\ Mono:Consolas:h16
let g:neovide_cursor_animation_length=0
let g:neovide_cursor_trail_size=0
let g:neovide_fullscreen=v:true
:hi Cursor guifg=#8787af guibg=#8787af
:hi Folded guifg=#deecf4 guibg=#FFFFFF
else
:hi Folded guifg=#3e3e3e
endif
"disable automatic comment character insertion
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
autocmd VimEnter * ZenMode
"when you save a file in nonexistent directory, Vim will ask you if you want the directory created and then create it.
"https://travisjeffery.com/b/2011/11/saving-files-in-nonexistent-directories-with-vim/
augroup vimrc-auto-mkdir
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force)
if !isdirectory(a:dir)
\ && (a:force
\ || input("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction
augroup END
"highlight json comments
autocmd FileType json syntax match Comment +\/\/.\+$+
"no match in insert mode
au InsertEnter * NoMatchParen
au InsertLeave * DoMatchParen
" Clear cmd line message
function! s:empty_message(timer)
if mode() ==# 'n'
echon ''
endif
endfunction
augroup cmd_msg_cls
autocmd!
autocmd CmdlineLeave : call timer_start(1500, funcref('s:empty_message'))
augroup END
" Save session on opening or switching buffers
autocmd BufReadPost,BufNewFile,BufEnter * silent! ProsessionSave
hi VertSplit guibg=NONE ctermbg=NONE
hi StatusLineNC guibg=NONE ctermbg=NONE
hi StatusLine guibg=NONE ctermbg=NONE
hi IncSearch ctermbg=NONE guibg=#ff005f
hi TSWarning ctermbg=NONE guibg=#ff005f
hi Todo ctermbg=NONE guibg=#ff005f
hi Pmenu guibg=#3D3A4A
"matchparen hl
hi MatchParen guibg=#d75fd7
nnoremap <M-8> :lua require'telescope.builtin'.grep_string({initial_mode = "normal"})<cr>
nnoremap <M-/> <cmd>Telescope live_grep<cr>
nnoremap <leader>f <cmd>lua require('telescope.builtin').find_files({sort_lastused = true})<cr>
nnoremap <Leader>p <cmd>lua require'telescope'.extensions.project.project{}<cr>
silent! execute "set <M-.>=\<Esc>."
nnoremap <M-b> <cmd> lua require('telescope.builtin').buffers({initial_mode = "normal", sort_mru = true, sort_lastused = true, ignore_current_buffer = true })<cr>
nnoremap <M-.> :lua require'telescope.builtin'.resume{}<cr>
nnoremap <M-G> :lua require('telescope.builtin').git_commits{}<cr>
nnoremap <M-B> :lua require('telescope.builtin').git_bcommits{}<cr>
nnoremap <leader>b :lua require('telescope.builtin').git_branches{}<cr>
nnoremap <M-S> :lua require('telescope.builtin').git_status{}<cr>
nnoremap <leader>\ :lua require('telescope.builtin').current_buffer_fuzzy_find{}<cr>
nnoremap <M-c> :lua require('telescope.builtin').colorscheme{}<cr>
"nnoremap <leader>e :Telescope aerial<cr>
lua <<EOF
require('telescope').setup{
defaults = {
color_devicons = false,
file_ignore_patters = {node_modules},
layout_strategy = 'vertical',
layout_config = { height = .95, width= .95 },
disable_devicons = true
},
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
}, -- the default case_mode is "smart_ca
--aerial = {
--sorting_strategy="descending"
--}
},
pickers = {
colorscheme = {
enable_preview = true
}
-- find_files = {
-- disable_devicons = true
-- },
}
}
require('telescope').load_extension('fzf')
require'telescope'.load_extension('project')
--require('telescope').load_extension('aerial')
--require('telescope.builtin').lsp_document_symbols({sorting_strategy="descending"})
--require('telescope.builtin').current_buffer_fuzzy_find({sorting_strategy="decesnding"})
-- insert path from picker
local path_actions = require('telescope_insert_path')
require('telescope').setup {
defaults = {
mappings = {
n = {
["[i"] = path_actions.insert_reltobufpath_i_visual,
["[I"] = path_actions.insert_reltobufpath_I_visual,
["[a"] = path_actions.insert_reltobufpath_a_visual,
["[A"] = path_actions.insert_reltobufpath_A_visual,
["[o"] = path_actions.insert_reltobufpath_o_visual,
["[O"] = path_actions.insert_reltobufpath_O_visual,
["]i"] = path_actions.insert_abspath_i_visual,
["]I"] = path_actions.insert_abspath_I_visual,
["]a"] = path_actions.insert_abspath_a_visual,
["]A"] = path_actions.insert_abspath_A_visual,
["]o"] = path_actions.insert_abspath_o_visual,
["]O"] = path_actions.insert_abspath_O_visual,
["{i"] = path_actions.insert_reltobufpath_i_insert,
["{I"] = path_actions.insert_reltobufpath_I_insert,
["-i"] = path_actions.insert_reltobufpath_i_normal,
["-I"] = path_actions.insert_reltobufpath_I_visual,
}
}
}
}
EOF
lua << EOF
--ZenMode
require("zen-mode").setup {
window = {
backdrop = 1, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal
-- height and width can be:
-- * an absolute number of cells when > 1
-- * a percentage of the width / height of the editor when <= 1
-- * a function that returns the width or the height
width = 80, -- width of the Zen window
height = 1, -- height of the Zen window
-- by default, no options are changed for the Zen window
-- uncomment any of the options below, or add other vim.wo options you want to apply
options = {
-- signcolumn = "no", -- disable signcolumn
-- number = false, -- disable number column
-- relativenumber = false, -- disable relative numbers
-- cursorline = false, -- disable cursorline
-- cursorcolumn = false, -- disable cursor column
-- foldcolumn = "0", -- disable fold column
-- list = false, -- disable whitespace characters
},
},
plugins = {
-- disable some global vim options (vim.o...)
-- comment the lines to not apply the options
options = {
enabled = true,
ruler = false, -- disables the ruler text in the cmd line area
showcmd = false, -- disables the command in the last line of the screen
},
twilight = { enabled = false }, -- enable to start Twilight when zen mode opens
gitsigns = { enabled = false }, -- disables git signs
tmux = { enabled = false }, -- disables the tmux statusline
-- this will change the font size on kitty when in zen mode
-- to make this work, you need to set the following kitty options:
-- - allow_remote_control socket-only
-- - listen_on unix:/tmp/kitty
kitty = {
enabled = false,
font = "+4", -- font size increment
},
},
-- callback where you can add custom code when the Zen window opens
on_open = function(win)
end,
-- callback where you can add custom code when the Zen window closes
on_close = function()
end,
}
EOF
lua << EOF
local builtin = require("nnn").builtin
require("nnn").setup({
explorer = {
width = 20,
tabs = false
},
mappings = {
{ "<C-s>", builtin.open_in_split }, -- open file(s) in split
{ "<C-v>", builtin.open_in_vsplit }, -- open file(s) in vertical split
{ "<C-p>", builtin.open_in_preview }, -- open file in preview split keeping nnn focused
{ "<C-y>", builtin.copy_to_clipboard }, -- copy file(s) to clipboard
{ "<C-w>", builtin.cd_to_path }, -- cd to file directory
{ "<C-e>", builtin.populate_cmdline }, -- populate cmdline (:) with file(s)
}
}
)
EOF
lua << EOF
local lsp = require('lsp-zero')
lsp.set_preferences({
suggest_lsp_servers = true,
setup_servers_on_start = true,
set_lsp_keymaps = true,
configure_diagnostics = false,
cmp_capabilities = true,
manage_nvim_cmp = true,
call_servers = 'local',
sign_icons = {
error = '✘',
warn = '▲',
hint = '⚑',
info = ''
}
})
lsp.setup()
vim.diagnostic.hide()
vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end
lsp.on_attach(function(client, bufnr)
--require("aerial").on_attach(client, bufnr)
end)
EOF
lua << EOF
require("persisted").setup({
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
command = "VimLeavePre", -- the autocommand for which the session is saved
use_git_branch = false, -- create session files based on the branch of the git enabled repository
autosave = true, -- automatically save session files when exiting Neovim
autoload = true, -- automatically load the session for the cwd on Neovim startup
allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
before_save = nil, -- function to run before the session is saved to disk
after_save = nil, -- function to run after the session is saved to disk
after_source = nil, -- function to run after the session is sourced
telescope = { -- options for the telescope extension
before_source = nil, -- function to run before the session is sourced via telescope
after_source = nil, -- function to run after the session is sourced via telescope
},
})
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment