From 5dae4d1a1a2a8fd3be3f4c0f6c92b9e74e432bb1 Mon Sep 17 00:00:00 2001 From: Linnnus Date: Fri, 8 Sep 2023 22:15:22 +0200 Subject: Import old init.vim --- home/neovim/default.nix | 4 + home/neovim/init.vim | 204 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 home/neovim/init.vim (limited to 'home') diff --git a/home/neovim/default.nix b/home/neovim/default.nix index 883c170..495da04 100644 --- a/home/neovim/default.nix +++ b/home/neovim/default.nix @@ -12,6 +12,10 @@ programs.neovim = { enable = true; + # Import my existing config. I've been working on this for years and when + # my enthusiasm for Nix eventually dies off, I want to take it with me. + extraConfig = builtins.readFile ./init.vim; + # Typing `vi`, `vim`, or `vimdiff` will also run neovim. viAlias = true; vimAlias = true; diff --git a/home/neovim/init.vim b/home/neovim/init.vim new file mode 100644 index 0000000..11de289 --- /dev/null +++ b/home/neovim/init.vim @@ -0,0 +1,204 @@ +" Settings +""""""""""""""""""""""""""" + +" Leave boomer mode +set nocompatible + +set history=1000 + +" Backspace in insert mode +set backspace=indent,eol,start + +" Hide buffer when abandoned (you can gd away, etc) +set hid + +" Searching +" NOTE: ignorecase and smartcase must be used together (see :h 'smartcase') +set incsearch gdefault ignorecase smartcase nohlsearch + +" Only auto-continue comments when i_ is pressed (not n_o) +" Must be set after :filetype-plugin-on +filetype plugin indent on +au FileType * setlocal fo-=o fo+=r + +" Enable syntax highlighting +syn on + +" Colorscheme +au VimEnter * ++nested colorscheme ansi_linus + +" Persistent undo +set undofile + +" Line numbers +set number relativenumber + +" Improve macro performance +set lazyredraw + +" Show matching brackets +set showmatch +set matchtime=2 + +set listchars=tab:>-,eol:$,space:.,trail:@,nbsp:% + +" Enable mouse input +set mouse=a + +" sussy sus the sussy sus +set nowrap + +" Mappings +""""""""""""""""""""""""""" + +let g:mapleader = "\" + +" Some keys are hard to press with the Danish layout. Luckily, we have some +" spare keys! Note that ctrl and esc are swapped at the OS level. +nnoremap æ $ +nnoremap Æ 0 + +" Switching windows +" TODO: make this work with iTerm2 panes +nnoremap +nnoremap +nnoremap +nnoremap +tnoremap +tnoremap +tnoremap +tnoremap + +" Resize windows +nnoremap + + +nnoremap - - + +" Switching tabs +nnoremap tt :tabnext +nnoremap tn :tabnew +nnoremap to :tabonly +nnoremap tc :tabclose +nnoremap tm :tabmove +" Just use gt and gT +" nnoremap tl :tabn +" nnoremap th :tabN +nnoremap t :tabl +nnoremap t :tabr + +" Fast macros (qq to record) +nnoremap Q @q +vnoremap Q :norm! @q + +" Make Y act like C and D +nnoremap y$ +vnoremap $y + +" Indent using tab key +nnoremap >l +nnoremap >gv +vnoremap +noremap! +noremap! +noremap! + +" Toggle showing 'listchars' +nnoremap l :set list! + +" Escape in terminal mode +tnoremap + +" Replace f and t with vim-sneak's version +let g:sneak#s_next = 1 +let g:sneak#use_ic_scs = 1 +map f Sneak_f +map F Sneak_F +map t Sneak_t +map T Sneak_T + +" Join to end of line below +" This is already used by the window switching mappings +" nnoremap ddpkJ + +" Commands +""""""""""""""""""""""""""" + +" Create a temporary buffer +" NOTE: relied on by other commands +command Temp new | setlocal buftype=nofile bufhidden=wipe noswapfile nomodified nobuflisted +command TempTab tabnew | setlocal buftype=nofile bufhidden=wipe noswapfile nomodified nobuflisted + +" Reverse lines +command! -bar -range=% Reverse ,g/^/m-1|nohl + +" Redraw screen +" CTRL-L mapping is used in other thing +command Redraw norm! + +" Run buffer contents as vimscript +command! -bar -range=% Run execute 'silent!' . . ',' . . 'y|@"' + +" Output the result of a command to the buf +command! -nargs=+ -complete=command Output + \ redir => output | + \ silent execute | + \ redir END | + \ tabnew | + \ setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified | + \ silent put=output | + \ if =~ ':!' | + \ silent 1,2delete _ | + \ else | + \ silent 1,4delete _ | + \ endif + +" Copy buffer to system clipboard +command! Copy silent w !pbcopy + +" Copy the location of the current file +command! CopyDir !echo %:r | pbcopy + +" View in-memory changes before writing to disk +command! DiffOnDisk + \ let orig_filetype=&ft | + \ vert new | + \ read ++edit # | 0d_ | + \ setlocal bt=nofile bh=wipe nobl noswf ro | + \ let &l:filetype = orig_filetype | + \ diffthis | + \ wincmd p | + \ diffthis + +" Miscellaneous +""""""""""""""""""""""""""" + +" Show the color column only if insert mode (and only if cc is set) +augroup ShowCCInInsertMode + au! + au InsertEnter * if &tw != 0 | let &cc = &tw + 1 | endif + au InsertLeave * let &cc = 0 +augroup END + +" Auto-refresh vim config +" au BufWritePost $XDG_CONFIG_HOME/*.{vim,lua} so % + +" Enter insert mode when entering terminals +au BufEnter term://* norm! i + +" Jump to last editing location when opening files +au BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal! g'\"" | + \ endif + +" FIXME: disable in insertmode +augroup HighlightSusWhitespace + au! + " Whenever a colorscheme clears the highlighting, re-add our own rule + au ColorScheme * hi SusWhitespace ctermbg=red guibg=red + " Whenever a new window is created, create our matches + au VimEnter,WinNew * match SusWhitespace /\s\+$/ + \ | 2match SusWhitespace /\%u00A0/ +augroup END -- cgit v1.2.3