Last active
April 11, 2025 22:17
-
-
Save vim-the-protogen/55074446d35b6d0bc585ba0c14d64ea5 to your computer and use it in GitHub Desktop.
My personal vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $vimconfigpath='path/to/.vim' | |
set runtimepath^=$vimconfigpath runtimepath+=$vimconfigpath/after | |
let &packpath = &runtimepath | |
let $MYVIMRC=$vimconfigpath . '/vimrc' | |
source $MYVIMRC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Shell: {{{ | |
if has('win64') | |
set shell=powershell | |
set shellcmdflag=-command | |
set shellquote=" | |
set shellxquote= | |
endif | |
" }}} | |
" Install-plug: {{{ | |
let $autoload=$vimconfigpath . '/autoload' | |
let autoload=shellescape($autoload) | |
let $plug=$autoload . '/plug.vim' | |
" Install vim-plug if not found | |
if empty(glob($plug)) | |
let plugsite='https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | |
if has('win64') | |
execute '!mkdir ' . autoload . ' -Force' | |
execute '!Invoke-WebRequest ' . plugsite . ' -OutFile ' . shellescape(plug) | |
else | |
call system('curl', [ '-fLo', autoload, '--create-dirs', plugsite]) | |
endif | |
source $plug | |
endif | |
" Run PlugInstall if there are missing plugins | |
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | |
\| PlugInstall --sync | source $MYVIMRC | |
\| endif | |
"}}} | |
" Settings: {{{ | |
" When the +eval feature is missing, the set command above will be skipped. | |
" Use a trick to reset compatible only when the +eval feature is missing. | |
silent! while 0 | |
set nocompatible | |
silent! endwhile | |
" Allow backspacing over everything in insert mode. | |
set backspace=indent,eol,start | |
"set ai " always set autoindenting on | |
set backup " keep a backup file | |
set viminfo='20,\"50 " read/write a .viminfo file, don't store more | |
" than 50 lines of registers | |
set history=50 " keep 50 lines of command line history | |
set showcmd " display incomplete commands | |
" Show @@@ in the last line if it is truncated. | |
set display=truncate | |
" Show a few lines of context around the cursor. Note that this makes the | |
" text scroll if you mouse-click near the start or end of the window. | |
set scrolloff=5 | |
" Do incremental searching when it's possible to timeout. | |
if has('reltime') | |
set incsearch | |
endif | |
" TODO: revaluate this for removal | |
" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it | |
" confusing. | |
set nrformats-=octal | |
if has("cscope") && filereadable("/usr/bin/cscope") | |
set csprg=/usr/bin/cscope | |
set csto=0 | |
set cst | |
set nocsverb | |
" add any database in current directory | |
if filereadable("cscope.out") | |
cs add $PWD/cscope.out | |
" else add database pointed to by environment | |
elseif $CSCOPE_DB != "" | |
cs add $CSCOPE_DB | |
endif | |
set csverb | |
endif | |
" Switch syntax highlighting on, when the terminal has colors | |
" Also switch on highlighting the last used search pattern. | |
if &t_Co > 2 || has("gui_running") | |
" Revert with ":syntax off". | |
syntax on | |
" I like highlighting strings inside C comments. | |
" Revert with ":unlet c_comment_strings". | |
let c_comment_strings=1 | |
set hlsearch | |
endif | |
" For plugins to load correctly | |
filetype plugin on | |
set fileformat=unix | |
set fileformats=unix,dos | |
if &term=="xterm" | |
set t_Co=8 | |
set t_Sb=m | |
set t_Sf=m | |
endif | |
" Don't wake up system with blinking cursor: | |
" http://www.linuxpowertop.org/known.php | |
let &guicursor = &guicursor . ",a:blinkon0" | |
" Turn on syntax highlighting | |
syntax on | |
" Leader key | |
let mapleader = "," | |
" Security | |
set modelines=0 | |
" Show line numbers | |
set number | |
" Show file stats | |
set ruler | |
" Blink cursor on error instead of beeping (grr) | |
set visualbell | |
" Encoding | |
set encoding=utf-8 | |
" Whitespace | |
set wrap | |
set textwidth=79 | |
set formatoptions=tcqrn1 | |
set expandtab | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 | |
set noshiftround | |
" Cursor motion | |
set scrolloff=3 | |
set backspace=indent,eol,start | |
set matchpairs+=<:> " use % to jump between pairs | |
runtime! macros/matchit.vim | |
" Allow hidden buffers | |
set hidden | |
" Status bar | |
set laststatus=2 | |
" Last line | |
set showmode | |
set showcmd | |
" Searching | |
nnoremap / /\v | |
vnoremap / /\v | |
set hlsearch | |
set incsearch | |
set ignorecase | |
set smartcase | |
set showmatch | |
" Visualize tabs and newlines | |
set listchars=tab:▸\ ,eol:¬,space:· | |
" Uncomment this to enable by default: | |
set list " To enable by default | |
" Color scheme (terminal) | |
"set t_Co=256 | |
set background=dark | |
" autorun cSyntaxAfter | |
autocmd! FileType c,cpp,java,php call CSyntaxAfter() | |
"}}} | |
" Diff-orig: {{{ | |
" Convenient command to see the difference between the current buffer and the | |
" file it was loaded from, thus the changes you made. | |
" Only define it when not defined already. | |
" Revert with: ":delcommand DiffOrig". | |
if !exists(":DiffOrig") | |
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis | |
\ | wincmd p | diffthis | |
endif | |
"}}} | |
" Key-mappings: {{{ | |
" clear search | |
map <leader><space> :let @/=''<cr> | |
" Formatting | |
map <leader>q gqip | |
" Toggle tabs and EOL | |
map <leader>l :set list!<CR> | |
" switch active pane | |
map <Leader>n :wincmd w<CR> | |
" force <C-c> to behave as <esc> | |
" This is because I believ that the two should be synonymous | |
" Yes, ik that in a UNIX context `ctrl + c` means "cancel this action" and that | |
" in vim `esc` means "I'm done, go back to normal mode" but they are nearly | |
" synonymous in most contexts and `<C-c>` is much easier to hit than <Esc> so | |
" I'm making a small concession here | |
vnoremap <C-c> <Esc> | |
nnoremap <C-c> <Esc> | |
inoremap <C-c> <Esc> | |
inoremap <C-BS> <C-w> | |
" map home and end motion to Ctrl + h and Ctrl + l respectively | |
" notice they are in the direction of the motion UwU | |
map <C-h> <home> | |
map <C-l> <end> | |
inoremap <M-h> <Left> | |
inoremap <M-l> <right> | |
inoremap <M-k> <Up> | |
inoremap <M-j> <Down> | |
inoremap <C-l> <Del> | |
inoremap <C-d> <BS> | |
" use Ctrl + right and Ctrl + left to navigate tabs | |
map <C-Right> :tabnext<CR> | |
map <C-Left> :tabprevious<CR> | |
" mappings for git | |
map <Leader><Leader>ga :Git add %<CR> | |
map <Leader><Leader>gc :Git commit<CR> | |
map <Leader><Leader>gs :Git status<CR> | |
map <Leader><Leader>gp :Git push<CR> | |
map <Leader><Leader>gf :Git fetch --all --prune<CR> | |
" split tabs and open new tabs for editing | |
map <Leader>vs :vsplit<CR> | |
map <Leader>vh :split<CR> | |
map <Leader>te :tabe<space> | |
" get ready to open and edit the file under the cursor | |
" this allows for the option of tab completing it before sending it | |
map <Leader>of :tabe <cfile> | |
"}}} | |
" Move-lines: {{{ | |
function! MoveLineUp() | |
call MoveLineOrVisualUp(".", "") | |
endfunction | |
function! MoveLineDown() | |
call MoveLineOrVisualDown(".", "") | |
endfunction | |
function! MoveVisualUp() | |
call MoveLineOrVisualUp("'<", "'<,'>") | |
normal gv | |
endfunction | |
function! MoveVisualDown() | |
call MoveLineOrVisualDown("'>", "'<,'>") | |
normal gv | |
endfunction | |
function! MoveLineOrVisualUp(line_getter, range) | |
let l_num = line(a:line_getter) | |
if l_num - v:count1 - 1 < 0 | |
let move_arg = "0" | |
else | |
let move_arg = a:line_getter." -".(v:count1 + 1) | |
endif | |
call MoveLineOrVisualUpOrDown(a:range."move ".move_arg) | |
endfunction | |
function! MoveLineOrVisualDown(line_getter, range) | |
let l_num = line(a:line_getter) | |
if l_num + v:count1 > line("$") | |
let move_arg = "$" | |
else | |
let move_arg = a:line_getter." +".v:count1 | |
endif | |
call MoveLineOrVisualUpOrDown(a:range."move ".move_arg) | |
endfunction | |
function! MoveLineOrVisualUpOrDown(move_arg) | |
let col_num = virtcol(".") | |
execute "silent! ".a:move_arg | |
execute "normal! ".col_num."|" | |
endfunction | |
" nnoremap <silent> <C-Up> :<C-u>call MoveLineUp()<CR> | |
" nnoremap <silent> <C-Down> :<C-u>call MoveLineDown()<CR> | |
" inoremap <silent> <C-Up> <C-o>:call MoveLineUp()<CR> | |
" inoremap <silent> <C-Down> <C-o>:call MoveLineDown()<CR> | |
" vnoremap <silent> <C-Up> :<C-u>call MoveVisualUp()<CR> | |
" vnoremap <silent> <C-Down> :<C-u>call MoveVisualDown()<CR> | |
" xnoremap <silent> <C-Up> :<C-u>call MoveVisualUp()<CR> | |
" xnoremap <silent> <C-Down> :<C-u>call MoveVisualDown()<CR> | |
" nnoremap <silent> <C-k> :<C-u>call MoveLineUp()<CR> | |
" nnoremap <silent> <C-j> :<C-u>call MoveLineDown()<CR> | |
" inoremap <silent> <C-k> <C-o>:call MoveLineUp()<CR> | |
" inoremap <silent> <C-j> <C-o>:call MoveLineDown()<CR> | |
" vnoremap <silent> <C-k> :<C-u>call MoveVisualUp()<CR> | |
" vnoremap <silent> <C-j> :<C-u>call MoveVisualDown()<CR> | |
" xnoremap <silent> <C-k> :<C-u>call MoveVisualUp()<CR> | |
" xnoremap <silent> <C-j> :<C-u>call MoveVisualDown()<CR> | |
"}}} | |
let s:using_snippets = 0 | |
" Vim-plug: {{{ | |
call plug#begin($vimconfigpath . '/plugged') | |
Plug 'junegunn/vim-plug' | |
Plug 'arcticicestudio/nord-vim' | |
Plug 'preservim/nerdtree' | |
Plug 'junegunn/fzf', { 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'terryma/vim-multiple-cursors' | |
"Plug 'tpope/vim-eunuch' | |
Plug 'tpope/vim-surround' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'Chiel92/vim-autoformat' | |
Plug 'rust-lang/rust.vim' | |
Plug 'lervag/vimtex' | |
Plug 'easymotion/vim-easymotion' | |
Plug 'tpope/vim-fugitive' | |
Plug 'Townk/vim-autoclose' | |
" Plug 'terrma/vim-multiple-cursors' | |
" ultisnips | |
Plug 'prabirshrestha/asyncomplete.vim' | |
if has('python3') | |
if s:using_snippets | |
Plug 'SirVer/ultisnips' | |
Plug 'honza/vim-snippets' | |
Plug 'prabirshrestha/asyncomplete-ultisnips.vim' | |
endif | |
endif | |
Plug 'vim-scripts/cSyntaxAfter' | |
"Plug 'ycm-core/YouCompleteMe' | |
Plug 'tpope/vim-sensible' | |
Plug 'preservim/nerdcommenter' | |
Plug 'OmniSharp/omnisharp-vim' | |
Plug 'nickspoons/vim-sharpenup' | |
Plug 'dense-analysis/ale' | |
"Plug 'prabirshrestha/vim-lsp' | |
" if executable('pyls') | |
" " pip install python-language-server | |
" au User lsp_setup call lsp#register_server({ | |
" \ 'name': 'pyls' | |
" \ 'cmd': {server_info->['pyls']}, | |
" \ 'allowlist': ['python'], | |
" \ }) | |
" endif | |
call plug#end() | |
"}}} | |
set completeopt="menuone,noinsert,noselect,popuphidden" | |
" Sharpenup: {{{ | |
" All sharpenup mappings will begin with `<Leader>os`, e.g. `<Leader>osgd` for | |
" :OmniSharpGotoDefinition | |
let g:sharpenup_map_prefix = '<Leader><Leader>' | |
let g:sharpenup_statusline_opts = { 'Text': '%s (%p/%P)' } | |
let g:sharpenup_statusline_opts.Highlight = 0 | |
"}}} | |
" ALE: {{{ | |
let g:ale_sign_error = '•' | |
let g:ale_sign_warning = '•' | |
let g:ale_sign_info = '·' | |
let g:ale_sign_style_error = '·' | |
let g:ale_sign_style_warning = '·' | |
let g:ale_linters = { 'cs': ['OmniSharp'] } | |
"}}} | |
" OmniSharp: {{{ | |
let g:OmniSharp_popup_position = 'peek' | |
if has('nvim') | |
let g:OmniSharp_popup_options = { | |
\ 'winblend': 30, | |
\ 'winhl': 'Normal:Normal,FloatBorder:ModeMsg', | |
\ 'border': 'rounded' | |
\} | |
else | |
let g:OmniSharp_popup_options = { | |
\ 'highlight': 'Normal', | |
\ 'padding': [0], | |
\ 'border': [1], | |
\ 'borderchars': ['─', '│', '─', '│', 'â•', 'â•®', '╯', 'â•°'], | |
\ 'borderhighlight': ['ModeMsg'] | |
\} | |
endif | |
let g:OmniSharp_popup_mappings = { | |
\ 'sigNext': '<C-n>', | |
\ 'sigPrev': '<C-p>', | |
\ 'pageDown': ['<C-f>', '<PageDown>'], | |
\ 'pageUp': ['<C-b>', '<PageUp>'] | |
\} | |
if s:using_snippets | |
let g:OmniSharp_want_snippet = 1 | |
endif | |
let g:OmniSharp_highlight_groups = { | |
\ 'ExcludedCode': 'NonText' | |
\} | |
"}}} | |
let g:asyncomplete_enable_for_all = 1 | |
" key mappings for asyncomplete | |
" Asyncomplete: {{{ | |
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() : "\<cr>" | |
" let g:asyncomplete_auto_popup = 1 | |
" let g:asyncomplete_auto_completeopt = 0 | |
"}}} | |
"}}} | |
"Trigger configuration. You need to change this to something other than <tab> if you use one of the following: | |
" - https://github.com/Valloric/YouCompleteMe | |
" - https://github.com/nvim-lua/completion-nvim | |
" UlitSnips: {{{ | |
let g:UltiSnipsExpandTrigger="<c-s>" | |
let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
"}}} | |
" Vimtex: {{{ | |
" vimtex stuff | |
" let g:tex_flavor='latex' | |
" let g:vimtex_view_method='zathura' | |
" let g:vimtex_quickfix_mode=0 | |
" " set conceallevel=1 | |
" let g:tex_conceal='abdmg' | |
"}}} | |
" Airline: {{{ | |
colorscheme nord | |
" Use unicode chars for ale indicators in the statusline | |
let g:airline#ale#indicator_checking = "\uf110 " | |
let g:airline#ale#indicator_infos = "\uf129 " | |
let g:airline#ale#indicator_warnings = "\uf071 " | |
let g:airline#ale#indicator_errors = "\uf05e " | |
let g:airline#ale#indicator_ok = "\uf00c " | |
if !exists('g:airline_symbols') | |
let g:airline_symbols = {} | |
endif | |
let g:airline_left_sep = '' | |
let g:airline_left_alt_sep = '' | |
let g:airline_right_sep = '' | |
let g:airline_right_alt_sep = '' | |
let g:airline_symbols.crypt = '🔒' | |
let g:airline_symbols.linenr = '☰' | |
let g:airline_symbols.linenr = '␊' | |
let g:airline_symbols.linenr = '' | |
let g:airline_symbols.linenr = '¶' | |
let g:airline_symbols.maxlinenr = '' | |
let g:airline_symbols.maxlinenr = '㏑' | |
let g:airline_symbols.branch = '⎇' | |
let g:airline_symbols.paste = 'ρ' | |
let g:airline_symbols.paste = 'Þ' | |
let g:airline_symbols.paste = '∥' | |
let g:airline_symbols.spell = 'Ꞩ' | |
let g:airline_symbols.notexists = 'Ɇ' | |
let g:airline_symbols.whitespace = 'Ξ' | |
let g:airline_symbols.dirty='⚡' | |
"}}} | |
" NerdTree: {{{ | |
autocmd StdinReadPre * let s:std_in=1 | |
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif | |
map <C-e> :NERDTreeToggle<CR> | |
let NERDTreeShowHidden=1 | |
"}}} |
apparently a copy/paste or two scrambled my airline symbols. I have fixed them. God I love source control
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There have been things added to help with configuring this to be easily used on windows without
bash
. Additionally, I'm usingneovim
more so these days thanvim
, which is why I included theinit.vim
. Put theinit.vim
in the path listed by running the commandecho stdpath('config').'/init.vim'
. Oh, and the reason for the shenanigans ininit.vim
is because I wanted to make it easy for me to change where I keep myvimrc
and my.vim
folder. It even works well withOneDrive
!