vimdiff

Lang: text
]c             " next difference
[c             " previous difference
do             " diff-obtain
dp             " diff-put
zo             " open folded text
zc             " close folded text
zr             " unfold ALL lines
zm             " fold ALL lines
:diffupdate    " re-scan the files for differences

Change window split orientation

Lang: text
ctrl-w H   " Move the current window to be at the far left
ctrl-w J   " Move the current window to be at the bottom
ctrl-w K   " Move the current window to be at the top
ctrl-w L   " Move the current window to be at the far right

Format table

Lang: vim
" using column unix command
:'<,'>!column -t -s '|' -o '|'

" collapse repeated whitespaces into single whitespace
:'<,'>s/\s\s\+/ /g

Vim color codes to terminal colors

Lang: bash
for i in {0..255}; do printf "\x1b[38;5;${i}mcolor${i}\n"; done

Highlight custom types and user functions

Base C syntax

Lang: vim
" In ~/.vim/after/syntax/c/base.vim
" Update some distributed syntax
if !exists("c_no_c99") " ISO C99
        syn keyword cConstant TRUE FALSE
endif

" Match typedefs ending with '_[te]'
syn match cType "\v<(\h\w+)_[te]>"

" Match functions and function like macros.
syn match cFunction "\v(\h\w+)\s*\("me=e-1

" Highlight syntax groups
hi def link cFunction Function

Base C++ syntax

Lang: vim
" In ~/.vim/after/syntax/cpp/base.vim
" Include all the C syntax.
runtime! syntax/c/base.vim

Project include paths

Lang: vim
" Find include files in file's directory and the directory vim started.
"
" Example:
" If vim started with
"     vim process/step.c
" Then
"     gf on log.h
" Opens files:
"     process/include/log.h
"     include/log.h
set path+=include,./include

System include paths

Lang: vim
" Don't add this when there are large system headers, it slows down vim.
set path+=/usr/include/x86_64-linux-gnu

Generate system tags

Lang: vim
" Generate tags using ctags for system includes.
set tags+=~/.local/share/tags/systags

Local vimrc

local-vimrc.vim

Lang: vim
" disable diagnostics
if has('nvim')
	source local-vimrc.lua
endif

" change some autocmds
augroup mk_c
	autocmd!
	autocmd FileType c,cpp
		\ setlocal textwidth=100
augroup end

local-vimrc.lua

Lang: lua
--- FIXME autocmd callback is not working
--- FIXME pass current number to this function
-- disable lsp clients
mk_disable_lsp = function(bufnr)
	for _, client in ipairs(vim.lsp.get_active_clients({id, name})) do
		if client.name == "clangd" and vim.lsp.buf_is_attached() then
			vim.lsp.buf_detach_client(bufnr, client.id)
			print (string.format(
			   "detached lsp client: id=%d, name=%s",
			    client.id, client.name)
			)
		end -- end if
	end
	vim.cmd('LspStop')
end

local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd

augroup('mk_lsp_aug', { clear = true })
autocmd('FileType', {
	group = 'mk_lsp_aug',
	pattern = { 'c', 'cpp' },
	buffer = bufnr,
	callback = function(buffer)
		mk_disable_lsp (buffer)
	end
})

Refer