How do I execute buffer text as a macro dynamically?
:let @a=getline('.')<CR>@a
How it works Instead of recording keystrokes interactively, you can write a sequence of Vim commands as plain text in your buffer and then execute that text as
:let @a=getline('.')<CR>@a
How it works Instead of recording keystrokes interactively, you can write a sequence of Vim commands as plain text in your buffer and then execute that text as
:jumps
How it works Vim keeps a jump list that records your cursor position every time you make a jump.
:if condition | execute 'normal cmd' | endif
How it works Vim macros can include Ex commands with conditional logic.
:%s/foo/bar/g | %s/baz/qux/g | w
The (bar) character in Vim's command line acts as a command separator, allowing you to chain multiple ex commands together on a single line.
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
:iabbrev teh the
Vim's abbreviation feature lets you define automatic text replacements that trigger as you type.
:'<,'>copy'>
How it works The :copy command (or its abbreviation :t) duplicates lines to a specified destination.
:nnoremap <buffer> <leader>r :!python %<CR>
How it works By adding to a mapping command, the mapping only applies to the current buffer.
:set winfixwidth winfixheight
How it works When you open new split windows in Vim, the existing windows automatically resize to make room.
:!ls -la
Vim lets you execute any shell command directly from within the editor using the :! (bang) command.
qa:s/old/new/g<CR>jq
How it works You can combine Ex commands like :s (substitute) with macro recording to create powerful repeatable find-and-replace operations that go beyond what
do (diffget) / dp (diffput)
How it works When you open two files in diff mode (using vim -d file1 file2 or :windo diffthis), Vim highlights the differences between them.
:%bd | e#
How it works Vim does not have a built-in single command to close all buffers except the current one, but you can achieve this with a two-part command: :%bd e#.
:tab sb N
How it works The :tab sb N command opens buffer number N in a brand new tab page.
autoload/myplugin.vim
The autoload mechanism in Vim lets you write plugins whose functions are only loaded into memory when they are first called.
:DB sqlite:mydb.sqlite SELECT * FROM users
vim-dadbod by Tim Pope is a plugin that lets you interact with databases directly from Vim.
:b N
How it works Every buffer in Vim is assigned a unique number when it is opened.
:'<,'>move'>+1 or :'<,'>move'<-2
How it works Vim's :move command lets you relocate lines to a different position.
:bdelete
How it works The :bdelete command (often abbreviated :bd) removes the current buffer from Vim's buffer list and closes it.
:cabbrev
:cabbrev (command-line abbreviation) lets you define short aliases for longer Ex commands.