├── README.md └── .vimrc /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Vim Configuration Guide 3 | 4 | This guide will walk you through installing Vim and configuring it with the provided \`.vimrc\` file. Instructions are provided for both macOS and Windows operating systems. 5 | 6 | For a visual demonstration of all the shortcuts and functionalities, please refer to [this YouTube video](https://youtu.be/ptdMMuK1WPs). 7 | 8 | 9 | ## macOS Installation 10 | 11 | ### 1. Install Vim 12 | You can install Vim on macOS using Homebrew. Open Terminal and run: 13 | ```bash copy 14 | brew install vim 15 | ``` 16 | 17 | ### 2. Download the .vimrc file 18 | Clone the repository or download the \`.vimrc\` file from the [GitHub repository](https://github.com/servetgulnaroglu/vim-config/blob/main/.vimrc). 19 | 20 | ### 3. Copy the .vimrc file to your home directory 21 | In Terminal, navigate to the directory containing the downloaded \`.vimrc\` file and run: 22 | ```bash copy 23 | cp .vimrc ~/ 24 | ``` 25 | 26 | ## Windows Installation 27 | 28 | ### 1. Install Vim 29 | You can download the Vim installer for Windows from the [official website](https://www.vim.org/download.php). 30 | 31 | ### 2. Download the .vimrc file 32 | Clone the repository or download the \`.vimrc\` file from the [GitHub repository](https://github.com/servetgulnaroglu/vim-config/blob/main/.vimrc). 33 | 34 | ### 3. Copy the .vimrc file to your home directory 35 | Copy the \`.vimrc\` file to your user home directory, usually located at \`C:\\Users\\YourUsername\`. 36 | 37 | ## Final Step 38 | After following the above steps, open Vim, and you should see the configurations from the \`.vimrc\` file applied. 39 | 40 | If you encounter any issues or have any questions, please refer to the repository or feel free to open an issue. 41 | 42 | Happy coding with Vim! 43 | 44 | 45 | 46 | 47 | # Vim Cheat Sheet 48 | 49 | This document provides an extensive collection of Vim commands that aid in navigation, editing, searching, and more. These commands are primarily used in Normal Mode, so remember to press 'ESC' before utilizing them. 50 | 51 | ## Basic Movements 52 | - **h:** Move cursor left. 53 | - **j:** Move cursor down. 54 | - **k:** Move cursor up. 55 | - **l:** Move cursor right. 56 | 57 | ## Modes 58 | - **Esc:** Normal Mode 59 | - **i:** Insert text before the cursor 60 | - **I:** Insert text at the beginning of the line 61 | - **a:** Append text after the cursor 62 | - **A:** Append text at the end of the line 63 | - **v:** Visual Mode (character-wise) 64 | - **V:** Visual Mode (line-wise) 65 | - **Ctrl+v:** Visual Mode (block-wise) 66 | - **::** Command-line Mode 67 | - **r:** Replace a single character 68 | - **R:** Replace mode (continuous replace) 69 | 70 | ## Word Movements 71 | - **w:** Move to the start of the next word. 72 | - **b:** Move to the start of the current/previous word. 73 | 74 | ## Line Movements 75 | - **0:** Move to the start of the line. 76 | - **^:** Move to the first non-blank character. 77 | - **$:** Move to the end of the line. 78 | - **%:** Jump to the matching brace or bracket. 79 | 80 | ## Screen Movements 81 | - **H:** Move to the top of the screen. 82 | - **M:** Move to the middle of the screen. 83 | - **L:** Move to the bottom of the screen. 84 | - **zz:** Center the current line. 85 | - **zt:** Move the current line to the top. 86 | 87 | ## Paragraph and Block Movements 88 | - **{:** Start of the current paragraph/block. 89 | - **}:** End of the current paragraph/block. 90 | 91 | ## File Movements 92 | - **gg:** Start of the file. 93 | - **G:** End of the file. 94 | - **::** Go to a specific line. 95 | 96 | ## Jump Movements 97 | - **gd:** Go to definition. 98 | - **ctrl-o:** Previous location. 99 | - **ctrl-i:** Next location. 100 | - **'m:** Jump to mark 'm'. 101 | - **[g, ]g:** Navigate diagnostics. 102 | - **:** Rename occurrences. 103 | 104 | ## Additional 105 | - **Shift 3:** Highlight All Occurrences 106 | - **n:** Navigate highlights. 107 | - **:noh:** Clear highlights. 108 | 109 | ## Scrolling 110 | - **ctrl-u:** Scroll up (half-screen). 111 | - **ctrl-d:** Scroll down (half-screen). 112 | - **ctrl-b:** Scroll up (full screen). 113 | - **ctrl-f:** Scroll down (full screen). 114 | 115 | ## Search 116 | - **/:** Search for a word. 117 | - **ge:** Replace word under cursor. 118 | 119 | ## Editing 120 | - **diw:** Delete current word. 121 | - **yiw:** Copy the current word. 122 | - **u:** Undo. 123 | - **p:** Paste copied by yiw (pastes after the cursor). 124 | - **shift+p:** Paste before the cursor. 125 | 126 | ## Fold 127 | - **zf:** Fold at current indent level. 128 | - **za:** Toggle current fold. 129 | 130 | ## NERDTree 131 | - **n:** Focus NERDTree (C means CTRL). 132 | - **:** Toggle NERDTree. 133 | - **:** A key specified in .vimrc, my leader key is a comma ','. 134 | 135 | ## Window Resizing 136 | - **++:** Increase window width. 137 | - **--:** Decrease window width. 138 | - **:new:** Create new buffer horizontally. 139 | - **:vnew:** Create new buffer vertically. 140 | - **CTRL+w+ :** Move between windows. 141 | 142 | ## Buffers 143 | - **gb:** List buffers. 144 | - **bd:** Delete current buffer. 145 | - **bd!:** Delete current buffer without saving changes. 146 | - **b:** Go to a specific buffer. 147 | 148 | ## Session 149 | - **mks!:** Create a session. 150 | - **vim -S:** Load a session. 151 | 152 | ## File Operations 153 | - **:w:** Save file. 154 | - **:q:** Quit without saving. 155 | - **:q!:** Force quit without saving. 156 | - **:wq:** Save and quit. 157 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " Specify a directory for plugins 2 | call plug#begin('~/.vim/plugged') 3 | "Plug 'ycm-core/YouCompleteMe' 4 | Plug 'neoclide/coc.nvim', {'branch': 'release'} 5 | Plug 'scrooloose/nerdtree' 6 | "Plug 'tsony-tsonev/nerdtree-git-plugin' 7 | Plug 'Xuyuanp/nerdtree-git-plugin' 8 | Plug 'tiagofumo/vim-nerdtree-syntax-highlight' 9 | Plug 'ryanoasis/vim-devicons' 10 | Plug 'airblade/vim-gitgutter' 11 | Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files 12 | Plug 'scrooloose/nerdcommenter' "Plug 'prettier/vim-prettier', { 'do': 'yarn install' } 13 | Plug 'christoomey/vim-tmux-navigator' 14 | Plug 'morhetz/gruvbox' 15 | Plug 'vim-airline/vim-airline' 16 | Plug 'vim-airline/vim-airline-themes' 17 | Plug 'HerringtonDarkholme/yats.vim' " TS Syntax 18 | Plug 'ryanoasis/vim-devicons' 19 | Plug 'maxmellon/vim-jsx-pretty' 20 | Plug 'projekt0n/github-nvim-theme', { 'tag': 'v0.0.7' } 21 | " Initialize plugin system 22 | call plug#end() 23 | 24 | set bg=dark 25 | set hlsearch 26 | set backspace=indent,eol,start 27 | set guifont=DejaVu\ Sans:s12 28 | set mouse=a 29 | set ignorecase 30 | set belloff=all 31 | set foldmethod=indent 32 | 33 | 34 | nmap n :NERDTreeFocus 35 | nmap :NERDTreeToggle 36 | vmap ++ NERDCommenterToggle 37 | nmap ++ NERDCommenterToggle 38 | nnoremap gb :ls:b 39 | nnoremap ge yiw:%s/0//g 40 | nnoremap = > 41 | noremap y "+y 42 | noremap p "+p 43 | vmap y "+y 44 | vmap p "+p 45 | nnoremap r @: 46 | 47 | 48 | 49 | 50 | nnoremap - < 51 | tnoremap 52 | inoremap 53 | 54 | " Increase window width by 5 columns 55 | nnoremap w+ :vertical resize +5 56 | 57 | " Decrease window width by 5 columns 58 | nnoremap w- :vertical resize -5 59 | nnoremap t :tabs 60 | 61 | 62 | "nnoremap ac :CocAction 63 | "open NERDTree automatically 64 | "autocmd StdinReadPre * let s:std_in=1 65 | "autocmd VimEnter * NERDTree 66 | "autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif 67 | 68 | let g:NERDTreeGitStatusWithFlags = 1 69 | let g:airline_theme='gruvbox' 70 | colorscheme gruvbox 71 | "let g:dracula_italic = 0 72 | "packadd! dracula 73 | "syntax enable 74 | "colorscheme dracula 75 | "colorscheme github_dark 76 | highlight Normal ctermbg=None 77 | let g:airline#extensions#tabline#enabled = 1 78 | let g:airline#extensions#tabline#formatter = 'default' 79 | "let g:vim_jsx_pretty_colorful_config = 1 80 | 81 | 82 | let mapleader = "," 83 | let g:mapleader = "," 84 | 85 | 86 | source ~/matchit/plugin/matchit.vim 87 | 88 | set number 89 | 90 | let g:airline_theme='dark' 91 | let g:airline_powerline_fonts = 1 92 | "let g:WebDevIconsUnicodeDecorateFolderNodes = 1 93 | "let g:NERDTreeGitStatusNodeColorization = 1 94 | "let g:NERDTreeColorMapCustom = { 95 | "\ "Staged" : "#0ee375", 96 | "\ "Modified" : "#d9bf91", 97 | "\ "Renamed" : "#51C9FC", 98 | "\ "Untracked" : "#FCE77C", 99 | "\ "Unmerged" : "#FC51E6", 100 | "\ "Dirty" : "#FFBD61", 101 | "\ "Clean" : "#87939A", 102 | "\ "Ignored" : "#808080", 103 | "\} 104 | 105 | 106 | let g:NERDTreeIgnore = ['^node_modules$'] 107 | 108 | " vim-prettier 109 | "let g:prettier#quickfix_enabled = 0 110 | "let g:prettier#quickfix_auto_focus = 0 111 | " prettier command for coc 112 | command! -nargs=0 Prettier :CocCommand prettier.formatFile 113 | " run prettier on save 114 | "let g:prettier#autoformat = 0 115 | "autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync 116 | 117 | 118 | " ctrlp 119 | let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] 120 | 121 | " j/k will move virtual lines (lines that wrap) 122 | noremap j (v:count == 0 ? 'gj' : 'j') 123 | noremap k (v:count == 0 ? 'gk' : 'k') 124 | 125 | 126 | set smarttab 127 | set cindent 128 | set tabstop=2 129 | set shiftwidth=2 130 | " always uses spaces instead of tab characters 131 | set expandtab 132 | set laststatus=2 133 | set statusline+=%F 134 | 135 | " sync open file with NERDTree 136 | " " Check if NERDTree is open or active 137 | function! IsNERDTreeOpen() 138 | return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1) 139 | endfunction 140 | 141 | " Call NERDTreeFind iff NERDTree is active, current window contains a modifiable 142 | " file, and we're not in vimdiff 143 | function! SyncTree() 144 | if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff 145 | NERDTreeFind 146 | wincmd p 147 | endif 148 | endfunction 149 | 150 | " Highlight currently open buffer in NERDTree 151 | "autocmd BufEnter * call SyncTree() 152 | autocmd BufRead * call SyncTree() 153 | 154 | " coc config 155 | let g:coc_global_extensions = [ 156 | \ 'coc-snippets', 157 | \ 'coc-pairs', 158 | \ 'coc-tsserver', 159 | \ 'coc-eslint', 160 | \ 'coc-prettier', 161 | \ 'coc-json', 162 | \ 'coc-html', 163 | \ 'coc-clangd', 164 | \ 'coc-java', 165 | \ ] 166 | " from readme 167 | " if hidden is not set, TextEdit might fail. 168 | set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Better display for messages set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000. 169 | set updatetime=300 170 | 171 | " don't give |ins-completion-menu| messages. 172 | set shortmess+=c 173 | 174 | " always show signcolumns 175 | set signcolumn=yes 176 | 177 | " Use to trigger completion. 178 | inoremap coc#refresh() 179 | 180 | " Use to confirm completion, `u` means break undo chain at current position. 181 | " Coc only does snippet and additional edit on confirm. 182 | inoremap pumvisible() ? "\" : "\u\" 183 | " Or use `complete_info` if your vim support it, like: 184 | " inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" 185 | 186 | " Use `[g` and `]g` to navigate diagnostics 187 | nmap [g (coc-diagnostic-prev) 188 | nmap ]g (coc-diagnostic-next) 189 | 190 | " Remap keys for gotos 191 | nmap gd (coc-definition) 192 | nmap gy (coc-type-definition) 193 | nmap gi (coc-implementation) 194 | nmap gr (coc-references) 195 | 196 | " Use K to show documentation in preview window 197 | nnoremap K :call show_documentation() 198 | 199 | function! s:show_documentation() 200 | if (index(['vim','help'], &filetype) >= 0) 201 | execute 'h '.expand('') 202 | else 203 | call CocAction('doHover') 204 | endif 205 | endfunction 206 | 207 | " Highlight symbol under cursor on CursorHold 208 | autocmd CursorHold * silent call CocActionAsync('highlight') 209 | 210 | " Remap for rename current word 211 | nmap (coc-rename) 212 | 213 | " Remap for format selected region 214 | xmap f (coc-format-selected) 215 | nmap f (coc-format-selected) 216 | 217 | augroup mygroup 218 | autocmd! 219 | " Setup formatexpr specified filetype(s). 220 | autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') 221 | " Update signature help on jump placeholder 222 | autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') 223 | augroup end 224 | 225 | " Remap for do codeAction of selected region, ex: `aap` for current paragraph 226 | xmap a (coc-codeaction-selected) 227 | nmap a (coc-codeaction-selected) 228 | 229 | " Remap for do codeAction of current line 230 | nmap ac (coc-codeaction) 231 | " Fix autofix problem of current line 232 | nmap qf (coc-fix-current) 233 | 234 | " Create mappings for function text object, requires document symbols feature of languageserver. 235 | xmap if (coc-funcobj-i) 236 | xmap af (coc-funcobj-a) 237 | omap if (coc-funcobj-i) 238 | omap af (coc-funcobj-a) 239 | 240 | nnoremap x "_x 241 | nnoremap d "_d 242 | nnoremap D "_D 243 | vnoremap d "_d 244 | 245 | nnoremap d ""d 246 | nnoremap D ""D 247 | vnoremap d ""d 248 | 249 | 250 | " Use for select selections ranges, needs server support, like: coc-tsserver, coc-python 251 | nmap (coc-range-select) 252 | xmap (coc-range-select) 253 | 254 | " Use `:Format` to format current buffer 255 | command! -nargs=0 Format :call CocAction('format') 256 | 257 | " Use `:Fold` to fold current buffer 258 | command! -nargs=? Fold :call CocAction('fold', ) 259 | 260 | " use `:OR` for organize import of current buffer 261 | command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') 262 | 263 | " Add status line support, for integration with other plugin, checkout `:h coc-status` 264 | "set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} 265 | 266 | " Using CocList 267 | " Show all diagnostics 268 | nnoremap a :CocList diagnostics 269 | " Manage extensions 270 | nnoremap e :CocList extensions 271 | " Show commands 272 | nnoremap c :CocList commands 273 | " Find symbol of current document 274 | nnoremap o :CocList outline 275 | " Search workspace symbols 276 | nnoremap s :CocList -I symbols 277 | " Do default action for next item. 278 | nnoremap j :CocNext 279 | " Do default action for previous item. 280 | nnoremap k :CocPrev 281 | " Resume latest coc list 282 | nnoremap p :CocListResume 283 | 284 | 285 | inoremap coc#pum#visible() ? coc#pum#confirm() : "\" 286 | 287 | 288 | nnoremap tC :call NERDComment(0, "toggle") 289 | vnoremap tC :call nerdcommenter#Comment(0, "toggle") 290 | 291 | nnoremap :call NERDComment(0, "toggle") 292 | vnoremap :call nerdcommenter#Comment(0, "toggle") 293 | --------------------------------------------------------------------------------