Skip to content

Instantly share code, notes, and snippets.

@andruhon
Last active April 18, 2024 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andruhon/d6984b6cf9506739ecc72034bbc4c119 to your computer and use it in GitHub Desktop.
Save andruhon/d6984b6cf9506739ecc72034bbc4c119 to your computer and use it in GitHub Desktop.

All commands below are in normal mode unless specified otherwise. Hit esc on keyboard to enter normal mode.

Search and Replace

/ search forward, ? search backward, for example
?text search backward for the word "text", /text\c case-insensitive search
:let @/ = "" clear search context;

:%s/text/replacement/gic interactive search. y - replace, n - skip, a - all, q - quit, l - replace one and quit

gn search

Search for text with /text, hit enter, then type cgn to change current selection and then select next occurrence of the text. Type replacement text and then hit . to continue to the next occurrence. You may hit n before repeating action to see which occurrence you are on. Hit n once again to skip occurrence. Same trick can be done with dgn to delete the text.

Search settings

:set ignorecase :set hlsearch highlight search; :set incsearch incremental (search as you type)
:set ic hls is enable all three at once, :set noic nohls nois disable all three
:noh clear search highlight until the next search

Navigation

ctrl + ] go to; :vsplit or :split to split window; ctrl + w and then navigation arrows or hjkl to switch between panels; ctrl + w + q or :close to close panel; % go to matching bracket (){}[], * go to next occurrence of the word under the cursor. w go to the next word, e go to the end of current word.
ctrl + o go to previous location, ctrl + i go to next location.

Registers

" then register code then command. "ay yank to register a, "ap paste from register a. * and + registers are special registers that are used for system clipboard. "+y yank to system clipboard, "+p paste from system clipboard.

Wayland has an issue with * and + vim registers. There's a plugin to fix it and probably vim can be rebuilt to address this. But so far the easy way to workaround is to use temp file to copy and paste:
Select lines with V and then hit :, :'<,'> will appear, type further to make :'<,'>w! /tmp/vimcp to copy. Use :r /tmp/vimcp to paste from this file. This approach will write whole lines into the file.
To write only the selection do :call writefile(getreg('z', 1, 1), "/tmp/vimcp).

Plugins

terryma/vim-multiple-cursors works fine in normal vim, but ideavim only understands alt + n, alt + x instead of ctrl + n and ctrl + x (skip).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment