Skip to content

Instantly share code, notes, and snippets.

@leopolicastro
Last active January 26, 2024 21:18
Show Gist options
  • Save leopolicastro/70c75c497fb3ab691fa44a8dd0e92744 to your computer and use it in GitHub Desktop.
Save leopolicastro/70c75c497fb3ab691fa44a8dd0e92744 to your computer and use it in GitHub Desktop.
"" Download vim-plug if missing
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
autocmd VimEnter * PlugInstall
endif
call plug#begin('~/.vim/plugged')
Plug 'Eliot00/git-lens.vim'
Plug 'airblade/vim-gitgutter'
Plug 'ap/vim-css-color'
Plug 'dense-analysis/ale'
Plug 'fisadev/fisa-vim-colorscheme'
Plug 'github/copilot.vim'
Plug 'honza/vim-snippets'
Plug 'itchyny/lightline.vim'
Plug 'jiangmiao/auto-pairs'
" Plug 'jremmen/vim-ripgrep'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'mileszs/ack.vim'
Plug 'morhetz/gruvbox'
Plug 'motemen/git-vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'pangloss/vim-javascript'
Plug 'preservim/nerdtree'
Plug 'thoughtbot/vim-rspec'
Plug 'tomtom/tcomment_vim'
Plug 'tomasr/molokai'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'vim-ruby/vim-ruby'
Plug 'vim-test/vim-test'
Plug 'vifm/vifm.vim'
call plug#end()
"" Enable syntax highlighting
syntax on
"" Remap 'ff' in normal mode to run ALEFix command (fix linting errors)
nnoremap ff :ALEFix<CR>
"" Remap Ctrl-P in normal mode to open a file search
nnoremap <C-p> :Files<CR>
"" Remap Ctrl-G in normal mode to open git file search
nnoremap <C-g> :GFiles<CR>
"" Remap Ctrl-F in normal mode to start a text search with Rg (ripgrep)
nnoremap <C-f> :Rg<CR>
"" Set Vim to behave as a full-featured editor, not like Vi
set nocompatible
"" Configure backspace so it behaves in a more common way
set backspace=2
"" Set the command history to remember 1000 entries
set history=1000
"" Show the last part of commands in the status line
set showcmd
"" Display the current mode (insert, normal, etc.) in the status line
set showmode
"" Set the status line to always display
set laststatus=2
"" Highlight the line where the cursor is located
set cursorline
"" Use a wild menu for command line completion
set wildmenu
"" Enable mouse support in all modes
set mouse=a
"" Show line numbers
" set number
"" Show relative line numbers
" set relativenumber
"" Set the color scheme to dark
set background=dark
"" Show the file name in the window title bar
set title
"" Set the leader key to ',' (used for leader key mappings)
let mapleader = ","
"" Use Node.js executable for Neoformat if available
let g:neoformat_try_node_exe = 1
"" Remap 'jk' in insert mode to escape to normal mode
inoremap jk <esc>
"" Remap 'jl' in normal mode to toggle paste mode
nnoremap jl :set paste!<cr>
"" Remap '<leader>ev' in normal mode to edit the vimrc file in a vertical split
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
"" Auto-reload vimrc file after saving changes to it
autocmd bufwritepost vimrc source ~/.vim/vimrc
"" Use spaces instead of tabs
set expandtab
"" Set the number of spaces a tab counts for
set tabstop=2
"" Set the number of spaces used for tab and backspace
set softtabstop=2
"" Set the number of spaces to use for each step of (auto)indent
set shiftwidth=2
"" Set the status line to always display
set ls=2
"" Make search patterns very magic (extended regular expressions)
nnoremap / /\v
vnoremap / /\v
"" Ignore case in search patterns
set ignorecase
"" Override ignorecase if search pattern contains upper case characters
set smartcase
"" Set global substitution flag (substitute all occurrences in the line)
set gdefault
"" Show incremental search results as you type
set incsearch
"" Show matching brackets/parentheses/etc.
set showmatch
"" Highlight all search results
set hlsearch
"" Set relative line numbers in the current buffer
" setlocal relativenumber
"" Set line numbers in the current buffer
" setlocal number
"" Define a new autocommand group named 'line_return'
augroup line_return
"" Clear all existing autocommands in this group
au!
"" When a buffer is read, position the cursor at the last edited line
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
"" Map ',r' to run the Ack command for searching
nmap ,r :Ack<Space>
"" Map ',wr' to search for the word under the cursor with Ack
nmap ,wr :Ack <cword><CR>
"" Check if the terminal supports 256 colors, or if using Neovim/GUI
if (&term =~? 'mlterm\|xterm\|xterm-256\|screen-256') || has('nvim') || has('gui_running')
"" Set the terminal to use 256 colors
let &t_Co = 256
"" Use the 'fisa' colorscheme if conditions are met
colorscheme fisa
else
"" Use the 'delek' colorscheme as fallback
colorscheme delek
endif
"" Set the number of context lines above/below the cursor
set scrolloff=3
"" Disable backup files, write backups, and swap files
set nobackup
set nowritebackup
set noswapfile
"" Enable persistent undo
set undofile
"" Set the directory for storing undo files
set undodir=~/.vim/dirs/undos
"" Add the option to store file positions in viminfo file
set viminfo+=n~/.vim/dirs/viminfo
"" Map F3 key to toggle NERDTree file explorer
map <F3> :NERDTreeToggle<CR>
"" Map ',t' to find the current file in NERDTree
nmap ,t :NERDTreeFind<CR>
"" Set NERDTree to ignore files with specified patterns (e.g., .pyc files)
let NERDTreeIgnore = ['\.pyc$', '\.pyo$', '/.overmind.sock']
"" Set a flag if Vim starts with a file read from stdin
autocmd StdinReadPre * let s:std_in=1
"" Automatically open NERDTree when Vim is started with a directory argument
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
"" Custom indicators for NERDTree to show file status (modified, untracked, etc.)
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
"" Set RSpec runner configuration for os_x_iterm2
let g:rspec_runner = "os_x_iterm2"
"" Configure ALE fixers for various file types (e.g., JavaScript, Ruby, CSS)
let g:ale_fixers = {
\ 'javascript': ['prettier'],
\ 'ruby': ['standardrb', 'rubocop'],
\ 'css': ['prettier'],
\ 'scss': ['prettier'],
\ 'html': ['prettier'],
\ 'json': ['prettier'],
\ 'markdown': ['prettier'],
\ 'eruby': ['erb-formatter'],
\ 'liquid': ['prettier'],
\}
"" Map '<Leader>t' to run the current spec file
map <Leader>t :call RunCurrentSpecFile()<CR>
"" Map '<Leader>s' to run the nearest spec
map <Leader>s :call RunNearestSpec()<CR>
"" Map '<Leader>l' to run the last spec
map <Leader>l :call RunLastSpec()<CR>
"" Map '<Leader>a' to run all specs
map <Leader>a :call RunAllSpecs()<CR>
"" Set folding method based on indentation
set foldmethod=indent
"" Set the maximum fold nesting level to 10
set foldnestmax=10
"" Disable automatic folding at startup
set nofoldenable
"" Set the default fold level to 2
set foldlevel=2
"" Remap ':git' to toggle GitLens functionality
nnoremap :git :call ToggleGitLens()<CR>
"" Open a terminal below current window with Control + ]
nnoremap <C-t> :botright term<CR>
"" Specific settings for GUI MacVim
if has("gui_macvim")
"" Enable high shift movement (specific setting for MacVim)
let macvim_hig_shift_movemzRent = 1
endif
"" Remap fe to open current file in buffer with nerdtree
nnoremap fe :NERDTreeFind<CR>
"" Show dotfiles
let NERDTreeShowHidden=1
"" Add all subdirectories to Vim's path
set path+=*/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment