Skip to content

Instantly share code, notes, and snippets.

@NegatioN
Last active August 4, 2023 08:24
Show Gist options
  • Save NegatioN/b7763f9b6ca3a0432ce40c36af521bc7 to your computer and use it in GitHub Desktop.
Save NegatioN/b7763f9b6ca3a0432ce40c36af521bc7 to your computer and use it in GitHub Desktop.
Vim stuff
\%23c Matches in a specific column. (23), example :%s/\%1c/#/ (insert # on first column of all rows)
:% (all rows), :. (this row), :$ (last row), :.,$ (this->last row), :5,$ (5th->last row)
s, substitute. :%s/a/b/g, change all a->b on all rows.
u, undo
p, paste
m+a, set mark a [works for a-z]
'+a, go to mark a [works for a-z]
<<, de-indent row
>>, indent row
J, join rows
ctrl+d, down half a page
ctrl+u, up half a page
d+$, delete+copy until end of line
{, go to previous paragraph (empty newline)
}, go to next paragraph
:1,5sort, sorts lines from 1,5
di(, delete everything between ( and )
vap, visually select paragraph
*, turns word under cursor to searchterm, and allows for moving to all exact duplicates.
g*, search for word under cursor (without word boundry)
%, move to matching ( [ { } ] )
:marks, brings up list of all active marks.
'', go to previous position. Useful after jumping around
ctrl+v, block-wise selection. Can select columns
g+v, re-do block selection
shift+i, Insert at beginning of line
3fX, go to third occurence of letter "X"
:% norm! @a, run macro "a" on all lines
s/expr\(.*\)/\1/g, pull out a regex from a line, and replace the line with the content
Windows:
:b N or :buffer N, goes to buffer number N. :b# can be used for "previously used buffer"
:ls, list all buffers
:bd N..., delete buffer N (can take several Ns)
ctrl+W [MoveKey] (hjkl), move between windows
ctrl+W [Shift+MoveKey] (HJKL), move windows in a direction
ctrl+W c, close selected window
ctrl+W o, close all except selected window
ctrl+W v, split vertical
:tabnew | r ![COMMAND], pipes a terminal command into a new tab
Links:
https://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118
http://derekwyatt.org/vim/tutorials/index.html
http://vimdoc.sourceforge.net/htmldoc/pattern.html
https://github.com/mhinz/vim-galore
https://www.guckes.net/vim/setup.html
https://begriffs.com/posts/2019-07-19-history-use-vim.html
http://vimcasts.org/episodes/page/7/
https://www.barbarianmeetscoding.com/boost-your-coding-fu-with-vscode-and-vim/moving-blazingly-fast-with-the-core-vim-motions/
Anecdotes:
The name grep seems to originate from g/re/p, which selects a (re)gex in vi.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment