vim

2023.10.15

vim text editor

#tools
use client /components/post/reExport , date: , tags: [ ], desc: , body: ( <> <H>LazyVim</H> <ul> <li> Notes are based on this resource <Lnk path= > { } https://lazyvim-ambitious-devs.phillips.codes/course/chapter-1/ </Lnk> </li> </ul> <H>Tutor</H> <ul> <li> <kbd>:Tutor</kbd> launch tutor </li> </ul> <H>Verb, count, motion</H> <ul> <li>count + verb + count + motion</li> <li>navigation is the default verb, can be omitted</li> </ul> <H>Motions</H> <ul> <li> <kbd>w</kbd> forward to start of a word </li> <li> <kbd>e</kbd> forward to end of a word </li> <li> <kbd>b</kbd> back to start of a word </li> <li> <kbd>ge</kbd> back to end of a word </li> <li> <kbd>$</kbd> forward to the end of a line </li> <li> <kbd>0</kbd> back to the start of a line </li> <li> <kbd>^</kbd> back to start of a line not taking white spaces into account </li> <li> <kbd>W</kbd> <kbd>E</kbd> <kbd>B</kbd> <kbd>gE</kbd> works the same, but splits words by white space, while lowercased versions split works also with dot, paren, quote </li> </ul> <H>Count + motion = Repeat motion</H> <ul> <li> <kbd>3w</kbd> forward to the end of a word 3 times </li> </ul> <H>Insert mode (text)</H> <ul> <li> <kbd>a</kbd>/<kbd>A</kbd> after cursor/line </li> <li> <kbd>i</kbd>/<kbd>I</kbd> before cursor/line </li> <li> <kbd>o</kbd>/<kbd>O</kbd> new line below/above </li> <li> <kbd>ge</kbd> go to the last insertion point </li> <li> <kbd>Esc</kbd> normal mode (navigate and manipulate text) </li> <li> <kbd>Ctrl+o</kbd> go back into Normal mode for one operation only </li> <li> <kbd>Ctrl+u</kbd> undo for current line in Insert mode </li> </ul> <H>Select</H> <ul> <li> <kbd>v</kbd> granule text selection in Visual mode </li> <li> <kbd>V</kbd> line text selection in Visual mode </li> <li> <kbd>V</kbd> selects whole line under cursor </li> <li> <kbd>Ctrl+v</kbd> block vertical text selection (handy for csv data), <kbd>$</kbd> - expands the selection to the longest line </li> <li>Or just click and drag mouse</li> <li> <kbd>Esc</kbd>/<kbd>v</kbd> exit Visual mode </li> <li> <kbd>gv</kbd> go back to prev selection </li> <li> <kbd>o</kbd> in Visual mode - jump to the start/end of selection </li> <li> <kbd>S</kbd> select with Seeking Surrounding Objects </li> </ul> <H>Expand selection</H> <ul> <li> there is no native vim way, but can use <code>treesitter</code> plugin </li> <li> Create or edit <code>~/.config/nvim/lua/plugins/treesitter.lua</code> </li> <Code block jsx>{ nvim-treesitter/nvim-treesitter , opts.incremental_selection or {}, { enable = true, keymaps = { init_selection = , -- start at node under cursor node_incremental = , -- expand outward node_decremental = , -- shrink inward scope_incremental = , -- expand to scope (func/class) }, }) end, } }</kbd> open register list </li> <li> <kbd> ap</kbd> paste from the <code>a</code> register </li> <li>you may also delete and replace into the register</li> <li>adding again to the same named register replaces the content</li> <li> <kbd> </kbd> show all registers and add content to <code>+</code> register with{ } <kbd>Enter</kbd> </li> <li> <kbd>Ctrl+r</kbd> show same registers menu in Insert mode </li> <li> Last copied text is available at <code>0</code> register and you may paste it with{ } <kbd> s end </li> <li> <kbd>yiq</kbd>/<kbd>yaq</kbd> copy inside nearest quotes / including quotes </li> <li> <kbd>yib</kbd>/<kbd>yab</kbd> copy inside nearest brackets / including brackets </li> <li> <kbd>yiw</kbd>/<kbd>yaw</kbd> copy nearest word / word and whitespaces around </li> <li> <kbd>yig</kbd> copy whole file </li> </ul> <H>Paste</H> <ul> <li> <kbd>p</kbd>/<kbd>P</kbd> paste deleted text after/before cursor </li> <li> <kbd>5p</kbd> paste 5 times </li> <li> In Insert mode to paste <kbd>Ctrl+r</kbd> followed by <kbd>+</kbd> </li> </ul> <H>Yanky.nvim Plugin</H> <ul> <li> Install it from <kbd>:LazyExtras</kbd> and pushing <kbd>x</kbd> in front of it, then reload NeoVim </li> <li> <kbd>Space p</kbd> opens the clipboard history list </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> pastes previous/next clipboard entries in cycle </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> pastes indented above/below current line </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd>/<kbd>{ }</kbd>/<kbd>{ }</kbd> put after/before and indent right/left </li> </ul> <H>Undo, Redo</H> <ul> <li> <kbd>u</kbd> undo the last command </li> <li> <kbd>U</kbd> undo all for the line </li> <li> <kbd>Ctrl+r</kbd> redo </li> <li> <kbd>Ctrl+u</kbd> undo in Insert mode </li> </ul> <H>Command mode</H> <ul> <li> <kbd>:</kbd> command mode </li> <li> <kbd>:q!</kbd> force exit without save </li> </ul> <H>Open project in NeoVim</H> <ul> <li> Navigate to you project in terminal with <kbd>cd</kbd> </li> <li> Type <kbd>nvim</kbd> </li> </ul> <H>Save</H> <ul> <li> <kbd>:w</kbd> write </li> <li> <kbd>:w TEST.txt</kbd> write under TEST name </li> <li> <kbd>:write TEST.txt</kbd> same </li> <li> <kbd>v</kbd> motion <kbd>:w</kbd> <code>FILENAME</code> saves the Visually selected lines in file FILENAME. </li> <li> <kbd>Ctrl+s</kbd> save file </li> </ul> <H>Exit</H> <ul> <li> <kbd>:q</kbd> quite </li> <li> <kbd>:wq</kbd> write & quit </li> <li> <kbd>:x</kbd> write & quit </li> <li> <kbd>:q!</kbd> quit without save </li> <li> <kbd>:qall</kbd> quit from all buffers </li> <li> <kbd>Space qq</kbd> to exit LazyVim </li> </ul> <H>Navigate in list</H> <ul> <li> <kbd>Tab</kbd> move down in list </li> <li> <kbd>Ctrl+y</kbd> accept </li> <li> <kbd>Arrow Down</kbd> accept </li> </ul> <H>Cursor movement</H> <ul> <li> <kbd>j</kbd> up </li> <li> <kbd>k</kbd> down </li> <li> <kbd>h</kbd> left </li> <li> <kbd>l</kbd> right </li> </ul> <H>Cursor history</H> <ul> <li> <kbd>Ctrl+o</kbd> jump back in history location </li> <li> <kbd>Ctrl+i</kbd> jump forward in history location </li> <li> <kbd>Ctrl+g</kbd> show cursor position + file name </li> </ul> <H>Jump by line (go to)</H> <ul> <li> <kbd>15G</kbd> jumps to line #15 </li> <li> <kbd>:15</kbd> jumps to line #15 </li> <li> <kbd>gg</kbd> jumps to first line </li> <li> <kbd>G</kbd> jumps to last line </li> <li> <kbd>M</kbd> jumps down to the middle of visible text (not scrolling) </li> </ul> <H>Jump by sentence</H> <ul> <li> <kbd>{ }</kbd> / <kbd>{ }</kbd> jump to start/end of the sentence </li> </ul> <H>Jump by paragraph</H> <ul> <li> <kbd>{ }</kbd> / <kbd>{ }</kbd> jump to start/end of the paragraph </li> </ul> <H>Jump by bracket</H> <ul> <li> <kbd>{ }</kbd> / <kbd>{ }</kbd> open go to prev/next menu </li> <li> <kbd>{ }</kbd> go to block }</code> </li> <li> <kbd>{ }</kbd> go to block }</code> </li> <li> <kbd>{ }</kbd> go to block }</code> </li> <li> <kbd>{ }</kbd> go to block }</Code>) </li> </ul> <H>Jump to matching bracket</H> <ul> <li> <kbd>%</kbd> jumps to closing bracket </li> </ul> <H>Jump by variable instance</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next variable instances </li> </ul> <H>Jump by function</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next function start </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next function end </li> </ul> <H>Jump by parameter</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next parameter start </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next parameter end </li> </ul> <H>Jump by method</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next method start </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next method end </li> </ul> <H>Jump by class</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next class start </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next class end </li> </ul> <H>Jump by scope</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to start/end of scope </li> </ul> <H>Jump by error, warning, spell, diagnostic</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next error </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next warning </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next spell issue (<kbd>Space us</kbd> to enable spell check) </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next diagnostic message </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> jumps to prev/next TODO or FIXME comment </li> <li> <kbd>Space cd</kbd> show full error message under cursor </li> </ul> <H>Jump by hunk (changes)</H> <ul> <li>Hunk - modifications that haven }</kbd>/<kbd>{ }</kbd> jumps to prev/next changes </li> </ul> <H>Go back/forward</H> <ul> <li> <kbd>Ctrl+o/i</kbd> go back/forward </li> </ul> <H>Go to definition</H> <ul> <li> <kbd>gd</kbd> go to definition </li> </ul> <H>Go to reference</H> <ul> <li> <kbd>gr</kbd> go to reference, shows the list of all files which uses the variable </li> <li> <kbd>Space sR</kbd> resumes your previous list </li> <li> <kbd>Alt+t</kbd> open all results in Trouble </li> </ul> <H>Go to symbol</H> <ul> <li> <kbd>Space ss</kbd> show list of symbols in file </li> <li> <kbd>Space cs</kbd> same, but another view, on the right side </li> <li> <kbd>Space sS</kbd> show list of symbols in project </li> </ul> <H>Show context info</H> <ul> <li> <kbd>K</kbd> show info (for ex. function signature from LSP) </li> </ul> <H>Marks</H> <ul> <li> <kbd>ma</kbd> mark line with <code>a</code> </li> <li> <kbd> </kbd> open list with marks </li> <li> <kbd>Space sm</kbd> same, but different view with search </li> <li> <kbd>:delmarks a</kbd> delete the mark <code>a</code> </li> <li> <kbd>:delm a</kbd> same, delete the mark <code>a</code> </li> <li> <kbd> .</kbd> jumps to the last place I inserted or changed text </li> </ul> <H>Find</H> <ul> <li> <kbd>fx</kbd> puts you in Find mode and jumps to the nearest <code>x</code> </li> <li> <kbd>;</kbd>/<kbd>,</kbd> jumps to the next/prev one </li> <li> <kbd>3fx</kbd> jumps to the 3rd <code>x</code> from you </li> <li> <kbd>F</kbd> searches backwards </li> </ul> <H>To</H> <ul> <li> <kbd>t</kbd> same as Find mode, but puts cursor before the found char </li> <li> <kbd>t</kbd> searches for next char </li> </ul> <H>Seek</H> <ul> <li> <kbd>s</kbd> seek mode </li> <li>you may jump to any visible text simply by typing part of it</li> <li>and press green label character</li> </ul> <H>Seek in object</H> <ul> <li>May seek inside text object where your cursor is</li> <li> <kbd>vS</kbd>/<kbd>dS</kbd>/<kbd>cS</kbd>/<kbd>yS</kbd> select/delete/change/copy & enter into SEEK mode </li> <li>Green labels will surround the text part, a,b,c,d,e... from the inner to outer</li> </ul> <H>Seek remote</H> <ul> <li> May for ex copy (yank) something from remote place <kbd>r</kbd> </li> <li> <kbd>yr</kbd> (enters into Seek mode) + <kbd>phrase</kbd> + <kbd>ib</kbd> (inside brackets) </li> <li>Cursor comes back to the initial place</li> </ul> <H>Seek remote object</H> <ul> <li> Copy something from remote object with <kbd>R</kbd> (capital) </li> <li>Cursor comes back to original position</li> <li> <kbd>yR</kbd> (enters into Seek mode) + <kbd>phrase</kbd> + <kbd>a</kbd> (tag) </li> </ul> <H>Surrounding Pair</H> <ul> <li> To change quotation marks or brackets, or content inside enable <code>mini.surround</code>{ } extra plugin </li> <li>Select some text</li> <li> <kbd>gsa</kbd> add surrounding to selection </li> <li> <kbd> </kbd>/<kbd> }</kbd>/<kbd>{ }</kbd>/<kbd>{ }</kbd> add braces with empty spaces </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd>/<kbd>{ }</kbd> add braces without empty spaces </li> <li> Instead of selecting the text first may do directly <kbd>gsaiB </kbd> will surround text between the cursor and the end of the line with double quotation marks </li> <li> <kbd>gsaSb }</kbd> delete surrounding square brackets </li> <li> <kbd>{ }</kbd> delete the second set of curly braces from cursor position </li> <li> <kbd>gsr </kbd> replace double quotes with single </li> <li> <kbd>gsfb</kbd>/<kbd>gsFb</kbd> jump to next/prev bracket </li> <li> <kbd>gsfb</kbd> highlight paired braces </li> <li> <kbd>gsat</kbd> add tags around selection </li> </ul> <H>Scroll</H> <ul> <li> <kbd>Ctrl+d/u</kbd> scroll down/up 50% </li> <li> <kbd>Ctrl+f/b</kbd> scroll down/up 100% </li> <li> <kbd>5</kbd> <kbd>Ctrl+f</kbd> scroll down 5 screens </li> <li> <kbd>Ctrl+e/y</kbd> scroll down/up 1 line </li> <li> <kbd>z</kbd> <kbd>t/b</kbd>scroll up/down to move active line almost to the top/bottom </li> <li> <kbd>zz</kbd> scroll to move active line to the middle </li> </ul> <H>Delete (verb)</H> <ul> <li> <kbd>d</kbd> [number] motion - delete operator </li> <li> <kbd>dh</kbd>/<kbd>dl</kbd> delete the character to the left/right of the cursor. </li> <li> <kbd>dw</kbd> delete to the beginning of next word </li> <li> <kbd>d2w</kbd> delete 2 words </li> <li> <kbd>de</kbd> delete to the end of the word </li> <li> <kbd>db</kbd> delete to the start of the word </li> <li> <kbd>d0</kbd> delete to the start of the line </li> <li> <kbd>d$</kbd> delete to the end of the line </li> <li> <kbd>dd</kbd> delete whole line (shortcut) </li> <li> <kbd>2dd</kbd> delete 2 lines </li> <li> <kbd>d2fe</kbd> delete to the second <code>e</code>, including <code>e</code> </li> <li> <kbd>d2ta</kbd> delete to the second <code>a</code> </li> <li> <kbd>dsfoos</kbd> the label <code>s</code> that pops up when you use Seek mode to seek to{ } <code>foo</code>. Note that Seek mode jumps to the beginning of the word </li> <li> <kbd>D</kbd> delete to the end of the line (shortcut) </li> <li> <kbd>diq</kbd>/<kbd>daq</kbd> delete inside nearest quotes / including quotes </li> <li> <kbd>dib</kbd>/<kbd>dab</kbd> delete inside nearest brackets / including brackets </li> <li> <kbd>diw</kbd>/<kbd>daw</kbd> delete nearest word / word and whitespaces around </li> </ul> <H>Delete char (verb)</H> <ul> <li> <kbd>x</kbd> delete char under cursor </li> <li> <kbd>5x</kbd> delete 5 chars </li> <li> <kbd>X</kbd> delete char before cursor </li> </ul> <H>Change (verb)</H> <ul> <li> <kbd>c</kbd> - deletes and inters into Insert mode </li> <li> same as <kbd>d</kbd> + motion + <kbd>i</kbd> </li> <li> <kbd>cw</kbd> deletes to the end of the word & enters into Insert mode </li> <li> <kbd>cc</kbd> changes whole line (shortcut) </li> <li> <kbd>C</kbd> changes to the end of the line (shortcut) </li> <li> <kbd>ciq</kbd>/<kbd>caq</kbd> changes inside nearest quotes / including quotes </li> <li> <kbd>cib</kbd>/<kbd>cab</kbd> changes inside nearest brackets / including brackets </li> <li> <kbd>ciw</kbd>/<kbd>caw</kbd> changes nearest word / word and whitespaces around </li> <li> <kbd>cag</kbd> changes whole file </li> </ul> <H>Replace char (verb)</H> <ul> <li> <kbd>r</kbd> go into replace mode of single char, then <kbd>a</kbd> to replace with{ } <code>a</code> </li> <li> <kbd>R</kbd> go into global replace mode </li> </ul> <H>Join lines</H> <ul> <li> <kbd>J</kbd> join lines merging white spaces </li> <li> <kbd>gJ</kbd> join lines keeping white spaces </li> </ul> <H>UpperCase & LowerCase</H> <ul> <li> <kbd>~</kbd> inverts case under the cursor </li> <li> <kbd>gU</kbd>/<kbd>gu</kbd> upper/lower case mode </li> <li> <kbd>gUU</kbd>/<kbd>guu</kbd> same, for whole line </li> </ul> <H>Dot repeat</H> <ul> <li> <kbd>.</kbd> repeats the verb </li> <li> <kbd>2.</kbd> repeats the verb two times (if you removed 3 lines with <kbd>3dd</kbd>,{ } <kbd>2.</kbd> will not remove 6 lines, but 2) </li> </ul> <H>Record command</H> <ul> <li> <kbd>qq</kbd> start recording and store commands into <code>q</code> named register </li> <li> <kbd>q</kbd> stop recording </li> <li> <kbd>qQ</kbd> continue recording (append commands to <code>q</code> register) </li> <li> <kbd>Q</kbd> play most recent recording </li> <li> <kbd>@a</kbd> play back recording stored at <code>a</code> register saved previously by{ } <kbd>qa</kbd> </li> <li> <kbd>@@</kbd> replay whichever register you most recently played </li> <li> To edit the recording just past it from the register by <kbd> } <code>q</code> register by <kbd> } <code>https</code> </li> <li> <kbd>\V</kbd> disable regexp for following search string </li> </ul> <H>Search and replace in file with Nvim-rip-substitute</H> <ul> <li>It is the plugin which has familiar dialog and easy to use</li> <li> Create <code>~/.config/nvim/lua/plugins/rip-substitute.lua</code> and restart NeoVim <Code block jsx>{ chrisgrieser/nvim-rip-substitute , function() require( ).sub() end, mode = { }, desc = , }, }, } }</kbd> will find <code>bar</code>,{ } <code>baz</code>, <code>ban</code> </li> </ul> <H>Search in project</H> <ul> <li>Telescope and RipGrep to be installed</li> <li> Maybe need to enable Telescope plugin via <kbd>:LazyExtras</kbd> </li> <li> <code>brew install ripgrep</code> install, it was not installed for me </li> <li> <kbd>Space /</kbd> open search prompt </li> <li> <kbd>Space sg</kbd> same </li> </ul> <H>Find and replace in file Vim way</H> <ul> <li> <kbd>:substitute</kbd> / <kbd>:s</kbd> enter into substitute mode </li> <li> <kbd>:s/old/new</kbd> replaces first occurrence in line where your cursor is </li> <li> <kbd>:.s/old/new</kbd> same, but specifically indicate that operation is done on the same line, can be omitted as it is the default behavior </li> <li> <kbd>:s/old/new/g</kbd> replaces all occurrences in line where your cursor is </li> <li> <kbd>:%s/old/new</kbd> replaces first occurrences in every line of in whole file </li> <li> <kbd>:%s/old/new/g</kbd> same, but all occurrences </li> <li> <kbd>:5s/old/new/g</kbd> replaces at line 5 </li> <li> <kbd>5G</kbd> maybe it is easier to jump to line 5 and then make replacement </li> <li> <kbd>:2,5s/old/new/g</kbd> replaces all occurrences in 2...5 lines </li> <li> <kbd>:,50s/old/new/g</kbd> replaces all occurrences from current line to line #50 </li> <li> <kbd>:,/text/s/old/new/g</kbd> replaces from current line to the first line with <code>text</code> including the line </li> <li> <kbd>:%s/old/new/gc</kbd> replaces in file with prompt, useful when you need to skip some replacements </li> <li> <kbd>:%s/old/new/gc</kbd> <code>c</code> prompt flag, replaces in file with prompt, useful when you need to skip some replacements </li> <li> <kbd>:%s/old/new/gI</kbd> <code>I</code> case sensitive flag </li> <li> <kbd>:s//new</kbd> if you omit search phrase, it replaces whatever pattern you last searched with </li> <li> <kbd>:s</kbd> without any pattern or replacement, it will repeat the last pattern and replacement you did, but it will not use any previous flags, so most useful would be{ } <code>:%sg</code> which means “repeat the last substitution on the entire file, globally.” </li> </ul> <H>Find and replace in project</H> <ul> <li> <kbd>Space sr</kbd> open dialog </li> <li> <kbd>j</kbd>/<kbd>k</kbd> jump between fields </li> <li>As you type you get instant live update with proposed changes</li> <li> To accept changes you need to go back into normal mode with <kbd>Esc</kbd> and then{ } <kbd>\r</kbd> to apply replacement </li> <li> You may modify replacement in preview window or even skip some replacements by deleting the preview line by <kbd>dd</kbd>. After that <kbd>\s</kbd> to sync changes. </li> <li> Press <kbd>Enter</kbd> over like in preview to jump to a source file </li> <li> <kbd>\t</kbd> open search history and <kbd>Enter</kbd> to reuse it </li> </ul> <H>External command</H> <ul> <li> <kbd>:!ls</kbd> show files </li> <li> <kbd>:!rm FILENAME</kbd> remove FILENAME file </li> </ul> <H>Read content and paste</H> <ul> <li> <kbd>:r TEST</kbd> reads content from the file TEST and pastes below the cursor </li> <li> <kbd>:r !ls</kbd> reads content from external command and pastes below the cursor </li> </ul> <H>Search file </H> <Hs>Search files in Current Working Directory</Hs> <ul> <li> <code>Current Working Directory</code> (CWD) is the directory where your terminal was in when you typed <code>nvim</code> </li> <li> <kbd>Space fF</kbd> files fuzzy search in (CWD) </li> <li> To check where you are, type <kbd>:pwd</kbd> (Print Working Directory) </li> <li> To change CWD <kbd>:cd path/to/directory</kbd> </li> <li> To change CWD just in one tab <kbd>:lcd path/to/directory</kbd> </li> </ul> <Hs>Search files in Root Directory</Hs> <ul> <li> <code>Root Directory</code> is where <code>package.json</code> or{ } <code>tsconfig.json</code> </li> <li> <kbd>Space Space</kbd> files fuzzy search in current project </li> <li> <kbd>Space ff</kbd> same </li> <li> Root Directory may be confusing, coz they may change silently. Imagine you are in a monorepo with multiple tsconfig.json files and you will have different{ } <code>Current Working Directory</code> depending on which file you are working on. In this case you may want to search relative to CWD </li> <Hs>Search gotchas</Hs> <li>Search is case insensitive, until you type a capital letter</li> <li> <code>phrase1 phrase2</code> - type <code>phrase1</code> first, get search results, hit{ } <kbd>Space</kbd>, type second <code>phrase2</code>, already visible results will be narrowed by fuzzy search with second phrase, super convenient </li> <li> <kbd>Alt+s</kbd> seek mode (may need to enable <kbd>Alt</kbd> first{ } <Code>iTerm2 → Preferences → Profiles → [your profile] → Keyboard</Code> and set Left Option Key to: <code>Esc+</code>) </li> <li> <kbd>Ctrl+j</kbd> <kbd>Ctrl+k</kbd> move down/up in the list </li> <li> <kbd>Ctrl+h</kbd> backspace </li> <li> <kbd>Tab</kbd> select multiple results </li> <li> <kbd>Enter</kbd> confirm selection </li> <li> <kbd>Esc Esc</kbd> exit from search mode </li> </ul> <H>Explorer</H> <ul> <li> <kbd>Space e</kbd> open file explorer at Root Directory </li> <li> <kbd>Space E</kbd> open file explorer at CWD </li> <li> <kbd>j</kbd>/<kbd>k</kbd> down/up </li> <li> <kbd>3j</kbd> jump down 3 lines </li> <li> <kbd>Enter</kbd> expand/collapse folder </li> <li> <kbd>Backspace</kbd> go to parent folder </li> <li> <kbd>Enter</kbd> expand/collapse folder </li> <li> <kbd>Tab</kbd> multiple select </li> <li> <kbd>Ctrl+f/b</kbd> scroll down/up </li> <li> <kbd>i</kbd> jump to search field in Insert mode to search for a specific file </li> <li> <kbd>Alt+s</kbd> seek mode during Insert mode </li> <li> <kbd>s</kbd> seek mode also covers the explorer window </li> <li> <kbd>d</kbd> delete file </li> <li> <kbd>a</kbd> add file/folder </li> <li> <kbd>r</kbd> rename </li> <li> <kbd>y</kbd>/<kbd>p</kbd> copy/paste </li> <li> <kbd>m</kbd> move file </li> <li> <kbd>?</kbd> being focused on explorer - help window with other useful shortcuts </li> </ul> <H>mini.files</H> <p>Like explorer, but more Vim-ish</p> <Hs>mini.files Installation</Hs> <ul> <li> Go to LazyVim extras by <kbd>x</kbd> from the dashboard </li> <li> Move your cursor to the line that contains <code>mini.files</code> </li> <li> Press <kbd>x</kbd> to install, then restart NeoVim </li> </ul> <Hs>mini.files Usage</Hs> <ul> <li> <kbd>Space fm</kbd> open dir of current file at explorer </li> <li> <kbd>Space fM</kbd> open the directory where your terminal was in when you typed{ } <kbd>nvim</kbd> (CWD) </li> <li> <kbd>j</kbd>/<kbd>k</kbd> move up/down </li> <li> <kbd>h</kbd>/<kbd>l</kbd> move out/in </li> <li> <kbd>o</kbd> add file/folder </li> <li> <kbd>dd</kbd> delete </li> <li> <kbd>i</kbd> go to Insert mode to rename </li> <li> <kbd>yy</kbd> copy </li> <li> <kbd>p</kbd> paste </li> <li> <kbd>q</kbd> close the explorer view </li> <li> <kbd>=</kbd> save changes </li> </ul> <H>Useful</H> <ul> <li> <Lnk path= > vim plugin for vscode </Lnk> </li> <li> <Lnk path= > learn vim plugin for vscode </Lnk> </li> <li> <kbd>vimtutor</kbd> terminal app to learn vim on most Unix operating systems </li> <li> <Lnk path= >cheatsheet</Lnk> </li> </ul> <H>NeoVim</H> <ul> <li> <Lnk path= >https://neovim.io/</Lnk> is Vim-based text editor </li> <li> <Lnk path= >LazyVim </Lnk> is opinionated popular Neovim setup </li> <li> <Lnk path= >LazyVim </Lnk> keybindings </li> </ul> <H>Font</H> <ul> <li> <Lnk path= > https://www.nerdfonts.com/font-downloads </Lnk> </li> <li>Download FiraCode Nerd Font, unzip, install all fonts</li> <li>Open iTerm2, then Preferences, then Profiles, then Text, pick FiraCode Nerd Font</li> <li>Restart the terminal</li> </ul> <H>Dashboard</H> <ul> <li> <kbd>:lua Snacks.dashboard()</kbd> open dashboard from editor </li> </ul> <H>Plugins</H> <ul> <li> The Lazy Extras mode can be accessed by pressing <kbd>x</kbd> from the dashboard or </li> <li> <kbd>:LazyExtras</kbd> from the editor </li> <li> Navigate and press <kbd>x</kbd> to pick </li> <li>Relaunch NeoVim</li> <li> <kbd>Space cm</kbd> open Mason, some other plugin list, alternative to LazyExtras </li> </ul> <H>Buffers</H> <ul> <li> <kbd>H</kbd>/<kbd>L</kbd> switch buffers visible in the currently active window </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> same, switch buffers </li> <li> <kbd>Space ,</kbd> open current buffer list </li> <li> <kbd>Ctrl+x</kbd> close buffer from the list </li> <li> <kbd>Space Space w </>/+/- }</kbd> to continuously resize </li> <li> <kbd>Space uz</kbd> go into Zen mode, center the window and dim all around </li> </ul> <H>Tabs</H> <p>Skipped, did not understand why it is needed...</p> <H>Fold</H> <ul> <li> <kbd>z c/a</kbd> fold / unfold </li> <li> <kbd>za</kbd> toggle folding </li> <li> <kbd>zR</kbd> unfold all </li> <li> <kbd>zO</kbd> unfold all folds under cursor </li> </ul> <H>Session</H> <ul> <li>Session keeps information about windows, splits and tabs</li> <li> <kbd>Space qq</kbd> to exit LazyVim </li> <li> <kbd>cd</kbd> to the project and open NeoVim by <kbd>nvim</kbd> </li> <li> <kbd>s</kbd> to restore the last session </li> <li> <kbd>Space qs</kbd> same, restore session </li> <li> <kbd>Space qS</kbd> open session list, can be useful to see last opened projects </li> <li> <kbd>Space qd</kbd> close without saving the session, useful when you temporarily opened NeoVim and close it </li> </ul> <H>Language server</H> <ul> <li> <kbd>:LspRestart</kbd> restart the language server </li> <li> <kbd>:checkhealth</kbd>/<kbd>:LazyHealth</kbd> health of various installed plugins (do not expect all to be green) (there are overlaps, LazyHealth is easier to read) </li> <li> <kbd>Space xx/xX</kbd> show diagnostic window with list of errors </li> </ul> <H>Code action</H> <ul> <li> <kbd>Space ca</kbd> open code actions </li> </ul> <H>Notice</H> <ul> <li> NeoVim has a notice window in the top right corner where some important messages pops up once in a while </li> <li> <kbd>Space cna</kbd> show list of messages </li> </ul> <H>ESLint</H> <ul> <li> Lint plugin for NeoVim <code>nvim-lint</code> </li> <li> Add file <code>~/.config/nvim/lua/plugins/nvim-lint.lua</code> </li> </ul> <Code block lua>{ mfussenegger/nvim-lint BufReadPre BufNewFile ) lint.linters_by_ft = { javascript = { }, typescript = { }, javascriptreact = { }, typescriptreact = { }, } -- Always use the project node_modules/.bin node_modules/.bin/eslint /node_modules/.bin/eslint$ )) end -- 2) nearest ESLint config local cfg = vim.fs.find({ , , , , , , }, { path = start, upward = true })[1] if cfg then return vim.fs.dirname(cfg) end -- 3) git root, then current cwd local git = vim.fs.find( , { path = start, upward = true })[1] return git and vim.fs.dirname(git) or vim.loop.cwd() end vim.api.nvim_create_autocmd({ InsertLeave }</Code> <H>Formatter</H> <ul> <li> Lint plugin for NeoVim <code>conform</code> </li> <li> Add file <code>~/.config/nvim/lua/plugins/conform.lua</code> </li> </ul> <Code block lua>{ stevearc/conform.nvim }, javascriptreact = { }, typescript = { }, typescriptreact = { }, json = { }, css = { }, html = { }, yaml = { }, markdown = { }, -- add more filetypes if needed }, }, } } <kbd>S</kbd> is invoked </li> <li> <kbd>V5jgc</kbd> commenting can be applied on visual mode, select 5 lines and then comment them </li> <li> <kbd>gco</kbd>/<kbd>gcO</kbd> add comment below/above </li> </ul> <H>Indent</H> <ul> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> indent the line where cursor is </li> <li> Select text and <kbd>{ }</kbd>/<kbd>{ }</kbd> to indent </li> <li>Indentation is always applied automatically with formatting on save</li> <li> <kbd>gqag</kbd> format the entire file </li> <li> Also may select text and hit <kbd>=</kbd> to fix indentation </li> <li> <kbd>{ }</kbd> fix indentation for active line </li> <li> In Insert mode <kbd>Ctrl+t/d</kbd> to indent (“add tab” and “dedent”) </li> </ul> <H>Wrap</H> <ul> <li> <kbd>gww</kbd> wrap line to 80 chars </li> <li> <kbd>gwip</kbd> wrap paragraph </li> <li> <kbd>gwig</kbd> wrap file </li> <li> <kbd>{ }</kbd> set wrap width </li> </ul> <H>Spell check</H> <ul> <li> <kbd>Space us</kbd> enable/disable spell check </li> <li> <kbd>{ }</kbd>/<kbd>{ }</kbd> next/prev misspelled word </li> <li> <kbd>z=</kbd> show suggestion </li> </ul> <H>Snippets & Abbreviations</H> <ul> <li> <Lnk path= > check later... </Lnk> </li> </ul> <H>Terminal in vim</H> <ul> <li> <kbd>Ctrl+/</kbd> open Vim s own terminal) </li> <li> <kbd>Esc</kbd> exit from Insert to Normal mode (that is how zsh is configured) </li> <li> <kbd>a</kbd>/<kbd>i</kbd> go into Insert mode </li> </ul> <H>Git in</H> <ul> <li> <kbd>Space gs</kbd> opens list of changed files </li> <li> <kbd>Space gc</kbd> opens list of commits </li> <li> <kbd>Space ghs</kbd> stage hunk </li> <li> <kbd>Space ghS</kbd> stage file </li> <li> <kbd>Space ghr</kbd> reset hunk </li> <li> <kbd>Space ghR</kbd> reset file </li> <li> <kbd>Space ghu</kbd> unstage hunk </li> <li> <kbd>Space ghb</kbd> git blame, check commit for the active line </li> <li> <kbd>Space ghp</kbd> preview the hunk, what has been changed </li> <li> <kbd>Space ghd</kbd> show diff between the current file (right) and the staging index file (left) </li> <li> <kbd>Space ghD</kbd> show diff between the current file and the last commit </li> <li> <kbd>:diffoff</kbd> disable diff mode, then <kbd>Space bd</kbd> to close the buffer </li> <li> <code>brew install lazygit</code> install and learn LazyGit, useful plugin to work with Git </li> <li> <kbd>Space gg</kbd> open LazyGit (after installation) </li> <li> <Lnk path= > Continue </Lnk>{