Vim directories and path

Updated: 10 September 2022

Current Directory is where vim was started, :pwd and :cd apply. “Directory of current file” could be different to Current Directory.

When setting the path . and ,, refer to the current directory and directory of current file.

Vim quickfix

Updated: 30 June 2023

The quickfix list is global.
The location list is local to the current window.

Open a window to show the current list.
:cope[n]

Go to an older list
:col[der]

Go to a newer list
:cnew[er]

Go to the next error in the window
:cn

Go to the previous error in the window
:cp

netrw

Updated: 12 May 2023

Make word below cursor the top of tree listing
gn

Toggle dot files
gh

Rename a file
R

Delete a file
D

Create a new file
%

Open file in new horizontal split
o

Open file in new vertical split
v

Open file in new tab
t

Create a new directory
d

Refresh directory listing
Ctrl+l

Reverse sort order
r

Preview window

open
p

close
:pc

Vim folding

Updated: 18 November 2023

Toggle fold
za

Close all
zM

Open all
zR

Eliminate all folds in window (foldmethod “manual” or “marker”)
zE

For html

:set foldmethod=indent

Disable folding

:set nofoldenable

Foldtext

Remove foldtext

:set foldtext=''

Default foldtext

:set foldtext=foldtext()

Vim miscellaneous

Updated: 30 March 2024

https://vimhelp.org/


Check if you’re running vim or neovim
:echo has('nvim')

To copy/paste with PRIMARY clipboard (i.e. copy on select)
"*y ("*yy) and then "*p

To copy/paste with CLIPBOARD clipboard (i.e. Ctrl c/v)
"+y ("+yy) and then "+p

Yank full line without new line character
^y$

Line numbers
:set number
:set nonumber

Line wrap
:set wrap
:set nowrap

Open all files in current directory
nvim *

Unload buffer [N] (default: current buffer) and delete it from the buffer list.
:bd[elete][!] [N]

Open all buffers in horizontal or vertical windows
:[vertical] ball

Open all buffers in tabs
:tab ball

Repeat last command mode command
@:

Open file/link under cursor
gz

Browse recent files
:browse oldfiles

Format a json file with jq command line JSON processor
:%!jq .

Apply a command to all open windows
:windo set list

Join lines with no space character
gJ

Print current file name with full path (any number would work)
3CTRL-G

Go to 1st search result
ggn

read
Execute the command and insert its standard output below the cursor

:r! pwd