Skip to content

Instantly share code, notes, and snippets.

@Starraider
Last active April 3, 2024 19:13
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Starraider/1dc22203c83804649b729e0ad830a4e9 to your computer and use it in GitHub Desktop.
Save Starraider/1dc22203c83804649b729e0ad830a4e9 to your computer and use it in GitHub Desktop.
Tips & Tricks for Vim/NeoVim

Tips & Tricks for Vim/NeoVim

Keyboard Shortcuts

Be aware the following shortcuts are only working, if you have the plugins installed mentioned below.

In Command Mode:

:w              Save file
:w filename     Save file under new filename
:q              Quit file
:<tab>          Show commands
i               Switch to INSERT mode
R               Switch to REPLACE mode to overwrite text
v               Switch to VISUAL mode
V               Switch to VISUAL LINE mode
<ctrl>v         Switch to VISUAL BLOCK mode
o               Insert a new line below the current line and go to INSERT mode
O               Insert a new line above the current line and go to INSERT mode
x               Delete character under the cursor
X               Delete character left of the cursor
dd              Delete current line
dw              Delete current word
D               Delete to the end of the line
<esc>           Leave current mode
/               Search for text
$               Go to the end of the line
gcc             Comment out a line
<ctrl>r         Redo last change
<ctrl>g         Show file info
<space>e        Toggle FileTree
<space>n        Toggle line numbers
<space>w        Toggle line wrap  
<space>c        Toggle colorscheme dark/light
<space>t        Open terminal (close with esc)
:PlugInstall    Install plugins which are added to the ~/.config/nvim/init.vim

** Surround **

Change Surround: cs(alt)(neu)
cs"'            Changes " to ' surrounding
cs"<p>          Changes " to <p></p>
cst"            Changes *t*ags like <p></p> to "

Delet Surround: ds(alt)
ds"             Deletes " surrounding
dst             Deletes *t*ag linke <p></p>

Text search:

/               Search forward
?               Search backward
n               Repeat last search
s{char}{char}   Sneak search forward
s<enter>        Repeat last sneak search
f{char}         Jump to the next {char} right
fffff           Jump to next found

Search pattern for / and ?:
^blabla         Matches start of line
blabla$         Matches end of line
bl.bla          Placeholder for 1 character

Move Cursor:

0               To first character in the line
$               To end of line
G               To end of file
gg              To start of file
w               Word forward
b               Word backwards
)               Sentence forward
(               Sentence backwards
}               Paragraph forward
{               Paragraph backwards

Sessions:

:SSave          Save a session
:SLoad          Load a session
:SDelete        Delete a session
:SClose         Close current session

Split window:

<ctrl><w>+s or :split   Split window horizontal
:vsplit                 Split window vertical
<ctrl><w>+n             Split window with new file
<ctrl><w>+q             Close current window
<ctrl><w>+w             Jump to upper/lower window
:sf filename            Open file in new window
:sf <tab>               Search file 

File Search:

<ctrl>p         Open fzf fuzzy search
<enter>         Open found file in current window
<ctrl>t         Open found file in tab split
<ctrl>s         Open found file in split  
<ctrl>v         Open found file in vsplit      

In INSERT mode

<esc>           Leave INSERT mode
<del>           Delete left
<fn><del>       Delete right
<ctrl>w         Delete word before cursor
<ctrl>u         Delete left until the end of line

In .html .xhtml .php files tags will be auto closed. If you want to format them to next line press > again after closing the tag.

VimWiki

<Leader>ww      Open default wiki index file.
<Leader>wt      Open default wiki index file in a new tab.
<Leader>ws      Select and open wiki index file.
<Leader>wd      Delete wiki file you are in.
<Leader>wr      Rename wiki file you are in.
<Enter>         Follow/Create wiki link on current text/selection.
<Shift-Enter>   Split and follow/create wiki link.
<Ctrl-Enter>    Vertical split and follow/create wiki link.
<Backspace>     Go back to parent(previous) wiki link.
<Tab>           Find next wiki link.
<Shift-Tab>     Find previous wiki link.

Plugins

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