From 901df5cef417af56e421ec0344e6926651da7599 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Fri, 31 Oct 2025 09:18:34 +0100 Subject: [PATCH] fix(vim): make windows compatible --- .vimrc | 74 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/.vimrc b/.vimrc index a531325..c749c5b 100644 --- a/.vimrc +++ b/.vimrc @@ -1,4 +1,9 @@ " vim: set foldmethod=marker: +" {{{1 Platform Detection + +let s:is_windows = has('win32') || has('win64') +let s:is_unix = has('unix') + " {{{1 Global Variables let g:skip_defaults_vim = 1 @@ -18,11 +23,15 @@ let g:netrw_sort_options = 'i' let g:netrw_sort_sequence = '[\/]\s*,*' let g:netrw_special_syntax = v:true let g:netrw_timefmt = '%d-%m-%Y %H:%M' -let &t_8f = "\[38;2;%lu;%lu;%lum" -let &t_8b = "\[48;2;%lu;%lu;%lum" -let &t_SI = "\e[6 q" -let &t_EI = "\e[2 q" -let &t_SR = "\e[4 q" + +" Terminal codes (Unix/Linux only) +if s:is_unix + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" + let &t_SI = "\e[6 q" + let &t_EI = "\e[2 q" + let &t_SR = "\e[4 q" +endif " {{{1 Options @@ -44,7 +53,11 @@ set nosmarttab set foldlevelstart=99 set foldmethod=indent set foldignore= -set guifont=Iosevka\ Custom\ 12 +if s:is_windows + set guifont=Iosevka_Custom:h12 +else + set guifont=Iosevka\ Custom\ 12 +endif set completeopt=menu,menuone,preview,noinsert,noselect set matchpairs=(:),{:},[:],<:> set linebreak @@ -108,9 +121,11 @@ imap ^ imap $ imap C imap x -execute "set =\ef" -execute "set =\eb" -execute "set =\ed" +if !s:is_windows + execute "set =\ef" + execute "set =\eb" + execute "set =\ed" +endif imap w imap b imap dw @@ -252,8 +267,13 @@ let g:NERDTreeShowHidden = 1 let g:NERDTreeWinSize = 50 let g:NERDTreeMinimalUI = 1 let g:NERDTreeCascadeSingleChildDir = 0 -let g:NERDTreeRemoveFileCmd = "gio trash " -let g:NERDTreeRemoveDirCmd = "gio trash " +if s:is_windows + let g:NERDTreeRemoveFileCmd = "del /q " + let g:NERDTreeRemoveDirCmd = "rmdir /s /q " +else + let g:NERDTreeRemoveFileCmd = "gio trash " + let g:NERDTreeRemoveDirCmd = "gio trash " +endif let g:NERDTreeMapActivateNode = "" let g:NERDTreeMapCloseDir = "" @@ -304,7 +324,11 @@ augroup END " {{{3 Undotree let g:undotree_WindowLayout = 2 -let g:undotree_DiffCommand = "diff -u" +if s:is_windows + let g:undotree_DiffCommand = "FC" +else + let g:undotree_DiffCommand = "diff -u" +endif let g:undotree_SplitWidth = 50 let g:undotree_DiffpanelHeight = 20 @@ -371,14 +395,28 @@ let g:fuzzbox_window_layout = { " {{{2 Install -let s:plug_file = expand('$HOME/.vim/autoload/plug.vim') -if !filereadable(s:plug_file) - silent execute '!curl -fkLo ' . s:plug_file ' --create-dirs' - \ ' https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +if s:is_windows + let s:plug_file = expand('$HOME/vimfiles/autoload/plug.vim') + let s:plug_dir = expand('$HOME/vimfiles/plugged') +else + let s:plug_file = expand('$HOME/.vim/autoload/plug.vim') + let s:plug_dir = expand('$HOME/.vim/plugged') endif -let s:plug_dir = expand('$HOME/.vim/plugged') +if !filereadable(s:plug_file) + if s:is_windows + silent execute '!powershell -Command "' + \ . 'New-Item -ItemType Directory -Force -Path ' + \ . fnamemodify(s:plug_file, ':h') . '; ' + \ . 'Invoke-WebRequest -Uri ' + \ . 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim ' + \ . '-OutFile ' . s:plug_file . '"' + else + silent execute '!curl -fkLo ' . s:plug_file ' --create-dirs' + \ ' https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + endif + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +endif call plug#begin(s:plug_dir) Plug 'joshdick/onedark.vim' Plug 'tpope/vim-commentary'