-
Notifications
You must be signed in to change notification settings - Fork 0
(neo)vim
:vim.pretty_print(<>)
open both files side-by-side (C-w v)
:windo diffthis
-
:Gitto open the git status. - on the conflicted file,
dvto open 3-way vertical diff. -
]cto jump through the changes - on a conflict
d2oto pick the left,d3oto pick th right. -
Ctrl-w oto close all other windows
:set nowrap
When live_greping, <C-space> to fuzzy refine the results list.
This allows filtering down to specific files without figuring out how to pass --glob to ripgrep.
To find what is changing a setting, run :verbose set <setting>.
This will show what last set the value, for example:
:verbose set conceallevel
conceallevel=2
Last set from /usr/share/nvim/runtime/ftplugin/help.vim line 18
:%! jq .
If the selection has surrounding content on the same line this seems to not work, in that case copy the content to a new line.
:'<,'>w !jq '.'
When running a command (: or /), you normally can't use regular keymaps.
To switch to a edit mode where you can, press C-f.
- Search as normal (
/,n) - when on the instance you want to replace, 'cgn' to change the search result in visual mode.
- 'n' to go to the next hit
- '.' to repeat the edit
:%s/pattern/replace/g
When searching, start the search with \v to use "very magic" mode.
https://neovim.io/doc/user/pattern.html#%2Fmagic
use {-} instead of * when using \v
- Select text to surround
-
q1start recording macro1 c<prefix><C-R>"<suffix><Esc>-
qstop recording
For example, to wrap selection in $``$ when working on LaTex in github markdown:
q1c$`<C-R>"`$<Esc>q
This tends to work a little more stable than the macro version.
vim.keymap.set('v', '4', 'c$`<C-r>"`$<Esc>', { desc = 'Wrap selection with $``$' })
qa"xywciw<C-R>=@x*0.8<CR><ESC>q
-
qa(optional) start recording macroa -
"xywyank word into bufferx -
ciwchange inner word -
<C-R>=Insert contents of register =, but the expression register is special in that you'll get prompted for an expression to insert. -
@x*0.8<CR>multiply bufferxby 0.8 -
<ESC>exit insert mode -
q(optional) end macro
https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines
:'<,'>norm! @a Visual select lines, then :norm! @a to run macro in register a on all selected lines
:lua =vim.lsp.get_active_clients()[1].server_capabilities
To make the clangd LSP work I need to have the compile_commands.json.
In CMake this can be done as cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1.
If the build dir is not $SRC or $SRC/build, symlink the output file to $SRC.
Neovim allows executing files in the cwd named .nvim.lua on startup.
This will run after normal init.
vim.o.exrc = true
Disable all-targets for rust-analyzer, for example when working on embedded projects.
local lspconfig = require('lspconfig')
local capabilities = lspconfig.rust_analyzer.manager.config.capabilities
-- Could be used to change existing settings instead of redefining them all like we do here
-- local existing_settings = lspconfig.rust_analyzer.manager.config.settings
local on_attach = lspconfig.rust_analyzer.manager.config.on_attach
-- Overrides any existing setup of rust-analyzer
lspconfig.rust_analyzer.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
["rust-analyzer"] = {
cargo = {
allTargets = false,
}
},
}
}Configure neotest-jest to match on a specific pattern
-- Configure neotest-jest to match on test.ts(x)
require("neotest").setup({
adapters = {
require('neotest-jest')({
isTestFile = function(file_path)
if not file_path then
return false
end
-- The default only matches on files with extension, not "test.ts"
if file_path:match("test.[jt]sx?$") then
return true
end
if require("neotest-jest.jest-util").defaultIsTestFile(file_path) then
return true
end
return false
end
}),
},
})-
:set listenable list mode -
:set listcharsto change what to show, see:h listchars
nvim-dap loads configurations from ./.vscode/launch.json when invoked with dap.continue().
Format of this file and more info: :help dap-configuration
{
"version": "0.2.0",
"configurations": [
{
"type": "python",
"name": "foo",
"request": "launch",
"args": [
"--help"
],
"justMyCode": false,
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"program": "foo.py"
}
]
}