|
" Source the example vimrc file |
|
" - It has sensible defaults |
|
" - It, in turn, sources $VIMRUNTIME/defaults.vim, which contains "defaults that most users want". |
|
" This approach is inline with the default behavior on Windows: vim on Windows will |
|
" source $VIMRUNTIME/vimrc_example.vim if the user did not define their own vimrc, as |
|
" explained here: https://github.com/vim/vim/issues/1468 |
|
source $VIMRUNTIME/vimrc_example.vim |
|
|
|
" Automatic installation of the Plug plugin manager |
|
" https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation |
|
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' |
|
if empty(glob(data_dir . '/autoload/plug.vim')) |
|
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' |
|
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC |
|
endif |
|
|
|
" Install some good plugins |
|
call plug#begin('~/.vim/plugged') |
|
Plug 'ghifarit53/tokyonight-vim' " colorscheme |
|
Plug 'dracula/vim', {'as': 'dracula'} " colorscheme |
|
Plug 'tpope/vim-sensible' |
|
Plug 'tpope/vim-commentary' |
|
Plug 'tpope/vim-surround' |
|
Plug 'itchyny/lightline.vim' |
|
Plug 'ntpeters/vim-better-whitespace' |
|
Plug 'editorconfig/editorconfig-vim' |
|
call plug#end() |
|
|
|
" Load additional sensible defaults from sensible.vim. |
|
" As suggested in the documentation, I include sensible.vim at top of my |
|
" .vimrc so that I can override settings. |
|
" (https://github.com/tpope/vim-sensible) |
|
runtime! plugin/sensible.vim |
|
|
|
" MAKE Y SENSIBLE TOO: Y => y$ |
|
" This mapping sets up Y to be consistent with the C and D operators, which |
|
" act from the cursor to the end of the line. The default behavior of Y is to |
|
" yank the whole line, but we can do that with `yy`. |
|
" http://vim.wikia.com/wiki/Short_mappings_for_common_tasks |
|
" VIM HELP suggests it: |
|
" If you like "Y" to work from the |
|
" cursor to the end of line (which is more logical, |
|
" but not Vi-compatible) use ":map Y y$". |
|
" http://vimdoc.sourceforge.net/htmldoc/change.html#Y |
|
" Vim Tips Wiki suggests it: |
|
" https://vim.fandom.com/wiki/Short_mappings_for_common_tasks#Copy |
|
" Tim Pope reluctantly removed it from sensible.vim |
|
" https://github.com/tpope/vim-sensible/issues/47 |
|
" Nvim added it to their defaults in 2021: |
|
" https://stackoverflow.com/q/14385998#comment127889635_19523143 |
|
" https://github.com/neovim/neovim/pull/13268 |
|
nnoremap Y y$ |
|
|
|
" Indent by four spaces |
|
set expandtab |
|
set shiftwidth=4 |
|
set softtabstop=-1 " Make 'softtabstop' follow 'shiftwidth' |
|
set autoindent |
|
|
|
" When pasting, it is necessary to temporarily disable autoindent |
|
" Assign F2 to toggle autoindent |
|
" Alternatively, you could use the ex commands: |
|
" :set paste |
|
" :set nopaste |
|
" http://vim.wikia.com/wiki/Toggle_auto-indenting_for_code_paste |
|
set pastetoggle=<F2> |
|
|
|
" Press F7 to reindent entire file |
|
" http://vim.wikia.com/wiki/Fix_indentation |
|
" Explanation: |
|
" gg Go to first line of file |
|
" =G Reindent (=) from current line to end of file (G) |
|
" <C-o> Move cursor back to previous position |
|
" <C-o> One more time |
|
map <F7> gg=G<C-o><C-o> |
|
|
|
if has('mouse') |
|
set mouse=a |
|
endif |
|
|
|
" Disable beep |
|
" https://vim.fandom.com/wiki/Disable_beeping |
|
set noerrorbells visualbell t_vb= |
|
autocmd GUIEnter * set visualbell t_vb= |
|
|
|
" Set the directory to use for swap files |
|
" (This must be a pre-existing directory. Our 'install.sh' script ensures this is the case.) |
|
" The double trailing slashes (//) at the end tells vim to use the absolute path of the file |
|
" when forming the swap file name so that there's no chance collisions between files of the |
|
" same name from different directories. |
|
" https://vi.stackexchange.com/questions/177/what-is-the-purpose-of-swap-files |
|
set directory=~/.vimswp// |
|
|
|
" Set a central directory to use for backup files |
|
" This is much better than littering |
|
" (This must be a pre-existing directory. Our 'install.sh' script ensures this is the case.) |
|
" The double trailing slashes (//) at the end tells vim to use the absolute path of the file |
|
" when forming the backup file name so that there's no chance collisions between files of the |
|
" same name from different directories. |
|
" Support for this was committed on Aug 7, 2018 |
|
" https://github.com/vim/vim/commit/b782ba475a3f8f2b0be99dda164ba4545347f60f |
|
" (Patch 8.1.0251) |
|
" Associated issue: https://github.com/vim/vim/issues/179 |
|
set backupdir=~/.vimbackup// |
|
|
|
" If we don't have that patch, use Victor Schröder's workound: |
|
" https://stackoverflow.com/a/38479550 |
|
if ! has('patch-8.1-0251') |
|
" This is a copy and paste of Victor Schröder's workound, except I already set backupdir above |
|
" === BACKUP SETTINGS === |
|
" turn backup OFF |
|
" Normally we would want to have it turned on. See bug and workaround below. |
|
" OBS: It's a known-bug that backupdir is not supporting |
|
" the correct double slash filename expansion |
|
" see: https://code.google.com/p/vim/issues/detail?id=179 |
|
set nobackup |
|
|
|
" set a centralized backup directory |
|
"set backupdir=~/.vim/backup// <== I already set this above -Robin |
|
|
|
" This is the workaround for the backup filename expansion problem. |
|
autocmd BufWritePre * :call SaveBackups() |
|
|
|
function! SaveBackups() |
|
if expand('%:p') =~ &backupskip | return | endif |
|
|
|
" If this is a newly created file, don't try to create a backup |
|
if !filereadable(@%) | return | endif |
|
|
|
for l:backupdir in split(&backupdir, ',') |
|
:call SaveBackup(l:backupdir) |
|
endfor |
|
endfunction |
|
|
|
function! SaveBackup(backupdir) |
|
let l:filename = expand('%:p') |
|
if a:backupdir =~ '//$' |
|
let l:backup = escape(substitute(l:filename, '/', '%', 'g') . &backupext, '%') |
|
else |
|
let l:backup = escape(expand('%') . &backupext, '%') |
|
endif |
|
|
|
let l:backup_path = a:backupdir . l:backup |
|
:silent! execute '!cp ' . resolve(l:filename) . ' ' . l:backup_path |
|
endfunction |
|
endif |
|
|
|
" Write with sudo |
|
" This variation works smoother than others I tried. |
|
" Reportedly works in nvim too. |
|
" https://stackoverflow.com/q/2600783#comment123636916_2600783 |
|
command! Wsudo :execute ':silent w !sudo tee > /dev/null "%"' | :edit! |
|
|
|
" Persistent undo |
|
" |
|
" Keep undo history across sessions by storing it in a file |
|
" http://stackoverflow.com/questions/5700389/using-vims-persistent-undo |
|
if has('persistent_undo') |
|
set undodir=~/.vim/undodir |
|
set undofile |
|
endif |
|
|
|
" Make search more forgiving by ignoring case |
|
set ignorecase |
|
|
|
" colorscheme |
|
" =========== |
|
|
|
" Set colorscheme variables |
|
let g:tokyonight_style = "night" |
|
let g:tokyonight_disable_italic_comment = "1" |
|
let g:dracula_bold = 1 |
|
let g:dracula_italic = 0 |
|
let g:dracula_underline = 1 |
|
let g:dracula_undercurl = 1 |
|
let g:dracula_inverse = 1 |
|
let g:dracula_colorterm = 0 |
|
let g:dracula_strikethrough = 0 |
|
|
|
" If the colorscheme has a variant for dark background, choose that |
|
set background=dark |
|
|
|
" This is a TAB |
|
set list |
|
set listchars=tab:>- |
|
|
|
" My modifications to colorschemes |
|
" ================================ |
|
" If a color scheme is almost right, you can add modifications... |
|
" https://vimhelp.org/syntax.txt.html#%3Acolorscheme |
|
|
|
augroup my_colorscheme_modifications |
|
" If a color scheme is almost right, you can add modifications... |
|
" https://vimhelp.org/syntax.txt.html#%3Acolorscheme |
|
au! |
|
|
|
"au Colorscheme tokyonight |
|
" \ hi Normal guibg=#000000 |
|
" \ | hi Comment guifg=#777777 |
|
"\ | hi SpecialKey ctermfg=DarkGreen guifg=DarkRed |
|
"\ hi Normal ctermbg=none guibg=#000000 |
|
|
|
" I wanted dracula's background color to be darker |
|
"au Colorscheme dracula |
|
" \ highlight Normal guibg=#171722 |
|
augroup END |
|
|
|
" Set a colorscheme, if desired |
|
"colorscheme desert |
|
"colorscheme pablo |
|
"colorscheme peachpuff |
|
"colorscheme darkblue |
|
"colorscheme elflord |
|
"colorscheme murphy |
|
"colorscheme ron |
|
"colorscheme slate |
|
"colorscheme torte |
|
"colorscheme dracula |
|
colorscheme tokyonight |
|
|
|
" Lightline |
|
" ========= |
|
|
|
" Lightline shows the mode in the status line |
|
" It is no longer necessary to to display '-- INSERT --' |
|
set noshowmode |
|
|
|
" See available lightline colorschemes here: |
|
" https://github.com/itchyny/lightline.vim/blob/master/colorscheme.md |
|
|
|
"let g:lightline = { 'colorscheme': 'wombat' } |
|
let g:lightline = { 'colorscheme': 'tokyonight' } |
|
"let g:lightline = { 'colorscheme': 'Tomorrow_Night_Blue' } |
|
"let g:lightline = { 'colorscheme': 'darcula' } |
|
|
|
|
|
" OSC52 clipboard support for vim 7.4 |
|
" ======================================== |
|
" |
|
" Yanking in visual mode will send the yanked text to the system clipboard, if |
|
" your terminal supports the OSC 52 escape sequence. |
|
" |
|
" I first tried the ojroques/vim-oscyank plugin, but it wasn't |
|
" compatible with vim 7.4 |
|
" |
|
" I then hacked together this solution |
|
" |
|
" I'd prefer to stay consistent with the key bindings suggested by the |
|
" ojroques/vim-oscyank plugin but that's not trivial. I decided to keep it |
|
" simple and restrict OSC52 to the visual mapping |
|
|
|
" Function to send yanked text to OSC52 sequence |
|
function! OSC52() |
|
let yanked = @" |
|
call system("base64 -w0 | xargs -0 printf '\\e]52;c;%s\\a' >/dev/tty", yanked) |
|
endfunction |
|
|
|
" Map visual y to the OSC52 function as a side effect |
|
" Maybe I should add more yank mappings, but I decided to keep it simple |
|
" Remember, this is merely a workaround for vim-oscyank not being compatible |
|
" with vim 7.4. |
|
vnoremap <silent> y y:call OSC52()<CR> |
|
|
|
" Jump to the last known position when reopening a file |
|
" https://vimdoc.sourceforge.net/htmldoc/eval.html#last-position-jump |
|
if has("autocmd") |
|
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") |
|
\| exe "normal! g`\"" | endif |
|
endif |
|
|
|
" Make split behave more intuitively |
|
" Open file in right split, not default of left split |
|
" https://stackoverflow.com/q/22614280 |
|
" This is for when you do :vsp filename.txt |
|
set splitbelow |
|
set splitright |
|
|
|
" Trim trailing white space |
|
" The ntpeters/vim-better-whitespace plugin supplies StripWhitespace |
|
" Let's map it to <leader>w |
|
nnoremap <leader>w :StripWhitespace<CR> |