Useful vim commands and shortcuts
Useful vim Commands
Search and Replace
-
:s/search/replace/for current line and first occurrence. -
:s/search/replace/gfor current line and all occurrence. -
:%s/search/replace/gfor all occurance. -
:3,10s/search/replace/gfor a range of line 3 to 10 -
:.,+4s/search/replace/gfrom current line to next 4 lines -
:.,$s/search/replace/from current line to end of the file. - end
gcto confirm each substitution. - end
gito ignore case sensitivity.
Comment multiple lines
Fold lines
:set foldmethod=indent folds all the lines by indentation
Neo Vim for C++
- Install Mason.nvim
- Add
M.plugins = "custom.plugins"to chadrc.lua under ~/.config/nvim/lua/custom - Create a new file here using a key in file tree plugins.lua, edit the following
local plugins = { { "williamboman/mason.nvim", opts = { ensure_installed = { "clangd" } } } } return plugins - Close and reopen nvim and run `MasonInstallAll
- Now add custom lspconfig to mason and final result would look like ```bash local plugins = { { “neovim/nvim-lspconfig”, config = function () require “plugins.configs.lspconfig” require “custom.configs.lspconfig” end }, { “williamboman/mason.nvim”, opts = { ensure_installed = { “clangd” } } } } return plugins
- create the lspconfig.lua inside custom/configs - The files looks as given below ```bash local base = require("plugins.configs.lspconfig") local on_attach = base.on_attach local capabilities = base.capabilities local lspconfig = require("lspconfig") lspconfig.clangd.setup{ on_attach = function (client,bufnr) client.server_capabilities.signatureHelpProvider=false on_attach(client,bufnr) end, capabilities=capabilities, }- exit and enter and do
TSInstall cpp
Final result
- custom/configs/null-ls.lua ```bash local null_ls = require(“null_ls”)
local opts = { sources = { null_ls.builtins.formatting.clang_format, } }
return opts ```
- Add
Enjoy Reading This Article?
Here are some more articles you might like to read next: