Avoid vs-****. Neovim is better.

Basic

  • fn + f12 for yakuke terminal
  • netrc - ctrl + o
  • d for dir
  • % for file
  • /home/guts/.config/nvim - config file path
  • == re-adjust tabs to spaces
  • nvim .

after / plugin - is automatically sourced
lua/ - is ready to be acquired

netrw

init - updates the files, make sure everything is ready,
after - once the above thing is done, now configure stuffs on initialized plugins.

X fix color scheme - transparent - tokyo night

sourcing manual:

:so %
:PackerSync
:VimBeGood

yank highlighted region
highlight another line, and Paste
** if you paste again… the stuffs that got replaced by Pasting previously appears again, because, delete and yank uses same buffer **

COMMAND - COUNT - MOTION
eg: d 10 j > removes 10 lines

  • r reverse

  • s sort-by

  • gh toggle hidden files

  • R rename

  • D delete file

  • u equivalent to backspace. traverse last visited folder.

  • - go to parent folder

  • % create a file

  • d create a directory

  • mf mark files / directories

  • mt mark target directory - used my copy / move commands

  • mc copy the marked files

  • mm move the copied files

  • mu clear all previous markings

  • mx execute a command on the marked files. example: rm -r


Lesson 2

  • _ move to the beginning of the sentance
  • 0 move to the literal beginning of the sentance
  • $ to end of line
  • f<char> moves to first occurance of char in the line
  • t<char> moves just before the first occurance
  • F <char> performs the same, but in search in reverse direction
  • T <char>
  • ; repeat forward f/t <char>
  • , repeat backward
  • I insert mode at the beginning of the line
  • A at the end of the line
  • o - make a newline and Insert mode
  • O - make a newline above the cursor and Insert mode
  • Selects==align automatically
  • =ap 8 space indenting

  • ctrl + d = skip half page (fast scrolling)
  • ctrl + u = "" "" up

  • V - Visual Line
  • K,J - move highlighted text
  • n, N - Next term on search
  • _p - better than normal paste
  • _y - yank into system clipboard (+ register)
  • y - is just within vim
  • _s : replace all

Advanced:

visual actions

  • vi{ | vi[ | vi( - select contents between paranthesis
  • va - including the brackets
  • ya( yi{ - just yank
  • yap - full paragraph (bw space)
  • da di
  • ca ci" - cuts & insert mode
  • sa si
  • viw/W - select a word / until spaces
  • o in V jumps b/w end
  • >4j intend
  • yap / dap / yip / dip - a to nuke white space, i to preserve it
  • Ctrl+a increment
  • Ctrl+x decrement
  • (https://learnbyexample.github.io/tips/vim-tip-1/)
  • ctrl+v multiple cursor -> I insert (type) and press escape

normal mode commandline

ref

  • :'<,'>norm _i{src=f,i} - to get ^[ use Ctrl+v and then press escape. This command simply adds a flower bracked for the selected range. _i goes to the first character apart from whitespace and goes to insert mode.
  • :'<,'>norm I{src=f,i}

Windo diffs

  • _wt - alias for :windo diff this
  • _wo - alias for :windo diff off

Replace All:

  • Highlight with v
  • press ':'
  • s/\(\w.*\)
  • TODO: use capture group to do substitution (slash 1 on first match) to do complex stuffs ig

Replace with confirmation: :s/search/replacement/gc

  • select g + ctrl + a increment all numbers
  • % - jump between brackets
  • gd - jump to definition
  • gh select the right side changes on diff view - need more guide
  • gv - select last selected
  • gi - last insert position
  • ga - ascii, hex, octal of a character
  • ctrl w o (close all window except the hightlighted)

  • { - paragraph jump

  • G - to bottom

  • gg - to top

  • <leader>gc - comment lines in visual mode (select multiple lines and fire the keybind)

  • :100 (exact jump)

  • /fun - search -n / N

  • ?fun

  • * highlighted word search

  • /word1\|word2\|word3 multiple search highlights

  • check from 12:44

  • also check

  • Ctrl w o close all window

  • Ctrl w = equal size of all windows

  • Shift + K ⇒ get function description

  • :setlocal spell - enable spell check in current buffer

  • :g/func/# - list out all functions in a file

  • :v/pattern/d - inverse regex matches, and delete the lines

  • :dlist / - list file specific definitions from root - check these in your free time :help definition-search, :help 'include', :help 'define', :help 'suffixesadd'

  • :vimgrep something %

  • :copen - quickfix list with results populated from above command

  • :cn, :cp - next / prev item in a quickfix list (better than <Ctrl ww> and switching back and forth)

  • :ccl - close quickfix list

  • :cdo command - apply the commands only on the files that that are present in quickfix list.

  • :retab - space to tabs

  • https://stackoverflow.com/questions/13306664/pipe-search-result-to-other-tab-window-buffer-in-vim

  • https://vi.stackexchange.com/questions/5941/summary-of-functions-in-current-file

  • :set spell do spell checks on text

  • :set linebreak - wraps entire word around to the next line. (unline wrap which breaks the word)

Redirect search results to a new buffer

:redir @a
:g/for.*bar/#
:redir END
:enew
:put! a

Redir even better

Resize window

  • Ctrl+W +/-: increase/decrease height (ex. 20<C-w>+)
  • Ctrl+W >/<: increase/decrease width (ex. 30<C-w><)
  • Ctrl+W _: set height (ex. 50<C-w>_)
  • Ctrl+W |: set width (ex. 50<C-w>|)
  • Ctrl+W =: equalize width and height of all windows

See also: :help CTRL-W

netrw shortcuts


  • set foldmethod=indent - for python folding
  • :5,16fo
  • select lines + fo: fold lines
  • ^ this is range in commands
  • za toggle between fold
  • zR unfold all
  • zM fold all
  • zE delete all folds
  • Ctrl w v - vertical split window or :vs
  • :on closes all other windows
  • Ctrl w r - rotate windows

macros

  • qa - it saves your movements on buffer ‘a’. stop macro recording by pressing ‘q’
  • to, replay the macro, in normal mode: @a
  • 500@a
  • :g/pattern/normal @q run a macro on all matches (have to test) decent fcc vim guide

Bulk Cut Paste matching pattern

  • /KC_\w*: pattern
  • qh: record movements at buffer ‘@h’
  • ndiw<Ctrl>wwp<Ctrl>ww: perform this movement to paste the cut word in another window
  • 100@h - repeat until everything is done
  • :sort u - keep only unique values
  • :'<,'>s/\\//g - string json → json. (don’t forget to remove the surrounding " quotes tho)
int encrypt_text(char *text, int bytes);
int decrypt_text(char *text, int bytes);
int process_text(char *text, int bytes);
int another_important_function(int bytes, double precision);

Fugitive

  • https://t.me/ERsiowj12h6s7w282jwheyueyywkwlwj/5496

  • https://dzx.fr/blog/introduction-to-vim-fugitive/#introduction

  • vim casts

  • do dp diffget and diffput for selecting hunk. works on range too

  • :G log -- % commits made on current file

  • :G diff-tree --no-commit-id --name-only -r <commit_id> list of changed files of a commit

  • :G diff --name-only temp/VP-686-query-profiling VP-686-query-profiling - list of changed files between two branches

  • :G rebase development -i --auto-squash squashes all fixup commits in the correct order

  • :G reset HEAD~1 --soft (default is soft btw) - undo a commit and put all the changes to stash

  • gh select the right side changes on diff view - need more guide

neovim diff

  • sause
  • Docs
  • :vert diffsplit folder/file - vertical diff between files
nvim -d file1 file2
:diffthis
:diffoff # turns off diff in current window
:diffs file.yaml
:diffs -o file
:vert diffsplit file.yaml
:G diff a/file.yaml b/file.yaml
:G difftool a/file.yaml b/file.yaml
:h :diffsplit
:G diff @
:windo diffo
:windo difft
:Gdifftoolc branch-name
:Gdifftoolc branch-name --names-only # all the changes opens in quickfix list
:Gvdiffsplit branch-name
:Gedit branch:file-name # supports tab completion

SSH Filesystem

while surviving network failures, edit any directory / files in your nvim editor!!

sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 user@192.168.18.3:/home/user/binlog-test ~/sshfiles
nvim sshfiles
# unmount directory
fusermount -u ~/sshfiles

File ownership

The last edit username of the files will be the same as your local machine. If needed use idmap, uidfile, and gidfile to map user / group IDs correctly

  • 100i0<enter><esc>vggg<ctrl-a> dope. g<ctrl-a> modifies the increment behaviour
  • The Power of :g

Other Cool Things

  • link
  • .nvim-commands.lua - to have keybindings with Toggleterm (F1 to build), (F2 to run), (F3 to run the test under the cursor 🤫). Saves the overhead of switching terminal and typing each time. the repo
-- Load toggle term
["t"] = { "<cmd>ToggleTerm<CR>", "toggle toggleterm" },
["T"] = { "<cmd>ToggleTerm direction=tab<CR>", "toggle toggleterm (tab)" },
-- Load nvim-commands file
["n"] = { "<cmd>luafile .nvim-commands.lua<CR>", "load nvim-commands.lua" },
  • Copy the huge string literal (longest was several paragraphs of Lorem Ipsum), and use a macro to get each word on its own line. Then I filtered it through sort, then uniq -c, then a :s with some backreferences and boom I had so many lines of theMap.insert or whatever the method is called for a Java hashmap.
  • telescope media!
  • compress multiple blank lines into single :v/./,/./-j

Give It A Read

Playlist Making

unpack uri provider: https://claude.ai/chat/71ec0667-1432-4247-bc7e-0700426bdc00

%s/C:/\/run\/media\/guts\/Acer/gI
%s/\\/\//gI

Run script and output to window

https://superuser.com/questions/868920/open-the-output-of-a-shell-command-in-a-split-pane

  • :vnew | 0read ! <command>

LSP

  • :LspInfo - get info
  • LspStop 2 - give ID to detach a lsp from the buffer ref

Telescope Symbol Navigation

Common LSP symbol kinds: Function, Method, Class, Interface, Constructor, Variable, Constant. accidental find: instead of symbols=Function manually, just do lsp_document_symbols, then press ctrl+l on any entry, and you can now filter based on the symbol kind, and cycle through it. Try it.

  • :Telescope lsp_document_symbols symbols=Function
  • :Telescope lsp_document_symbols symbols=Class
  • :Telescope lsp_document_symbols symbols=Function,Method,Class
  • :Telescope lsp_document_symbols symbols=Enum,Null,Struct
  • :Telescope resume - continue popup window from where you left off. Alt + e to trigger telescope resume.

TIP

press TAB on telescope results to mark them (the little + icon), then press Alt+q instead of Ctrl+q to open quickfix list, but only with the items you marked earlier.

Then to fuzzy-filter over the results (e.g. type async to narrow results).

  • :Telescope lsp_document_symbols symbols=Function initial_query=async (TODO: idk how opencode Gwen 3.6 free found about initial_query options, I couldn’t find it in telescope.nvim man pages yet)

NOTE

For the full enum list, check microsoft lsp docs, scroll a bit down, and see SymbolKind definition

TIP

telescope and treesitter should be upgraded together, and check supported neovim version in README.md. treesitter docs

Telescope fuzzy find patterns

Modifiers: docs

  • 'wild - exact match (no fuzzy) (includes “wild”)
  • ^music - starts with “music”
  • .mp3$ - ends with “.mp3”
  • !fire - excludes items containing “fire”
  • !^music - doesn’t start with “music”
  • !.mp3$ - doesn’t end with “.mp3”

Operators:

  • .json | .md - list both the results
  • ^core go$ | rb$ | py$ - starts with core, ends with go, rb, or py

Friendly Snippets

https://github.com/rafamadriz/friendly-snippets/tree/main

  • Ctrl + f: select the next highlight in snippet
  • Ctrl + b: select the prev highlight in thte snippet

Mason, lsp-zero, null-ls relation

https://www.reddit.com/r/neovim/comments/13xyixb/some_questions_about_code_formatting_with_lspzero/

  • use conform.nvim instead, null-ls is archived

Replace \n with actual new line

You get ^M character by presssing ctrl+v and then enter

  • set magic
  • :s/,/,^M/g
  • ref

Get items from drop down list from DND Beyond site

Copy outerHTLMElement from inspect tab, put them in a temp.html file. prettier html format

:%!prettier --stdin-filepath %
:v/<\/label/d
:%s/<\/label/
:%s/\/>/