Vim shortchuts
todo
- on cpp project it didn't detect getCharacterStats to recommend me to auto import unless I opened the file.
- try out supermaven copilot
- replace the no longer supported null-ls with none-ls
- practice search and replace and '.'
- practice with leap
- try out lazy docker and lazygit
- try out https://github.com/jmederosalvarado/roslyn.nvim plugin that adds support for the new official Microsoft C# lsp introduced in the VSCode C# extension.
this might support LSP and highlighting for Razor pages. which is an issue I have.
REQUISITES and dependencies
- python, node (with nvim package), I believe a C compiler (cygwin)
- install a nerd font for terminal (I like the JetBrains Mono or hack font)
- install ripgrep and fzf with a package manager
- (and psfzf for windows powershell), zlocation, everything
- install npm neovim package
npm install -g neovim
- install and make sure python3 is in env
- install python module to run plugins
python3 -m pip install --user --upgrade pynvim
- have a c compiler
choco intall mingw
- clone my dotenv repo
- make symlinks, make nvim look for files to the correct directory with
command here
. default windows dir isC:/Users/User/AppData/Local/nvim
or run thedev
script and it will create a sym link from the default nvim config folder to wherever I cloned the repo
- java LSP:
install jdtls, java test and java debug with Mason,
install google style guide and place it in /mason/package/jdtls/
intelliJ google style
cambiar variables que apuntan a versiones de java al lugar correcto. verificar version de java que ejecuta cmd
(tiene que ser > 17)
troubleshooting
shada file error
go to nvim-data shada folder and delete it's contents
syntax highlighting
- if I'm not getting syntax highlighting, first check that TreeSitter (TS) is installed for that language.
testing
- for neotest-jest (javascript) I might have to install jest globally
npm install -g jest
debugging
- if everything fails. debugging on vscode not something out of the ordinary. many vim users do it this way.
-
to attach node debugger to a running node process I have to make sure to run
node --inspect test.js
with the inspect flag
I can debug single js files by launching the debugger, or debug server apps (Express for example) by starting the node process with the inspect flagnode --inspect ./app.js
(if it is a typescript project I might need to first compile the project and run the compiled js file in the dist/out dir) or debug a browser application by selectingstart chrome with Localhost
. The app MUST be running on port3000
, or I can change the port in the config file. -
to change the port of svelte project (to try and debug on port 3k) go to package.json and change the dev command and add
port 3000
flag to the vite run command. or go tovite.config.ts
and addserver: {port:3000,},
inside defineConfig -
for python projects: seems that the most efficient way is to remember to install debugpy on my projects env. and use the oficial dap setup where it detects my projects env python. (can also add more if's to detect backup pythons)
LSP and null-ls
- if lsp error says it can't find executable, try uninstall and reinstalling it on Mason.
java
- JAVA JDTLS. el auto setup de mason-lspconfig ta necio. borra manualmente el script de Mason que lo inicializa en el root de mason/jdtls.
svelte
- on svelte projects, tsserver LSP and svelteLSP might conflict on some files. might need to uninstall tsserver while working with the svelte LSP.
also I might or might not need the svelteLSP to attach to .js and .ts files on svelte projects. to do this uncomment the svelte filetypes line onlsp.lua
. this might create a double diagnostic of conflict situation tho... - for eslint to work with svelte I need to add it's plugin on the eslintrc file
npm install eslint eslint-plugin-svelte
same formatting with prettier. adding a svelte plugin to prettier is necessary.npm install prettier prettier-plugin-svelte
the svelte language server comes with linting and formatting out the box
null-ls
so the mson-null-ls plugin installs and sets up eslint_d AND prettier (sets paths idk) so all I have to do to get formatting and linting is adding the .prettierrc
and .eslintrc.*
file. see eslint and prettier config files. initializing a svelte project with npm create svelte@latest <app_name>
also generates these files automatically for svelte projects
after this, extend null-ls filetypes to attach to .svelte files. (this might override the autoconfig set by mason-null-ls, comment stuff out as needed for working with svelte or other types of projects)
I could also install eslint and prettier globally (npm install -g eslint prettier
) and set null-ls source 'manually' or I could install eslint and prettier with Mason and manually add to $PATH the location of the mason generated scripts that execute the programs
or I could use eslint-lsp (installed on Mason and auto sets up) which doesn't require having a .eslintrc file in the directory as it most likely has some default config saved somewhere, the other 2 do require the file
-
null-ls might break eventually since it is archived. when it does look for migration youtube videos or set up
none-ls or conform.nvim + nvim-lint https://www.josean.com/posts/neovim-linting-and-formatting
does mason-null-ls work with none.nvim -
I can create an empty
.null-ls-root
file in the directory I want to mark as the project root for null-ls.
KEYMAPS and COMMANDS
commands
:w :q :q! :wq save, quit, quit without save
ZZ = :xa
:w new_file_name save the file under a new name and continue editing original
:sav save file under a new name and continue editing the new copy
:nmap _    gives me all mappings on whatever mode I'm in
:vsp and :terminal  quit terminal with ctrl+\ + ctrl + n
:so refresh lua source
y+ copies to system clipboard and _x means that deletes but doesn't yank, copy the value deleted (remap aclaration)
ctrl + + zoom in
ctrl + - zoom out
NAVIGATION
keys | Description |
---|---|
esc / ctrl+z / ctrl+[ | go to normal mode |
hjkl | left down up right |
_ / 0 / home | place cursor at start of line |
$ / End | place cursor at end of line |
b B | go back word by word. |
ge | go back to end of word. |
w W | go forward by start of word |
e E | go forward by end of words |
shift [,] | jump over blocks |
( { [ or % | to go to matching closing |
* or # | find next/previous occurence of word under cursor |
gg, G | go to beginning/end of file |
2G | go to line 2 |
keys | description |
---|---|
f F | move to next/previous char in line. Then use ';' and ',' to go back and forth finds |
t T | move to but not on the char in line (like f) |
- you can combine editing functions (d,c, y, v) with navigation (w,b,e, p) or with (i (inside, exclusive) , a (all, inclusive)) and limiting chars that surround the block ( (), {}, "", '', [])
p is for parragraph, or contiguos text
| keys | Description |
| ---- | ----------- |
| | |
zt    move curr line to top of screen
zb    move curr line to bottom os screen
zz    move current line to center of screen
ctrl y   scroll up
ctrl e  scroll down
[t [b [q [l   go to previous tab, buffer, q?, l?     with shift go to first/last
]t ]b ...
]m go to next method
[ + delimiter [,{,( go to start of block
]+ delimiter ],},) go to end of block
leap navigation
<>h leap forward
<>H leap backwards
<>hw leap across windows
marks and `
m_Â Â Â Â Â set a mark named with any letter/number. Upper case letters are global marks (project wide?
`_Â Â Â Â Â Â go to a set mark named with any letter/number.
`` go to position before jump
`. go to position when last edited
:marks     see marks
mx       Set mark x
m,       Set the next available alphabetical (lowercase) mark
m;Â Â Â Â Â Â Â Toggle the next available mark at the current line
dmx       Delete mark x
dm-Â Â Â Â Â Â Â Delete all marks on the current line
dm <space>Â Â Â Â Delete all marks in the current buffer
m]Â Â Â Â Â Â Â Move to next mark
m[Â Â Â Â Â Â Â Move to previous mark
m:Â Â Â Â Â Â Â Preview mark. This will prompt you for a specific mark to
preview; press <cr> to preview the next mark.
m[0-9]Â Â Â Â Â Add a bookmark from bookmark group[0-9].
dm[0-9]Â Â Â Â Â Delete all bookmarks from bookmark group[0-9].
m}Â Â Â Â Â Â Â Move to the next bookmark having the same type as the bookmark under the cursor. Works across buffers.
m{Â Â Â Â Â Â Â Move to the previous bookmark having the same type as the bookmark under the cursor. Works across buffers.
dm=Â Â Â Â Â Â Â Delete the bookmark under the cursor.
editing
i I insert mode. Insert mode at start of line
a A insert mode after cursor. insert at end of line
ctrl+w    insert mode delete previous word.
J gJ merge next line with current line.
~ switch case
r replace letter under cursor
R replace 'mode'.
y  copy
d delete command
c   cut
p  paste
MACROS
q+_Â Â Â Â Â Â Â the next key after key is where the macro is saved
record key presses
press q again
@_Â Â Â Â Â Â Â Â execute the macro stored at _
DELETE
x X delete letter under cursor
D delete(cut) to end of line
C deletes (cut) the rest of the line to insert
d delete (cut). can be combined with movement (like hjkl, web). also copies content and can be pasted with p
dd delete (cut) entire line
S delete (cut) current line, to insert mode
p P paste before/after cursor
o O inserts new line below/above and stars insert mode
oo OO insert without entering insert mode
<>o insert new line above and below current line and enter insert mode
. repeat previous command
u undo
ctrl R redo
HIGHLIGHTING and selecting mutliple character
v highlighting mode.
V highlight entire line/block
ctrl+v vertical edit, combine with I to insert at start of every line
o toggle jump cursor to end of selected text
v > u U change to lower/upper case
yy copy current line
/ is like ctrl f, then press 'n' and 'N' to find next/previous occurrences
:noh remove highlighting of seaerch matches
:%Â Â Â Â refer to current buffer. I can combine with 'y' or 'd'Â Â Â Â delete entire page
highlight some area > ':s/myvar/yourvar'Â Â Â Â substitue mode
MOVING BY SCREENS
Ctrl + b – move back one full screen
Ctrl + f – move forward one full screen
Ctrl + d – move forward 1/2 a screen
Ctrl + u – move back 1/2 a screen
Ctrl + e – move screen down one line (without moving the cursor)
Ctrl + y – move screen up one line (without moving the cursor)
Ctrl + o – move backward through the jump history
Ctrl + i – move forward through the jump history
H – move to the top of the screen (H=high)
M – move to the middle of the screen (M=middle)
L – move to the bottom of the screen (L=low)
FOLDING
za ZAÂ Â Â Toggle a fold under cursor
zM Close all open folds
zm Increase the foldlevel by one
zR Decrease the foldlevel to zero—all folds will be open
zr Decrease the foldlevel by one
zo Open a fold at the cursor
zO Open all folds at the cursor
zc Close a fold under cursor
zf#j Create a fold from the cursor down # lines
zf/ String creates a fold from the cursor to string
zj Move the cursor to the next fold
zk Move the cursor to the previous fold
zd Delete the fold at the cursor
zE Delete all folds
[z Move to start of open fold
]z Move to end of open fold
INDENTATION
<< or >> indent one shift
<>f, f4 format file
highlight and press +
SEARCH AND REPLACE
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations
<>s           replace all instaces of current word under cursor
TABS
<>tx    close current tab
gt < >tn move to the next tab
gTÂ < >tp move to the previous tab
#gt
move to tab number #
:tabo[nly] - close all tabs except for the current one
:tabdo command - run the command on all tabs (e.g. :tabdo q - closes all opened tabs)
< >to or :tabnew {page.words.file} open a file in a new tab
WORKING WITH MULTIPLE FILES
Ctrl + T open current window in a tab
Ctrl + h - move cursor to the left window (vertical split)
Ctrl + l - move cursor to the right window (vertical split)
Ctrl + j - move cursor to the window below (horizontal split)
Ctrl + k - move cursor to the window above (horizontal split)
ctrl arrow keys resize the windows
:e[dit] file - edit a file in a new buffer
:bn[ext] - go to the next buffer
:bp[revious] - go to the previous buffer
:bd[elete] - delete a buffer (close a file)
:b[uffer] file - go to a buffer by file
:ls or :buffers - list all open buffers
:sp[lit] file - open a file in a new buffer and split window
:vs[plit] file - open a file in a new buffer and vertically split window
:tab ba[ll] - edit all buffers as tabs
Ctrl + wT - move the current split window into its own tab
Ctrl + wt - duplicate current buffer in new tab
Ctrl + ws - split window
Ctrl + wv - split window vertically
Ctrl + ww - switch windows
Ctrl + wq - quit a window
ctrl + wc    - close windows
ctrl + c close window (global, works for all/ most plugins)
Ctrl + wx - exchange current window with next one
Ctrl + w= - make all windows equal height & width
Ctrl + wH - make current window full height at far left (leftmost vertical window)
Ctrl + wL - make current window full height at far right (rightmost vertical window)
Ctrl + wJ - make current window full width at the very bottom (bottommost horizontal window)
Ctrl + wK - make current window full width at the very top (topmost horizontal window)
Ctrl + wo - make current window the only open window
SURROUND
highlight + S + whatever     surround highlighted with whatever and surround it with whatever
ys = surround
ds = delete surround
cs = chage surround
yss = surround entire line
ysiw      surround inside word
ds(Â Â Â Â delete surrounding () dst delete surrounding tags
cs'(Â Â Â Â change surrounding '' for ()
cst"Â Â Â Â change TAGS for ""
cs]{Â Â Â Â when changing for enclosing using open and closing adds or doesnt' add indentation/spaces
T IS FOR TAGS
AUTO PAIRS
"" some text     if I press alt+e in this case the " will travel thro every word
alt+p    toggle plugin itself
- [x]
CUSTOM
<>u             undo tree
<leader>nh", ":nohl<CR>"
vJ / KÂ Â Â Â Â .move line up and down. first enter visual mode.
<>m toggle treesitter join: joins blocks of code like arrays, and maps. collapse, expand.
Harpoon
harpoon is a plugin that marks files (4) for quick access
<>ss open ui
<>sa mark file
<>su,i,o,p go to file 1,2,3,4
Telescope
< >ff  fuzy find files by name
<>fg   git files finder
<>fs    grep all files
<>ft     open telescope
<>fp search past yanks on clipboard
<>fq search recorded macros
? fuzzy find current buffer
ctrl-u/d  scroll up/down preview
ctrl j/k  selec next/prev file
n, j/k delect next/prev file
tab/S-tab select/deselect file
ctrl s    open vertical split
alt s    open horizontal spli
ctrl t      open tab
ctrl c      close
:Telescope git_Â Â view git related things like branches
<>fb open buffers
DEBUGGING
f5, <>du    UI toggles
<>b, Â Â Â toggle breakpoint
<>B, Â Â Â set conditional breakpoint
f9, <>dc    launch debugger / continue
f10, <>dj   step out
f11, <>dl   step over
f12, <>dk    step in
f6Â Â Â Â Â ui eval()
f7, <>dh    ui evaluate expression. trigger again to go to window
f8, <>dr    repl toggle
<>da attach debugger
<>ds variable scopes window
<>db breakpoints window
<>dw watches window
<>dt stacks window
on DAP-ui on the breakpoints window I can press o
to go the breakpoint or t
to toggle it on and off.
I can also insert what variables to watch with i
on the watch window and repl
Testing
<>tm, "Run" },
<>tM, "Run with DAP" },
<>tf , "Run File" },
<>tF, "Run File with DAP" },
<>ts, "Summary" },
<>tw "Watch" },
GIT
< >gs open lazy git within floaterm
fugitive
:G any git command
< >g      open fugitive. Git
'-' and s    stages a file change
=  or dv   shows diffs. dq to quit
u    unstage file
XÂ Â Â Â Â delete changes
cc commit pane
zzz stash changes
]] move between changes
]c     jump to next tongue(conflict) ?
[c     jump to prev change
o OÂ Â Â see changes in a split or new tab
coo checkout commit
in a file with merge conflicts I can :Gvdiffsplit!.
left: current change, mid: conflict, right branch I want to merge with
gf, d2o  choose from left window
gj, d3o  choose from right window
if doesn't work use difget
:help fugitive
:Gvdiffsplit (branch-name)   see changes of curr file compared to last commit
:G difftool -y     see changes of all files open in different tabs
:Gedit main:file2.js      see the contents of a file
Gread main:file1.js      == git reset   replace current buffer
:Gwrite    =git add <filename> changes the entire file and stages it for commit
:git revert is for reverting commits, reset resets changes
:G restore   restore file changes to last commit
git signs
git info in buffers
<>g with which key
<>gb checkout branch
<>gc checkout commit
<>gd Git Diff
<>gj next hunk
<>gk prev hunk
<>gl blame
... many more
Git Worktrees
<>gn create work tree
<>gt       open worktree. telescope
(believe don't have to do this with the create worktree command)
couldn't get the plugin to work but I could still use git commands to do this.
git clone --bare URL git-worktree.nvim
git worktree add <branch_name>
git signs
td   toggle to see inline git change
tb   toggle git blame
more bindings for staging hunks (only committing certain parts of a file instead of the entire thing)
![image.png](/img/user/00-09 System/09 resources/image-3.png)
HARPOON
< >sa             add file to harpoon
< >u,i,o,p          go to files 1,2,3,4
<>ss            open marked files
TOGGLETERM
alt t  toggle floating terminal
Troubles
<>xq open trouble, window showing all problems on the file/ project?
<>xa workspace troubles
<>x   document diagnostics
<>xx trouble toggle
MASON
:Mason package manager for LSP, DAP (debugger protocols), linters and formatters
navigate to package and:
u updates
X deletes
i installs
:LspInstall
lsp autocomplete
normal mode
(normal) K, (insert) C-h   hover info, documentation
gd   go to definition
gDÂ Â go to declaration
gr  go to references
gi   go to implementations
go jumps to definition of the type of symbol under cursor
gs buffer symbols
gS workspace symbols
<>r, f2Â rename/replace all ocurrences
<>a, f4 code actions
gl line diagnostics
[d ,]d prev/next diagnostic
<>ws view workspace symbol (queries and finds all instances of a symbol, i.e classes functions, etc...)
<>wa add workspace folder
<>wr remove workspace folder
in insert mode
C-h show signature.
ctrl e    toggle cmp
ctrl n trigger autocomplete suggestions
tab      show suggestions even inside words. next/prev suggestion
ctrl < > starts completion
ctrl p/n previous and next option
ctrl u/f      scroll up and down in items documentation.
ctrl j/k    go to next/prev placeholder in snippet
ctrl y confirm
java lsp
normal mode
:Jdt_ commands
:JdtSetRuntime change java runtime, must refresh dap settings after.
<>ji organize_imports
<>jt test class
<>jn test nearest_method
(v,n)<>je extract_variables
<>je extract_variable
<>jea extract_variable and replace all ocurrences
<>jc extract_constant
<>jm extract_method
Refactoring
<>re :Refactor extract ")
<>rf :Refactor extract_to_file ")
<>rv :Refactor extract_var ")
<>ri :Refactor inline_var")
<>rI :Refactor inline_func")
<>rb :Refactor extract_block")
<>rbf :Refactor extract_block_to_file")
COMMENTING
gcc toggle comment current line
gc toggle comment highlited text
gb toggle comment blockwise
gc navigation toggle commenting navigation input
neotree FILE TREE
? help?
< >e open file tree
<>eb open buffer list
<>eg open git status files
<, > switch source
s,
bd     delete buffer
a new file
AÂ Â Â Â Â Â Â Â new dir
d delete file
PÂ Â Â Â Â Â Â preview
Y copy file path options
y copy file
x cut file
p paste from clipboard
sessions
neovim-sesssion-manager plugin. saves session on a per folder basis
:SessionManager
GITHUB COPILOT
- Alt+y              accept
- alt+ n             next suggestion
- alt+p             prev suggestion
- alt+ e            dismiss suggestion
- alt+a             copilot panel. 10 suggestions
- alt+l accept line