25
submitted 3 months ago* (last edited 2 months ago) by sxwpb@lemmy.world to c/neovim@programming.dev

Hello, I wanted to share a small keymap I made. It lets you inspect unsaved changes in the current file. It uses diff mode, in a vertical split.

To close the diff mode, just press q in the scratch buffer.

vim.keymap.set(
	'n',
	'<M-C-D>',
	function()
		local tmpft = vim.bo.filetype
		vim.cmd.vnew()
		vim.bo.filetype = tmpft
		vim.bo.buftype = 'nofile'
		vim.keymap.set(
			'n',
			'q',
			'<cmd>bw<cr>',
			{ noremap = true, silent = true, buffer = true }
		)
		vim.cmd('silent r#|0d_')
		vim.bo.modifiable = false
		vim.cmd('diffthis|wincmd p|diffthis')
	end,
	{ noremap = true }
)

edit: I discovered that this functionality is actually documented in the help pages (:h :DiffOrig). It’s basically the same action but bound to a command

you are viewing a single comment's thread
view the rest of the comments
[-] GreyCat@lemmy.world 2 points 2 months ago

Yeah havn't checked how to use undo-tree yet, gotta do that at some point, seems really useful.

But I have put this post's keymap in my config and first impressions are pretty good. Now I just have to remember to use it haha

this post was submitted on 18 Aug 2024
25 points (100.0% liked)

Neovim

2175 readers
6 users here now

founded 1 year ago
MODERATORS