Avoid vs-****. Neovim is better.
Basic
- fn + f12 for yakuke terminal
- netrc - ctrl + o
dfor 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
ctrl - o & ctrl - I- previous location & next location https://vim.fandom.com/wiki/Jumping_to_previously_visited_locations:jumps:vsp filename- (vertical split)ctrl ww- jump
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
Navigation
-
rreverse -
ssort-by -
ghtoggle hidden files -
Rrename -
Ddelete file -
uequivalent to backspace. traverse last visited folder. -
-go to parent folder -
%create a file -
dcreate a directory -
mfmark files / directories -
mtmark target directory - used my copy / move commands -
mccopy the marked files -
mmmove the copied files -
muclear all previous markings -
mxexecute a command on the marked files. example:rm -r
Lesson 2
_move to the beginning of the sentance0move to the literal beginning of the sentance$to end of linef<char>moves to first occurance of char in the linet<char>moves just before the first occuranceF <char>performs the same, but in search in reverse directionT <char>;repeat forwardf/t <char>,repeat backwardIinsert mode at the beginning of the lineAat the end of the lineo- make a newline and Insert modeO- make a newline above the cursor and Insert mode- Selects
==align automatically =ap8 space indenting
ctrl + d= skip half page (fast scrolling)ctrl + u= "" "" up
V- Visual LineK,J- move highlighted textn, 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:
vi{ | vi[ | vi(- select contents between paranthesisva- including the bracketsya( yi{- just yankyap- full paragraph (bw space)da dica ci"- cuts & insert modesa siviw/W- select a word / until spaceso in Vjumps b/w end>4jintendyap / dap / yip / dip- a to nuke white space,ito preserve itCtrl+aincrementCtrl+xdecrement- (https://learnbyexample.github.io/tips/vim-tip-1/)
ctrl+vmultiple cursor->Iinsert (type) and press escape
normal mode commandline
:'<,'>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._igoes 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 + aincrement all numbers %- jump between bracketsgd- jump to definitionghselect the right side changes on diff view - need more guidegv- select last selectedgi- last insert positionga- ascii, hex, octal of a characterctrl 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\|word3multiple search highlights -
check from 12:44
-
Ctrl w oclose 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 spelldo spell checks on text -
:set linebreak- wraps entire word around to the next line. (unlinewrapwhich breaks the word)
Redirect search results to a new buffer
:redir @a
:g/for.*bar/#
:redir END
:enew
:put! aResize 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
gh: hide git files- Check: https://stackoverflow.com/questions/67898068/neovim-is-transparent-but-the-auto-copplete-window-is-pink-how-to-make-it-semi-t
set foldmethod=indent- for python folding:5,16fo- select lines +
fo: fold lines - ^ this is range in commands
zatoggle between foldzRunfold allzMfold allzEdelete all foldsCtrl w v- vertical split window or:vs:oncloses all other windowsCtrl 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 @qrun a macro on all matches (have to test) decent fcc vim guide
Bulk Cut Paste matching pattern
/KC_\w*: patternqh: record movements at buffer ‘@h’ndiw<Ctrl>wwp<Ctrl>ww: perform this movement to paste the cut word in another window100@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://dzx.fr/blog/introduction-to-vim-fugitive/#introduction
-
do dpdiffget 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-squashsquashes 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 -
ghselect the right side changes on diff view - need more guide
neovim diff
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 completionSSH 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 ~/sshfilesFile ownership
The last edit username of the files will be the same as your local machine. If needed use
idmap,uidfile, andgidfileto 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, thenuniq -c, then a:swith some backreferences and boom I had so many lines oftheMap.insertor whatever the method is called for a Java hashmap. - telescope media!
- compress multiple blank lines into single
:v/./,/./-j
Give It A Read
- https://neovim.io/doc/user/lsp.html
- https://github.com/VonHeikemen/lsp-zero.nvim/blob/v2.x/doc/md/lsp.md#introduction
Playlist Making
unpack uri provider: https://claude.ai/chat/71ec0667-1432-4247-bc7e-0700426bdc00
%s/C:/\/run\/media\/guts\/Acer/gI
%s/\\/\//gIRun 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 infoLspStop 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 + eto trigger telescope resume.
TIP
press TAB on telescope results to mark them (the little
+icon), then pressAlt+qinstead ofCtrl+qto 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 aboutinitial_queryoptions, 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
SymbolKinddefinition
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 snippetCtrl + 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.nviminstead, 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/\/>/