Skip to content

Commit

Permalink
ええやんクリップボード使いますわ
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuote committed Mar 21, 2024
1 parent 064e950 commit ff56e7a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 25 deletions.
55 changes: 30 additions & 25 deletions conf/rc/mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,6 @@ nnoremap <Space>. <Cmd>edit $VIMDIR/vimrc<CR>
nnoremap <Space>d <Cmd>DduSelectorCall filer<CR>
nnoremap Q <Cmd>confirm qa<CR>
" shellのcd用ヘルパー
""/tmp/vim_shell_cdにカレントファイルのディレクトリパスを書き込んでVimを落とす
nnoremap <C-q> <Cmd>call writefile([expand('%:p:h')], '/tmp/vim_shell_cd')<CR><Cmd>confirm qa<CR>
" sugoi undo
nnoremap U <C-r>
" tab
nnoremap H <Cmd>tabprevious<CR>
nnoremap L <Cmd>tabnext<CR>
nnoremap tt <Cmd>tab split<CR>
" window movement
nnoremap <Space>w <C-w>
nnoremap sh <C-w>h
nnoremap sj <C-w>j
nnoremap sk <C-w>k
nnoremap sl <C-w>l
" こまめなセーブは忘れずに
nnoremap <Space>s <Cmd>update<CR>
" 開く前の方向に戻っていく
nnoremap <expr> tq printf('<Cmd>tabclose <Bar> tabnext %d<CR>', max([1, tabpagenr() - 1]))
" based from https://github.com/habamax/.vim/blob/5ae879ffa91aa090efedc9f43b89c78cf748fb01/plugin/mappings.vim?plain=1#L152
" HLとPageDown/PageUpを共用する
function s:pagedown() abort
Expand All @@ -54,3 +29,33 @@ endfunction

nnoremap <Space>j <Cmd>call <SID>pagedown()<CR>
nnoremap <Space>k <Cmd>call <SID>pageup()<CR>
" shellのcd用ヘルパー
""/tmp/vim_shell_cdにカレントファイルのディレクトリパスを書き込んでVimを落とす
nnoremap <C-q> <Cmd>call writefile([expand('%:p:h')], '/tmp/vim_shell_cd')<CR><Cmd>confirm qa<CR>
" sugoi undo
nnoremap U <C-r>
" tab
nnoremap H <Cmd>tabprevious<CR>
nnoremap L <Cmd>tabnext<CR>
nnoremap tt <Cmd>tab split<CR>
" window movement
nnoremap <Space>w <C-w>
nnoremap sh <C-w>h
nnoremap sj <C-w>j
nnoremap sk <C-w>k
nnoremap sl <C-w>l
" yank operation
"" L<denops-vimrc-yank>
nnoremap <CR> <Cmd>call vimrc#denops#request('yank', 'yank', [getline(1, '$')])<CR>
" こまめなセーブは忘れずに
nnoremap <Space>s <Cmd>update<CR>
" 開く前の方向に戻っていく
nnoremap <expr> tq printf('<Cmd>tabclose <Bar> tabnext %d<CR>', max([1, tabpagenr() - 1]))
5 changes: 5 additions & 0 deletions conf/rc/mode/ov/map.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
" fake textobj-entire
onoremap ae <Cmd>normal! gg0vG$<CR>
xnoremap ae gg0oG$
" yank operation
"" L<denops-vimrc-yank>
xnoremap <CR> <Cmd>call vimrc#denops#request('yank', 'yank', [getregion(getpos('v'), getpos('.'), #{type: mode()})])<CR>:<C-u><Esc>
1 change: 1 addition & 0 deletions denops/@deps/deno_std.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as TOML from "/data/vim/repos/github.com/denoland/deno_std/toml/mod.ts";
export * as stdpath from "/data/vim/repos/github.com/denoland/deno_std/path/mod.ts";
export * from "/data/vim/repos/github.com/denoland/deno_std/encoding/base64.ts";
56 changes: 56 additions & 0 deletions denops/@vimrc/yank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { encodeBase64 } from "../@deps/deno_std.ts";
import { Denops } from "../@deps/denops_std.ts";

async function yankDetachWayland(text: string) {
const wlCopy = new Deno.Command("wl-copy", {
stdin: "piped",
stdout: "null",
stderr: "null",
}).spawn();
const w = wlCopy.stdin.getWriter();
w.write(new TextEncoder().encode(text))
.finally(() => w.close());
await wlCopy.status;
// detach tmux for VIME use
await new Deno.Command("tmux", {
args: ["detach-client"],
}).output();
}

async function oscyank(denops: Denops, text: string) {
const content = `\x1b]52;c;${encodeBase64(text)}\x1b\\`;
if (denops.meta.host == "vim") {
await denops.call("echoraw", content);
} else {
await denops.call("luaeval", "vim.api.nvim_chan_send(2, _A)", content);
}
}

function union(text: unknown) {
if (Array.isArray(text)) {
return text.join("\n");
}
return String(text);
}

// X<denops-vimrc-yank>
export async function main(denops: Denops) {
const isWayland = Deno.env.get("WAYLAND_DISPLAY") != "" &&
Boolean(await denops.call("executable", "wl-copy"));
denops.dispatcher = {
async yank(text: unknown) {
const trimText = union(text).trimEnd();
if (isWayland) {
await yankDetachWayland(trimText);
} else {
await oscyank(denops, trimText);
}
},
};
// await denops.cmd(
// `nnoremap <CR> <Cmd>call denops#request('${denops.name}', 'yank', [getline(1, '$')->join("\\n")])<CR>`,
// );
// await denops.cmd(
// `xnoremap <CR> y<Cmd>call denops#request('${denops.name}', 'yank', [getreg(v:register)])<CR>`,
// );
}

0 comments on commit ff56e7a

Please sign in to comment.