└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Vim Notes from the Primeagen 2 | [The Primeagen](https://www.youtube.com/playlist?list=PLm323Lc7iSW9kRCuzB3J_h7vPjIDedplM) 3 | 4 | Notes written in (neo)vim 5 | 6 | ## Vim Movements P1 - Your First Moves 7 | https://www.youtube.com/watch?v=nnhqVDIx-go 8 | 9 | Don't use your arrow keys! 10 | 11 | `j`, `k`,`h`, `l`: down, up, left, right 12 | 13 | `w`, `b`: jump forward by word, jump backwards by word 14 | 15 | `f`, `t`: jump to a letter, jump one before a letter 16 | 17 | `%`: Go to respective parenthesis, brace, etc. 18 | 19 | `Ctrl-d`, `Ctrl-u`: jump down half page, jump up half page 20 | 21 | `{`, `}`: jump up a block, jump down by a block 22 | 23 | `V`: highlight line and enter visual mode 24 | 25 | `P`, `p`: paste up a line, paste down a line 26 | 27 | `U`: Capitalize stuff that's highlighted 28 | 29 | `Ctrl-a`, `ctrl-x`: Increment var, decrement var 30 | 31 | `o`, `O`: Insert newline below current, insert newline above current line (both enter insert mode) 32 | 33 | `I`, `A`: Enter insert mode at first character on a line, enter insert mode at last character in the current line 34 | 35 | 36 | ## Your first VimRC: How to setup your vim's vimrc 37 | https://www.youtube.com/watch?v=n9k9scbTuvQ 38 | 39 | Source or "execute" everything in a file with `source %`. 40 | This applies changes made to .vimrc. 41 | 42 | Make sure to create the undodir at `~/.vim/undodir` 43 | 44 | Run the following command to install the plug vim plugin manager 45 | ```console 46 | curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ 47 | https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 48 | ``` 49 | 50 | Open up the .vimrc and add in your plugins. 51 | Then source the .vim with `:source %s`. 52 | Then install plugins with `:PlugInstall`. 53 | 54 | Make YCM work: 55 | ```console 56 | $ cd ~/.vim/plugged/YouCompleteMe 57 | $ python3 install.py 58 | ``` 59 | 60 | Add some nice remap to make things easier: 61 | * `h`: Move to window on the left 62 | * `l`: Move to window on the right 63 | * `j`: Move to window on the bottom 64 | * `k`: Move to window on the top 65 | 66 | * `u`: Show undo tree 67 | 68 | * `pv`: Open up file tree 69 | 70 | * `ps`: (Project Search) searches for stuff using ripgrep (Make sure to install ripgrep on your system) 71 | 72 | * `gd`: Go to definition 73 | * `gr`: Go to references 74 | 75 | ## VIM Movements P2: 5 moves to make you better ked 76 | https://www.youtube.com/watch?v=QN4fuSsWTbA 77 | 78 | * Use Ctrl-c or Ctrl-open bracket instead of Esc. 79 | Instead of using the CAPS LOCK key for Esc, you can use it for CTRL. 80 | 81 | * When using f and t, you can use `,` to go backwards and `;` to go forwards to search for the same letter without repeating the same command 82 | * Use `c` instead of `d` to enter insert mode 83 | * You can use `i` and `a` in conjunction with c or d to remove whatever's inside {}, [], "", '', etc. 84 | E.g. ci" will delete everything within the following string: "Hello, world". 85 | ca" will delete everything inside the string as well as the "". 86 | * Marks allow jumping to points in a file: `mJ` will create a mark called J. `'J` will jump to the mark. Note: Capital letter are marks that are unique across multiple files while lowercase letters are for local file marks. 87 | * Bonus remap allows you to move highlighted regions up or down: 88 | ``` {.vimscript} 89 | vnoremap J :m '>+1gv=gv 90 | vnoremap K :m '<-2gv=gv 91 | ``` 92 | 93 | ## Using Vim: Vim + Git - Fugitive 94 | https://www.youtube.com/watch?v=PO6DxfGPQvw 95 | 96 | `gs`: Git Status 97 | 98 | Use `s` to stage and `u` to unstage. 99 | 100 | `:Gcommit`: Commits stuff 101 | 102 | `:Gpush`: Pushes stuff 103 | 104 | `:Git merge `: Merge 105 | 106 | Use `dv` on the file you want to resolve if you have merge conflicts. 107 | The window on the left should be the current branch, the window on the right should be the one you just merged from, and the middle window is the resulting merge. 108 | 109 | `gf`: Grab from the window on the left (Use 'gu' if using dvorak) 110 | 111 | `gj`: Grab from the window on the right (Use 'gh' if using dvorak) 112 | 113 | `Ctrl-w` and `ctrl-O`: save and close 114 | 115 | ## Making Vim Amazing - Why use Vim and the .vimrc 116 | https://www.youtube.com/watch?v=Iid1Ms14Om4 117 | 118 | Why Vim? 119 | * Fast: Doesn't take forever to load files 120 | * Autocomplete 121 | * Able to jump to definitions fast 122 | 123 | ## Vimium: Intro to using keyboard in your browser 124 | https://www.youtube.com/watch?v=cA2aUFsSLac 125 | 126 | `j` and `k`: down and up 127 | 128 | `d`, `u`: half-page down, half-page up (you don't need ctrl) 129 | 130 | `f`: open link in current tab 131 | 132 | `H`: go back 133 | 134 | `V`: Visual mode highlight entire line 135 | 136 | `y`: yank 137 | 138 | ## Using Vim: My Vim Workflow - Solving a bug 139 | https://www.youtube.com/watch?v=-I1b8BINyEw 140 | 141 | ### First you want some plugins 142 | 143 | * Gruvbox: "The greatest colorscheme ever bestowed to mankind" 144 | * COC: For autocomplete 145 | * Fzf: File finding 146 | 147 | Colorscheme: 148 | ``` 149 | colorscheme gruvbox 150 | ``` 151 | 152 | Nice remaps for coc and jumping to definition/references: 153 | ``` 154 | nmap gd (coc-definition) 155 | nmap gr (coc-references) 156 | ``` 157 | 158 | Fzf remap to make searching for files easier: 159 | ``` 160 | nnoremap :GFiles 161 | ``` 162 | 163 | ### Commands Used 164 | 165 | `Ctrl-p`: Remap for :GFiles. Use it to search for a file. Works even for searching large codebases. 166 | 167 | `gd`: Jump to definition 168 | 169 | `Ctrl-^`: Jumps to the last file you were in 170 | 171 | `Ctrl-o`: Go back to last position 172 | 173 | `Ctrl-i`: Go forward position (Opposite of Ctrl-o) 174 | 175 | ## VIM: Coolest Vim Command 176 | https://www.youtube.com/watch?v=E7NBhSsZouc 177 | 178 | Let's say you have a line of code: 179 | ```javascript 180 | const res = await fetch("http://localhost:8002", { 181 | ``` 182 | If you wanted to change the `http://localhost:8002` string inside the quotes, 183 | you don't have to use `f"` to go to the quotes, you can just use `ci"`. Vim automatically jumps to the nearest quote. 184 | 185 | ## Vim "g" Command 186 | https://www.youtube.com/watch?v=CN8p9iL7PPI 187 | 188 | `g Ctrl-g`: Shows you what line, column, word, and byte you're at and how far you're down the file 189 | 190 | `g8`: Get ASCII Code of current character 191 | 192 | `g<`: Get the output from the last command you executed 193 | 194 | `g&`: Replay your last s command (substitution) 195 | 196 | `gJ`: Combines the line below with the current line while keeping the spacing the same 197 | 198 | `gU motion`: Uppercase stuff 199 | 200 | `gu motion`: Lowercase stuff 201 | 202 | `gd`: Jump to definition in the file (or function?) 203 | 204 | `gf`: Jumps to a file 205 | 206 | `gF`: Jump to a line in a file 207 | 208 | `gq`: Automatically align text to 80 characters 209 | 210 | `gQ`: Enter Ex mode 211 | 212 | `8g_`: Jumps down *7* lines and puts you at the end of that line 213 | 214 | `g\$`: In wrap mode go to the end of the "line" 215 | 216 | `g??`: Rot13 on a line 217 | 218 | `gg`: To Top 219 | 220 | `G`: Bottom 221 | 222 | `gv`: Rehighlight what you previously highlighted 223 | 224 | `gi`: Go back to your previous insert spot 225 | 226 | `'<,'>g/Styled/d`: Delete all lines with "Styled" 227 | 228 | `'<,'>g/Styled/norm! diw`: Execute diw on every line with "Styled" 229 | 230 | `:help g`: A bunch more g commands 231 | 232 | `help :g`: All the fun searching g commands 233 | --------------------------------------------------------------------------------