Skip to content

Instantly share code, notes, and snippets.

@njgheorghita
Last active July 30, 2024 19:13
Show Gist options
  • Save njgheorghita/1ff6019974b46c00b9fd129b3fed01fb to your computer and use it in GitHub Desktop.
Save njgheorghita/1ff6019974b46c00b9fd129b3fed01fb to your computer and use it in GitHub Desktop.
vim shortcuts

https://rsdlt.github.io/posts/rust-nvim-ide-guide-walkthrough-development-debug/

custom mapping to toggle showcursorline and showcursorcolumn

  • ctrl + u

show git diff between current file state and saved state

  • :w !diff % -

repeat your last edit

  • .

search for all words under cursor

  • *

skip to the next occurrence

  • n

refresh current file

  • :e / :edit

count number of occurrences in file

  • :%s/pattern//ng

folding

  • zf create fold in visual mode
  • zo open fold

open previous file

  • :b#

move to a specific character on line

  • f <char> forwards to char
  • F <char> backwards to char

dealing with tabs/space

I think you just need to make sure you have your expandtab option set:

:set expandtab You could also make a json.vim file in your ftplugin directory that looks something like this:

set shiftwidth=2
set softtabstop=2
set tabstop=2
set expandtab

You might also need to select the offending whitespace and do:

:retab

repaint vim

  • ctrl - l

nerdtree commenting

  • 1\cc - - - to comment 1 line
  • 10\cc - - - to comment 10 lines
  • 10\cu - - - to uncomment 10 lines

# search

  • :noh - - - to remove highlighted words

:Explore - - - to rename a file

Change tab size

  • :set tabstop=4
  • :set shiftwidth=4 (this is the one i usually use)
  • :set expandtab

Create folder/file with NERDTree

  • when in nerdtree window press m then a to add (there are other commands listed)
  • folders end with a /

Delete till next character

  • d t char

Delete character before

  • X

Replace All: Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.

  • :%s/foo/bar/g

For specific lines:

  • :6,10s/foo/bar/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment