├── .gitignore ├── autoload └── lf_tmux.vim ├── cheat40.txt ├── coc-settings.json ├── readme.md ├── tmp ├── backup │ └── .gitkeep └── undo │ └── .gitkeep ├── ultisnips └── javascript.snippets └── vimrc /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /*~ 3 | /plugged 4 | /autoload/plug.vim 5 | sessions 6 | /tmp/** 7 | -------------------------------------------------------------------------------- /autoload/lf_tmux.vim: -------------------------------------------------------------------------------- 1 | let s:tmux_directions = {'h':'L', 'j':'D', 'k':'U', 'l':'R'} 2 | 3 | fun! lf_tmux#navigate(dir) 4 | let l:winnr = winnr() 5 | execute 'wincmd' a:dir 6 | if winnr() ==# l:winnr 7 | call system("tmux select-pane -".s:tmux_directions[a:dir]) 8 | endif 9 | endf 10 | -------------------------------------------------------------------------------- /cheat40.txt: -------------------------------------------------------------------------------- 1 | Other Plugins {{{1 2 | Surround {{{2 3 | Insert surrounding ‹c› «C-g»s‹c› I 4 | Surround with ‹c› ys‹Move›‹c› N 5 | Surround with ‹c› S‹c› V 6 | Replace delimiters cs‹c›‹c› N 7 | Replace tags cst‹c› N 8 | Remove ‹c› delimiters ds‹c› N 9 | Remove enclosing tags dst N 10 | Ultisnips {{{2 11 | Expand «C-e» I 12 | Next «C-j» I 13 | Previous «C-k» I 14 | Vimrc {{{1 15 | Buffers and files {{{2 16 | Cd to current path cd N 17 | Save (only if modified) \fw N 18 | Ditto \w N 19 | Save as root \fW N 20 | Edit {{{2 21 | Omnicomplete «Tab» I 22 | Copy to clipboard \y O 23 | Copy line to clipboard \Y N 24 | Paste from clipboard \p VN 25 | Paste from clipboard \P VN 26 | Search {{{2 27 | Find file in working dir \ff N 28 | Find file hidden \fh N 29 | Find grep \fg N 30 | Find words \fw N 31 | Find recent file \fr N 32 | Find Commits \fc N 33 | Find recent file \«space» N 34 | Find buffers \bf N 35 | Go {{{2 36 | Go to window number n \‹n› N 37 | Go to (tmux) left pane «Alt-h» N 38 | Go to (tmux) right pane «Alt-l» N 39 | Go to (tmux) pane below «Alt-j» N 40 | Go to (tmux) pane above «Alt-k» N 41 | NERDTree {{{2 42 | Toggle NERDTree \vn N 43 | Open in new tab t N 44 | Open in split i N 45 | Open in vsplit s N 46 | Open/close node o N 47 | Recursively open node O N 48 | Close parent of node x N 49 | Close all child nodes X N 50 | Go to root P N 51 | Go to parent p N 52 | Go to first child K N 53 | Go to last child J N 54 | Go to next sibling «C-j» N 55 | Go to prev sibling «C-k» N 56 | Toggle hidden files I N 57 | Make current dir root C N 58 | Refresh cursor dir r N 59 | Refresh current root R N 60 | Change CWD to cursor dir cd N 61 | Change tree root to CWD CD N 62 | Options {{{2 63 | Toggle Paste mode «f9» N 64 | Toggle cursorline \oc N 65 | Toggle search highlight \oh N 66 | Toggle ignore case \oi N 67 | Toggle invisibles \ol N 68 | Toggle line numbers \on N 69 | Toggle rel line numbers \or N 70 | CoC {{{2 71 | Quick fix \qf N 72 | Rename word \rn N 73 | Open link \co N 74 | Go to implementation \gi N 75 | Go to definition \gd N 76 | Find references \gr N 77 | Show outline list \co N 78 | List errors \cl N 79 | List commands \cc N 80 | Format \f VN 81 | Smart Jump forward f N 82 | Smart Jump backward F N 83 | Show yanks \y N 84 | Next error [c N 85 | Prev error ]c N 86 | Next chunk [g N 87 | Prev chunk ]g N 88 | Git chunk info \gs N 89 | Show documentation K N 90 | Code Action \ca VN 91 | Restart CoC \cR N 92 | -------------------------------------------------------------------------------- /coc-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "coc.preferences.formatOnSaveFiletypes": ["css", "json"], 3 | 4 | "javascript.preferences.quoteStyle": "single", 5 | 6 | "diagnostic.errorSign": "✖", 7 | "diagnostic.hintSign": "•", 8 | "diagnostic.infoSign": "•", 9 | 10 | "list.source.files.defaultOptions": ["--auto-preview"], 11 | "list.source.outline.defaultOptions": ["--auto-preview"], 12 | 13 | "snippets.extends": { 14 | "typescript": ["javascript"], 15 | "svelte": ["javascript", "typescript", "html", "css"] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Vimrc 2 | 3 | > My sweet sweet vim configuration 4 | 5 | - Foldable and thoroughly commented `vimrc`. 6 | - Move freely between Vim and tmux using `⌥-h/j/k/l` 7 | (plugin-free, requires [some configuration](https://github.com/lifepillar/dotfiles/blob/master/dot-tmux.conf) in tmux, too). 8 | - 40-column **cheat sheet** always two keys away (courtesy of [Cheat40](https://github.com/lifepillar/vim-cheat40)). 9 | 10 | ### Requirements 11 | 12 | - A fairly recent Vim (8 or later) (`brew install vim` recommended on macOS). 13 | 14 | Recommended: 15 | 16 | - Neovim. 17 | - [fzf](https://github.com/junegunn/fzf) (only the executable); 18 | - [ripgrep](https://github.com/BurntSushi/ripgrep). 19 | 20 | ### Installation 21 | 22 | ```sh 23 | git clone https://github.com/terkelg/vimrc.git ~/.vim 24 | ``` 25 | 26 | ### Credit 27 | 28 | - Based on the amazing work from [lifepillar](https://github.com/lifepillar/vimrc). 29 | - With inspiration from [yoshuawuyts](https://github.com/yoshuawuyts/dotfiles/blob/master/vim/vimrc) 30 | - [Plugin Script](https://stories.abletech.nz/get-rid-of-your-vim-plugin-manager-7c8ff742f643) 31 | -------------------------------------------------------------------------------- /tmp/backup/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terkelg/vimrc/3ea3ab6ba07675ee270871278b5222ae75e32e99/tmp/backup/.gitkeep -------------------------------------------------------------------------------- /tmp/undo/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terkelg/vimrc/3ea3ab6ba07675ee270871278b5222ae75e32e99/tmp/undo/.gitkeep -------------------------------------------------------------------------------- /ultisnips/javascript.snippets: -------------------------------------------------------------------------------- 1 | snippet cl "console.log(...)" i 2 | console.log($0); 3 | endsnippet 4 | 5 | snippet cw "console.warn(...)" i 6 | console.warn($0); 7 | endsnippet 8 | 9 | snippet ce "console.error(...)" i 10 | console.error($0); 11 | endsnippet 12 | 13 | snippet prom 14 | new Promise((resolve, reject) => { 15 | $0 16 | }) 17 | endsnippet 18 | 19 | snippet r "require(...)" 20 | require('$0'); 21 | endsnippet 22 | 23 | snippet im "import {...} from ''" 24 | import {$1} from '$2'; 25 | endsnippet 26 | 27 | snippet f "function() {...}" i 28 | function (${1}) {$0} 29 | endsnippet 30 | 31 | snippet fa "function() {...}" i 32 | async function (${1}) {$0} 33 | endsnippet 34 | 35 | snippet fn "function name() {...}" i 36 | function ${1} ($2) { 37 | $0 38 | } 39 | endsnippet 40 | 41 | snippet comp 42 | class ${1:Name} extends Component { 43 | constructor() { 44 | $2 45 | } 46 | } 47 | endsnippet 48 | 49 | snippet exp "export default ..." 50 | export default $0 51 | endsnippet 52 | -------------------------------------------------------------------------------- /vimrc: -------------------------------------------------------------------------------- 1 | " Modeline and Notes {{ 2 | " vim: set sw=2 ts=2 sts=0 et fdm=marker :nospell: 3 | " __ ___ 4 | " \ \ / (_)_ __ ___ _ __ ___ 5 | " \ \ / /| | '_ ` _ \| '__/ __| 6 | " \ V / | | | | | | | | | (__ 7 | " \_/ |_|_| |_| |_|_| \___| 8 | " - Terkel Gjervig 9 | " 10 | " This is a lighter version of my previous vimrc. 11 | " See old commits for more mappings. 12 | " }} 13 | 14 | " TODO 15 | " - Update cheat40 16 | 17 | " Install Plugins {{ 18 | if empty(glob('~/.vim/autoload/plug.vim')) 19 | silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs 20 | \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 21 | autocmd VimEnter * PlugInstall --sync | source $MYVIMRC 22 | endif 23 | call plug#begin('~/.vim/plugged') 24 | Plug 'lifepillar/vim-cheat40' " Cheat sheet for Vim 25 | Plug 'tpope/vim-commentary' " Add comments in blocks 26 | Plug 'tpope/vim-surround' " Enable inserting brackets around words 27 | Plug 'tpope/vim-repeat' " Enable . repeat for vim surround and others 28 | Plug 'can3p/incbool.vim' " Increment not only numbers but also true/false, show/hide etc. 29 | Plug 'justinmk/vim-sneak' " Jump Around! 30 | Plug 'editorconfig/editorconfig-vim' " Respect editorconfig files 31 | Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " File browser 32 | Plug 'sheerun/vim-polyglot' " Syntax highlighting for more languages 33 | Plug 'rakr/vim-one' " A nice theme 34 | Plug 'arcticicestudio/nord-vim' " Another nice theme 35 | Plug 'evanleck/vim-svelte', {'branch': 'main'} " Svelte syntax highlight 36 | Plug 'petrbroz/vim-glsl' " Shader GLSL highlighting 37 | Plug 'neoclide/jsonc.vim' " Syntax highlight tsconfig.json and other jsonc docs 38 | Plug 'neoclide/coc.nvim', {'branch': 'release'} 39 | Plug 'liuchengxu/vim-clap', {'do': ':Clap install-binary'} 40 | call plug#end() 41 | " }} 42 | 43 | " Automatically reload vimrc when it's saved 44 | autocmd! BufWritePost vimrc so ~/.vim/vimrc" 45 | 46 | " Use correct terminal colors 47 | if(has('termguicolors')) 48 | set termguicolors 49 | endif 50 | 51 | " Environment {{ 52 | syntax on "enable syntax mode 53 | set encoding=utf-8 " utf8 everywhere 54 | set updatetime=500 " Trigger CursorHold event after half a second 55 | filetype on " Enable file type detection 56 | filetype plugin on " Enable loading the plugin files for specific file types 57 | filetype indent on " Load indent files for specific file types 58 | set autoread " Re-read file if it is changed by an external program 59 | set ttimeout 60 | set ttimeoutlen=10 " This must be a low value for -key not to be confused with an mapping 61 | " }} 62 | 63 | " History and Backup {{ 64 | " Consolidate temporary files in a central spot 65 | set backupdir=~/.vim/tmp/backup 66 | set directory=~/.vim/tmp/swap 67 | set undofile " Enable persistent undo 68 | set undodir=~/.vim/tmp/undo 69 | " }} 70 | 71 | " Apperance {{ 72 | colorscheme nord " set colorscheme 73 | set background=dark 74 | set shortmess+=Im " No intro, use [+] instead of [Modified] 75 | let g:one_allow_italics=1 "allow italics 76 | let g:nord_bold = 1 77 | let g:nord_italic = 1 78 | let g:nord_italic_comments = 1 79 | let g:nord_underline = 1 80 | " }} 81 | 82 | " Editing {{ 83 | set backspace=indent,eol,start " Intuitive backspacing in insert mode 84 | set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J) 85 | set splitright splitbelow " When splitting focus goes to the bottom or right window 86 | set mouse=a " Enable mouse use in all modes 87 | set number " Turn line numbering on 88 | set relativenumber " Display line numbers relative to the line with the cursor 89 | " }} 90 | 91 | " Wrapping {{ 92 | set whichwrap+=<,>,[,],h,l " More intuitive arrow movements 93 | set nowrap " Don't wrap lines by default 94 | set linebreak " If wrapping is enabled, wrap at word boundaries 95 | set formatoptions+=1j " Do not wrap after a one-letter word and remove extra comment when joining lines 96 | set textwidth=80 " Show gutter at 80 chars 97 | " }} 98 | 99 | " Find, replace, and completion {{ 100 | set incsearch " Search as you type 101 | set nohlsearch " Don't keep search highlight after search 102 | set ignorecase " Case-insensitive search by default 103 | set infercase " Smart case when doing keyword completion 104 | set smartcase " Use case-sensitive search if there is a capital letter in the search expression 105 | set wildignore+=.DS_Store,Icon\?,*.dmg,*.git,*.o,*.obj,*.so,*.swp,*.zip,*.jpg,*.png,*.gif 106 | set wildmenu " Show possible matches when autocompleting 107 | " }} 108 | 109 | " Indentation {{ 110 | set autoindent " Use indentation of the first-line when reflowing a paragraph 111 | set shiftround " Round indent to multiple of shiftwidth (applies to < and >) 112 | set tabstop=2 " Use two spaces for tab by default 113 | set shiftwidth=4 114 | set softtabstop=4 115 | set smarttab 116 | set expandtab " Use soft tabs by default 117 | " }} 118 | 119 | " Scrolling {{ 120 | " Scroll the viewport faster 121 | nnoremap 122 | nnoremap 123 | " Start scrolling when we're getting close to margins 124 | set scrolloff=10 " Minimal number of screen lines to keep above and below the cursor 125 | set sidescrolloff=15 " Minimal side scroll offset 126 | set sidescroll=1 127 | " }} 128 | 129 | " Disabled Vim Plugins (performance) {{ 130 | let g:loaded_getscriptPlugin = 1 131 | let g:loaded_gzip = 1 132 | let g:loaded_logiPat = 1 133 | let g:loaded_netrwPlugin = 1 134 | let g:loaded_rrhelper = 1 135 | let g:loaded_tarPlugin = 1 136 | let g:loaded_vimballPlugin = 1 137 | let g:loaded_zipPlugin = 1 138 | " }} 139 | 140 | " Space Space Space Space 141 | map 142 | 143 | " Window navigation {{ 144 | nnoremap 1 1w 145 | nnoremap 2 2w 146 | nnoremap 6 6w 147 | nnoremap 7 7w 148 | nnoremap 8 8w 149 | nnoremap 9 9w 150 | nnoremap 0 10w 151 | if $TERM =~# '^\%(tmux\|screen\)' 152 | nnoremap :call lf_tmux#navigate('h') 153 | nnoremap :call lf_tmux#navigate('j') 154 | nnoremap :call lf_tmux#navigate('k') 155 | nnoremap :call lf_tmux#navigate('l') 156 | else 157 | nnoremap l 158 | nnoremap h 159 | nnoremap j 160 | nnoremap k 161 | endif 162 | " Disable arrow movement, resize splits instead 163 | nnoremap :resize +2 164 | nnoremap :resize -2 165 | nnoremap :vertical resize +2 166 | nnoremap :vertical resize -2 167 | " Faster split navigation 168 | noremap 169 | noremap 170 | noremap 171 | noremap 172 | " }} 173 | 174 | " Allow using alt/ctrl in macOS without enabling “Use Option as Meta key” {{ 175 | " https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim 176 | nmap ¬ 177 | nmap ˙ 178 | nmap ∆ 179 | nmap ˚ 180 | " }} 181 | 182 | " tsconfig.json is actually jsonc, help TypeScript set the correct filetype 183 | autocmd BufRead,BufNewFile tsconfig.json set filetype=jsonc 184 | 185 | " Plugins {{ 186 | " Clap {{ 187 | nnoremap :Clap 188 | nnoremap ff :Clap files 189 | nnoremap fb :Clap buffers 190 | nnoremap fh :Clap files --hidden 191 | nnoremap fg :Clap grep 192 | " }} 193 | 194 | " Nerdtree {{ 195 | nnoremap vn :NERDTreeToggle 196 | " close vim if the only window left open is a NERDTree 197 | autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif 198 | " }} 199 | 200 | " Sneak {{ 201 | let g:sneak#label = 1 202 | " }} 203 | 204 | " CoC {{ 205 | " Plugins 206 | let g:coc_global_extensions = [ 207 | \ 'coc-tsserver', 208 | \ 'coc-css', 209 | \ 'coc-json', 210 | \ 'coc-html', 211 | \ 'coc-emmet', 212 | \ 'coc-dictionary', 213 | \ 'coc-omni', 214 | \ 'coc-pairs', 215 | \ 'coc-git', 216 | \ 'coc-lists', 217 | \ 'coc-snippets', 218 | \ 'coc-highlight', 219 | \ 'coc-prettier' 220 | \ ] 221 | 222 | " restart when tsserver gets wonky 223 | nnoremap cR :CocRestart 224 | 225 | " qf - quick fix 226 | nmap qf (coc-fix-current) 227 | 228 | " expand snippets with enter 229 | inoremap pumvisible() ? "\" : "\u\" 230 | inoremap 231 | \ pumvisible() ? "\" : 232 | \ check_back_space() ? "\" : 233 | \ coc#refresh() 234 | inoremap pumvisible() ? "\" : "\" 235 | 236 | function! s:check_back_space() abort 237 | let col = col('.') - 1 238 | return !col || getline('.')[col - 1] =~# '\s' 239 | endfunction 240 | " }} 241 | "}} 242 | --------------------------------------------------------------------------------