Skip to content

Instantly share code, notes, and snippets.

@Zakgeki
Last active August 16, 2023 13:06
Show Gist options
  • Save Zakgeki/55074446d35b6d0bc585ba0c14d64ea5 to your computer and use it in GitHub Desktop.
Save Zakgeki/55074446d35b6d0bc585ba0c14d64ea5 to your computer and use it in GitHub Desktop.
My personal vimrc
" Install vim-plug if not found
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
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
" 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
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=m
set t_Sf=m
endif
" 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
if has('langmap') && exists('+langremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If set (default), this may break plugins (but it's backward
" compatible).
set nolangremap
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
" For plugins to load correctly
" filetype plugin indent on
"
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
" Move up/down editor lines
"nnoremap j gj
"nnoremap k gk
" Allow hidden buffers
set hidden
" Rendering
set ttyfast
" 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
map <leader><space> :let @/=''<cr> " clear search
" Textmate holdouts
" Formatting
map <leader>q gqip
" Visualize tabs and newlines
set listchars=tab:▸\ ,eol:¬,space:·
" Uncomment this to enable by default:
set list " To enable by default
" Or use your leader key + l to toggle on/off
map <leader>l :set list!<CR> " Toggle tabs and EOL
" Color scheme (terminal)
"set t_Co=256
set background=dark
" autorun cSyntaxAfter
autocmd! FileType c,cpp,java,php call CSyntaxAfter()
"move lines script
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>
" vim-plug plugins
call plug#begin('~/.vim/plugged')
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 'sixro/vim-java-maven'
Plug 'tpope/vim-fugitive'
Plug 'Townk/vim-autoclose'
" Plug 'terrma/vim-multiple-cursors'
"Plug 'SirVer/ultisnips'
" Plug 'honza/vim-snippets'
Plug 'mikelue/vim-maven-plugin'
Plug 'vim-scripts/cSyntaxAfter'
"Plug 'ycm-core/YouCompleteMe'
Plug 'tpope/vim-sensible'
Plug 'preservim/nerdcommenter'
Plug 'OmniSharp/omnisharp-vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
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()
" key mappings for 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>"
" 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 stuff
colorscheme nord
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 settings and mappings
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
" acustom key mappings
" switch active pane
map <Leader>n :wincmd w<CR>
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 <C-h> <Left>
inoremap <C-l> <right>
" 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment