Skip to content

Instantly share code, notes, and snippets.

@al3rez
Created September 6, 2023 11:16
Show Gist options
  • Save al3rez/5c71538dd7f5c47a71ecfc4d496cd733 to your computer and use it in GitHub Desktop.
Save al3rez/5c71538dd7f5c47a71ecfc4d496cd733 to your computer and use it in GitHub Desktop.
vimrc
set nocompatible " be iMproved, required
filetype plugin on " required
let maplocalleader=","
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'janko/vim-test'
Plugin 'tpope/vim-rails'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-ruby/vim-ruby'
Plugin 'pangloss/vim-javascript'
Plugin 'scrooloose/nerdtree'
Plugin 'tomasr/molokai'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'tpope/vim-endwise'
Plugin 'rhysd/vim-crystal'
Plugin 'ddollar/nerdcommenter'
Plugin 'ap/vim-css-color'
Plugin 'rbgrouleff/bclose.vim'
Plugin 'tommcdo/vim-fubitive'
Plugin 'freitass/todo.txt-vim'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'tomasiser/vim-code-dark'
Plugin 'nanotech/jellybeans.vim'
Plugin 'github/copilot.vim'
Plugin 'chriskempson/base16-vim'
" 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
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" Write swp files to /tmp instead of current directory
set nobackup
set noswapfile
set dir=/tmp
" change the mapleader from \ to ,
let mapleader=","
" strip trailing whitespace on save
autocmd BufWritePre * :%s/\s\+$//e
" line numbers
set number
" highlight current line
set cursorline
" Two space tabs
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
" Set some file types
" Set the Ruby filetype for a number of common Ruby files without .rb
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,Procfile,Guardfile,config.ru,*.rake} set ft=ruby
" Monokai theme
syntax enable
set termguicolors
colorscheme base16-tomorrow-night
" Allow using ctrl-j k l h to navigate between window splits
map <C-h> <C-W>h
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-l> <C-W>l
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COMMAND-T CONFIG
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
"let g:CommandTFileScanner="git" " Controls the file scanner used
let g:CommandTMaxHeight=30 " Sets the maximum height of the results window
let g:CommandTTraverseSCM='pwd'
" Enable git gutter
let g:gitgutter_async=0
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
autocmd FileType text setlocal textwidth=80
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" these "Ctrl mappings" work well when Caps Lock is mapped to Ctrl
nmap <silent> t<C-n> :TestNearest<CR>
nmap <silent> t<C-f> :TestFile<CR>
nmap <silent> t<C-s> :TestSuite<CR>
nmap <silent> t<C-l> :TestLast<CR>
nmap <silent> t<C-g> :TestVisit<CR>
" Nerdtree open by default
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
let NERDTreeQuitOnOpen = 0
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
" Ignore some folders and files for CtrlP indexing
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.yardoc\|node_modules\|log\|tmp$',
\ 'file': '\.so$\|\.dat$|\.DS_Store$'
\ }
" Don't wrap long lines
set nowrap " do not automatically wrap on load
set formatoptions-=t " do not automatically wrap text when typing
" Toggle nerdcommenter with command+/
nmap <C-_> <Plug>NERDCommenterToggle
vmap <C-_> <Plug>NERDCommenterToggle<CR>gv
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
let g:NERDTreeWinPos = "right" " Open NERDTree to the right
let g:NERDTreeWinSize = 30 " Set the width of NERDTree split
nnoremap <C-e> :NERDTreeToggle<cr>
nnoremap <S-q> :Bclose<cr>
" grep
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
set grepformat+=%f:%l:%c:%m
inoremap <c-x><c-k> <c-x><c-k>
set mouse=a
" make status line for terminal similar to normal splits
hi StatusLineTerm term=bold,reverse ctermfg=16 ctermbg=253 gui=italic guifg=#000000 guibg=#dddddd
hi StatusLineTermNC term=reverse ctermfg=231 ctermbg=235 gui=italic guifg=#ffffff guibg=#403c41
tnoremap <Esc> <C-W>N
set notimeout ttimeout timeoutlen=100
" Map gd to perform a recursive vimgrep for the word under cursor in .ts files
nnoremap gr :vimgrep /<c-r><c-w>/j src/**/**/*.ts \| :belowright copen<CR>
:set backspace=indent,eol,start
" Expand current file path with leader + e
nnoremap <expr> <leader>e ":e " . expand('%')
" Use ripgrep if available
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
else
let g:ctrlp_clear_cache_on_exit = 0
endif
" Use Ctrl-J to accept the selected completion from Github Copilot
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true
" This function will toggle between the current buffer and the todo.txt buffer
let g:todo_buffer = -1
function! ToggleTodoBuffer()
if g:todo_buffer == -1
let g:todo_buffer = bufnr('%') " Save the current buffer number
e ~/todo.txt
else
" Switch back to the original buffer
execute g:todo_buffer . 'b'
let g:todo_buffer = -1
endif
endfunction
nnoremap <leader>t :call ToggleTodoBuffer()<cr>
" Map '==' to the Ctrl-W + = command to equalize window sizes
nnoremap == <C-W>=
" Refresh ctags
set tags+=.tags
nnoremap <leader>ct :silent ! /opt/homebrew/opt/universal-ctags/bin/ctags -R --languages=ruby --exclude=.git --exclude=log -f .tags<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment