markdown-preview.nvim
markdown-preview.nvim copied to clipboard
[Feature request] Macos 分屏打开新浏览器窗口
终端全屏模式下运行 neovim,使用MarkdownPreview在当前屏幕下分屏打开浏览器窗口
不知道怎么搞
@fishioon 用窗口管理工具吧 https://github.com/koekeishiya/yabai ,感觉这个插件应该不好做分屏。 然后这么设置。
function! g:Open_firefox_in_new_window(url)
silent exe 'silent !open -na "Firefox" --args --new-window ' . a:url
endfunction
let g:mkdp_browserfunc='g:Open_firefox_in_new_window'
@fishioon 用窗口管理工具吧 https://github.com/koekeishiya/yabai ,感觉这个插件应该不好做分屏。 然后这么设置。
function! g:Open_firefox_in_new_window(url) silent exe 'silent !open -na "Firefox" --args --new-window ' . a:url endfunction let g:mkdp_browserfunc='g:Open_firefox_in_new_window'
我使用firefox作为预览浏览器,但是我每次打开预览总会和其他网页合并到一起,我想单独一个窗口打开预览,请问有什么方法解决吗?
或许可以用AppleScript实现?
下边是一个iTerm2 + Chrome的demo,只是窗口铺满桌面了,不是全屏
- 当前vim窗口铺满桌面,运行
:!osascript xxx.scpt
- 效果是左边vim占半屏,右边chrome占半屏
-- a debug helper function
on print(msg)
display notification msg with title "AppleScript Message"
end print
-- get the size of the whole window
on get_window_size()
-- I assume that iTerm2 is in fullscreen **with top menubar on**
tell application "iTerm2"
set ret to the bounds of the front window
return { item 3 of ret, item 4 of ret }
end tell
end get_window_size
-- place app window to pos
-- pos is a list {x, y, x+w, y+h}
on place_app(app_name, pos)
tell application app_name
set the bounds of the first window to pos
activate -- grab focus
end tell
end place_app
on open_chrome(target_url, pos)
tell application "Google Chrome"
tell (make new window)
set URL of active tab to target_url
set bounds to pos
end tell
end tell
end open_chrome
on main()
set window_size to get_window_size()
set window_width to item 1 of window_size
set window_height to item 2 of window_size
open_chrome("http://xxx:xxx/page/1", ¬
{window_width / 2, 0, window_width, window_height})
place_app("iTerm2", {0, 0, window_width / 2, window_height})
end main
main()
全屏有办法吗
我用的lazyvim(neovim)
Steps
- 写一个applescript,随便存到哪个位置,内容如下:
set Height to 1120 -- 这个地方改为你屏幕的高度
set Width to 1792 -- 改为屏幕的宽度
set bar to 24 -- 苹果顶部导航栏的高度
set halfHeight to Height / 2
set halfWidth to Width / 2
-- 检查应用是否在全屏状态
tell application "iTerm" to set screenSize to bounds of front window
set rightX to item 3 of screenSize
if rightX is equal to Width then
-- 关闭iTerm的全屏状态
tell application "System Events"
tell process "iTerm2"
click (first menu item whose name is "Toggle Full Screen") of menu "View" of menu bar 1
end tell
end tell
delay(0.5)
end if
-- 打开Chrome并放置在右侧
tell application "Google Chrome" -- 也可以是"firefox"等等浏览器
make new window -- 创建新窗口来打开preview
set the bounds of the first window to {halfWidth, bar, Width, Height}
end tell
-- 调整iTerm大小并放置到左侧
tell application "iTerm"
activate
set the bounds of the first window to {0, bar, halfWidth, Height}
delay(0.5)
end tell
上面的延时函数都是经过测试之后添加的,最好不要删除。因为程序执行打开、最小化等操作需要时间,如果在上一个操作还没有完成就执行下一条自动化命令,可能会出现奇怪的bug。 如果还是有奇怪的bug比如窗口开在别的桌面啥的,可以适当增加一下延时的时间。 2. 在快捷键配置文件,我的是在:~/.config/nvim/lua/config/keymaps.lua 加入以下配置:
local keymap = vim.keymap -- lazyvim的快捷键设置对象
local mode_n = {"n"} -- normal模式
-- 我的快捷键是<leader>mp,按自己需求改一下
keymap.set(mode_n, "<leader>mp", ":silent !osascript your/absolute/path/to/applescript.applescript<cr>:MarkdownPreview<cr>", { desc = "markdown preview", remap = true, silent = true})
-- 注意path一定要是绝对地址,因为运行这段代码的md文件位置是不定的,所以相对地址会找不到文件
-- 其他两个命令把上面:MarkdownPreview分别改称:MarkdownPreviewStop和:MarkdownPreviewToggle就可以了
如果不是用lazyvim的lua配置,也差不多,把上面lua的配置换成vimrc的配置语言就好,内核都是一样的,先用osascript执行以下applescript然后:MarkdownPreview
效果如下:
iTerm是不是全屏状态都可以用,自动调整大小到一半