Last active
August 15, 2023 23:29
-
-
Save subfuzion/a704d6c2d495f58204d232c29ab1a251 to your computer and use it in GitHub Desktop.
My personal vim configuration
This file contains 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
"==================================================================== | |
" Leader key | |
"==================================================================== | |
" Remap the leader key. | |
" let g:mapleader = "\<space>" | |
let g:mapleader = ";" | |
"==================================================================== | |
" Edit and reload .vimrc | |
"==================================================================== | |
nnoremap conf :e $MYVIMRC <cr> | |
nnoremap confs :source $MYVIMRC <cr> | |
"==================================================================== | |
" Appearance | |
"==================================================================== | |
" Nicer vertical lines. | |
set fillchars+=vert:\▏ | |
set bg=dark | |
colo darcula | |
syn enable | |
syn on | |
au BufNewFile,BufRead *.{json} setlocal syntax=off | |
"==================================================================== | |
" Sane editor settings | |
"==================================================================== | |
" Relax file compatibility restriction with original vi. | |
" (Not necessary to set with neovim, but useful for vim.) | |
set nocompatible | |
" Save everything when switching buffers/windows/etc. | |
set autowriteall | |
" Disable beep / flash. | |
set vb t_vb= | |
set novisualbell "vb: | |
set noerrorbells "eb | |
set backspace=indent,eol,start | |
set tabstop=2 | |
set shiftwidth=2 | |
set autoindent | |
set expandtab "replace tabs w/spaces; don't forget to use retab after | |
" Allow cursor to move to beginning of tab. | |
" Will interfere with soft line wrapping (set nolist). | |
"set list lcs=tab:\ \ | |
set cin | |
filetype plugin indent on | |
" Enable line and column display. | |
set ruler | |
" Line numbering. | |
" Toggle set to <esc>n in Behavior section. | |
set nonumber | |
" Disable line wrapping. | |
" Toggle set to <esc>w in Behavior section. | |
set nowrap | |
" Disable showmode if using vim-airline; otherwise use 'set showmode'. | |
set showmode | |
" File type recognition. | |
filetype on | |
filetype plugin on | |
filetype indent on | |
" Scroll a bit horizontally when at the end of the line. | |
set sidescroll=6 | |
"==================================================================== | |
" Behavior | |
"==================================================================== | |
" Shorten from default 2 seconds. | |
set timeoutlen=1000 | |
" Capture mouse (prevents tmux from scrolling out of vim). | |
set mouse=a | |
" Use jj to esc in insert mode. | |
inoremap jj <esc> | |
" Highlight matches when searching. | |
" Use <esc><esc> to clear. | |
set hlsearch | |
" Redraw screan and clear search highlighted items. | |
" http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting#answer-25569434 | |
" nnoremap <silent> <c-L> :nohlsearch<cr><c-L> | |
nnoremap <silent> <esc><esc> :nohlsearch<cr><c-L> | |
" Visual matching for :e. | |
set wildmode=list:longest | |
" Toggle line numbers. | |
nnoremap <silent> <esc>n :set number! number?<CR> | |
" Toggle line wrap. | |
nnoremap <silent> <esc>w :set wrap! wrap?<CR> | |
" Toggle syntax. | |
noremap <silent> <esc>s :if exists("g:syntax_on") <bar> | |
\ syntax off <bar> | |
\ else <bar> | |
\ syntax on <bar> | |
\ endif <cr> | |
" Save. | |
inoremap <d-s> <C-o>^:update<cr>gi | |
"==================================================================== | |
" Buffers | |
"==================================================================== | |
nnoremap <silent> <leader>w :w<cr> | |
" Go to next buffer. | |
nnoremap <silent> <leader>n :bn<cr> | |
inoremap <silent> <leader>n <esc>:bn<cr> | |
" Go to previous buffer. | |
nnoremap <silent> <leader>p :bp<cr> | |
inoremap <silent> <leader>p <esc>:bp<cr> | |
" Toggle buffer (switch between current and last buffer). | |
nnoremap <silent> <leader>bb <C-^> | |
" Close buffer. | |
nnoremap <silent> <leader>d :bd<cr> | |
inoremap <silent> <leader>d <esc>:bd<cr> | |
" Kill buffer (ignore edits). | |
nnoremap <silent> <leader>d! :bd!<cr> | |
inoremap <silent> <leader>d! <esc>:bk<cr> | |
" List buffers and select. | |
nnoremap <silent> <leader>bl :ls<cr>:buffer<space> | |
inoremap <silent> <leader>bl <esc>:ls<cr>:buffer<space> | |
" Select buffer. | |
" Press <tab> after <leader>b to execute right away. | |
nnoremap <silent> <leader>b :buffer<space> | |
nnoremap <silent> <enter> :CtrlPBuffer<enter> | |
" Forward and back. | |
nnoremap J <c-f> | |
nnoremap K <c-b> | |
" H, M, and L move the cursor to top, middle, and bottom of the | |
" screen, but the following scrolls the buffer contents so that | |
" the line under the cursor is shifted to the top, middle, or | |
" bottom. | |
nnoremap gt H | |
nnoremap gm M | |
nnoremap gb L | |
nnoremap mt zt | |
nnoremap mm zz | |
nnoremap mb zb | |
" Go to buffer number | |
" =================== | |
" => enter #<enter> to go to buffer # quickly, where # is 1..9 | |
let c = 1 | |
while c <= 9 | |
execute "nnoremap " . c . " :b" . c ."<cr>" | |
let c += 1 | |
endwhile | |
" => enter <leader># to go to buffer #, where # is 1..9 | |
let c = 1 | |
while c <= 9 | |
execute "nnoremap <leader>" . c . " :b" . c ."<cr>" | |
let c += 1 | |
endwhile | |
" => enter #b to go to buffer #, where # is 1..99 | |
let c = 1 | |
while c <= 99 | |
execute "nnoremap " . c . "b :b" . c . "<cr>" | |
let c += 1 | |
endwhile | |
"==================================================================== | |
" Windows | |
"==================================================================== | |
" Prefer opening windows to right and below | |
set splitright | |
set splitbelow | |
" Split horizonal with new buffer. | |
" (The divider is horizontal, the buffers are stacked) | |
nnoremap <silent> <leader>- :new<cr> | |
" Split vertical with new buffer. | |
" (The divider is vertical, the buffers are side-by-side) | |
nnoremap <silent> <leader>\ :vnew<cr> | |
" Close window. | |
nnoremap <silent> <leader>c :close<cr> | |
inoremap <silent> <leader>c <esc>:close<cr> | |
" Improved keyboard navigation. | |
nnoremap <leader>hh <c-w>h | |
nnoremap <leader>jj <c-w>j | |
nnoremap <leader>kk <c-w>k | |
nnoremap <leader>ll <c-w>l | |
nnoremap <esc-h>h <c-w>h | |
nnoremap <esc-j>j <c-w>j | |
nnoremap <esc-k>k <c-w>k | |
nnoremap <esc-l>l <c-w>l | |
inoremap <silent> <leader>hh <esc><c-w>h | |
inoremap <silent> <leader>jj <esc><cr><c-w>j | |
inoremap <silent> <leader>kk <esc><c-w>k | |
inoremap <silent> <leader>ll <esc><c-w>l | |
" Resize horizontal splits (change height). | |
" <c-w><s--> and <c-w><s-=> only shift one line at a time (too slow) | |
nnoremap <silent> <leader>_ :exe "resize " . (winheight(0) * 2/3)<cr> | |
nnoremap <silent> <leader>+ :exe "resize " . (winheight(0) * 3/2)<cr> | |
" Resize vertical splits (change width). | |
" <c-w><s-,> and <c-w><s-.> only shift one line at a time (too slow). | |
nnoremap <silent> <leader>< :exe "vertical resize " . (winwidth(0) * 2/3)<cr> | |
nnoremap <silent> <leader>> :exe "vertical resize " . (winwidth(0) * 3/2)<cr> | |
" Resize everything evently | |
nnoremap <silent> <leader>0 <c-w>= | |
"==================================================================== | |
" Terminal | |
"==================================================================== | |
" Start terminal in insert mode. | |
au Bufenter * if &buftype == 'terminal' | :startinsert | endif | |
" New terminal below. | |
nnoremap <silent> <leader>; :botright terminal<cr> | |
" New terminal to the right. | |
nnoremap <silent> <leader>, :vertical terminal<cr> | |
tnoremap <silent> <leader>, <c-w>:vertical terminal ++close<cr> | |
" Navigation | |
tnoremap <leader>hh <c-w>h | |
tnoremap <leader>jj <c-w>j | |
tnoremap <leader>kk <c-w>k | |
tnoremap <leader>ll <c-w>l | |
" Go to previous / next buffer | |
tnoremap <leader>p <c-w><c-p> | |
tnoremap <leader>n <c-w><c-n> | |
" toggle buffer (switch between current and last buffer). | |
tnoremap <silent> <leader>bb <C-^> | |
" Close terminal | |
" ============== | |
" Enter terminal "normal" mode. | |
tnoremap <silent> <esc> <c-\><c-n> | |
" Close window but don't terminate the shell buffer (can go back to it later) | |
tnoremap <silent> <leader>; <c-w>:close!<cr> | |
" Close window and terminate the shell. | |
tnoremap <silent> <leader>c <c-w>:bd!<cr> | |
"==================================================================== | |
" netrw explorer | |
"==================================================================== | |
" https://vonheikemen.github.io/devlog/tools/using-netrw-vim-builtin-file-explorer/ | |
" https://shapeshed.com/vim-netrw/ | |
" http://ellengummesson.com/blog/2014/02/22/make-vim-really-behave-like-netrw/ | |
let g:netrw_banner = 0 | |
let g:netrw_keepdir = 0 | |
let g:netrw_liststyle = 3 | |
let g:netrw_browse_split = 0 | |
let g:netrw_altv = 1 | |
let g:netrw_winsize = 25 | |
"augroup ProjectDrawer | |
" autocmd! | |
" autocmd VimEnter * :Vexplore | |
"augroup END | |
let g:netrw_localcopydircmd = 'cp -r' | |
hi! link netrwMarkFile Search | |
"nnoremap mm :Lexplore %:p:h<CR> | |
nnoremap m; :Lexplore<CR> | |
"==================================================================== | |
" Plugins | |
" mkdir -p ~/.vim/pack/plugins/start | |
" git clone --depth=1 REPO ~/.vim/pack/plugins/start/REPO-NAME | |
"==================================================================== | |
" CtrlP: https://github.com/ctrlpvim/ctrlp.vim | |
"let g:ctrlp_map = '<c-p>' | |
let g:ctrlp_map = '\' | |
let g:ctrlp_cmd = 'CtrlP' | |
let g:ctrlp_root_markers = ['.git', 'package.json', 'tsconfig.json'] | |
let g:ctrlp_working_path_mode = 'ra' | |
let g:ctrlp_prompt_mappings = { | |
\ 'PrtSelectMove("j")': ['<s-j>', '<down>'], | |
\ 'PrtSelectMove("k")': ['<s-k>', '<up>'], | |
\ } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My JetBrains vim plugin configuration: .ideavimrc.
Explanation of keys here.