mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
4 Commits
68a349c145
...
8b7fe75497
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b7fe75497 | ||
|
|
7645751dc1 | ||
|
|
8880268140 | ||
|
|
994b0d4c84 |
@ -191,7 +191,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu
|
|||||||
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
|
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
|
||||||
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
||||||
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
|
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
|
||||||
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
|
|
||||||
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
|
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
|
||||||
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
||||||
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
||||||
@ -206,6 +205,7 @@ In addition to commands provided by various plugins, I have also created some cu
|
|||||||
| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` |
|
| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` |
|
||||||
| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` |
|
| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` |
|
||||||
| `JSONFormat` | format a JSON file | `JSONFormat` |
|
| `JSONFormat` | format a JSON file | `JSONFormat` |
|
||||||
|
| `CopyPath` | copy current file path to clipboard | `CopyPath relative` |
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ For a list of terminals that support true colors, see [here](https://github.com/
|
|||||||
|
|
||||||
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
|
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
|
||||||
|
|
||||||
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
|
If you ssh to Linux server on Windows, or use [WSL2 (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/about) I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
|
||||||
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
|
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
|
||||||
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
|
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
|
||||||
|
|
||||||
|
|||||||
58
plugin/command.lua
Normal file
58
plugin/command.lua
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
-- Copy file path to clipboard
|
||||||
|
vim.api.nvim_create_user_command("CopyPath", function(context)
|
||||||
|
local full_path = vim.fn.glob("%:p")
|
||||||
|
|
||||||
|
local file_path = nil
|
||||||
|
if context["args"] == "nameonly" then
|
||||||
|
file_path = vim.fn.fnamemodify(full_path, ":t")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get the file path relative to project root
|
||||||
|
if context["args"] == "relative" then
|
||||||
|
local project_marker = { ".git", "pyproject.toml" }
|
||||||
|
local project_root = vim.fs.root(0, project_marker)
|
||||||
|
if project_root == nil then
|
||||||
|
vim.print("can not find project root")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
file_path = string.gsub(full_path, project_root, "<project-root>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if context["args"] == "absolute" then
|
||||||
|
file_path = full_path
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.fn.setreg("+", file_path)
|
||||||
|
vim.print("Filepath copied to clipboard!")
|
||||||
|
end, {
|
||||||
|
bang = false,
|
||||||
|
nargs = 1,
|
||||||
|
force = true,
|
||||||
|
desc = "Copy current file path to clipboard",
|
||||||
|
complete = function()
|
||||||
|
return { "nameonly", "relative", "absolute" }
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- JSON format part of or the whole file
|
||||||
|
vim.api.nvim_create_user_command("JSONFormat", function(context)
|
||||||
|
local range = context["range"]
|
||||||
|
local line1 = context["line1"]
|
||||||
|
local line2 = context["line2"]
|
||||||
|
|
||||||
|
if range == 0 then
|
||||||
|
-- the command is invoked without range, then we assume whole buffer
|
||||||
|
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
|
||||||
|
vim.fn.execute(cmd_str)
|
||||||
|
elseif range == 2 then
|
||||||
|
-- the command is invoked with some range
|
||||||
|
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
|
||||||
|
vim.fn.execute(cmd_str)
|
||||||
|
else
|
||||||
|
vim.api.nvim_err_write(string.format("unsupported range: %s", range))
|
||||||
|
end
|
||||||
|
end, {
|
||||||
|
desc = "Format JSON string",
|
||||||
|
range = "%",
|
||||||
|
})
|
||||||
@ -45,6 +45,3 @@ function! s:md_to_pdf() abort
|
|||||||
echoerr "Error running command"
|
echoerr "Error running command"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" json format
|
|
||||||
command! -range JSONFormat <line1>,<line2>!python -m json.tool
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user