使用Vim集成堆栈溢出

时间:2012-10-03 20:50:20

标签: firefox vim

我最近在这里开始做审查任务(编辑第一篇帖子/后期答案等)。

  • 起初我试图从Firefox本身进行编辑
  • 然后我开始复制到Vim并在那里进行格式化
  • 很快我发现Firefox的it's all text插件可以编辑多行文本字段

所以现在我正在尝试找到下一步,它将消除所有鼠标点击(编辑/提交等),仅在Vim上完成工作。 Firefox中的当前界面(只需点击一下即可为您提供下一个第一篇文章)似乎能够集成到Vim本身,所以我想知道是否/如何实现这一目标?

如果没有,你有什么好的做法?

3 个答案:

答案 0 :(得分:1)

嗯,这是一种方法:

  1. 安装Vimperator,这是一款非常类似于Firefox的Vim-like插件
  2. 将以下内容添加到〜/ .vimperatorrc

    autocmd LocationChange。*:set editor =“xterm -x vim”

  3. Vim编辑器在由vim按键控制的浏览器中,无需鼠标。赢得。 (选择你喜欢的xterm,顺便说一句)

    另一种方法是切换到终端并使用w3m。很容易配置使用vim作为编辑器。但是,如果不使用JavaScript,就不那么容易使用stackoverflow。

答案 1 :(得分:1)

特别是由于Stack Overflow等现代Web应用程序的用户界面(以及基础JavaScript需求)越来越丰富,我建议不要移出浏览器,特别是因为实现了基于Vim的客户端(尽管可以使用像 curl wget ,甚至像webapi.vim这样的可用库都需要付出很多努力。

我发现使用你提到的Firefox附加组件已经非常有效(我已经转移到 Pentadactyl ,一个 Vimperator fork)和一个单独的GVIM实例,特别是如果你精简这个。我在blog post中描述了如何为Stack Overflow文本区域自动设置markdown文件类型。

答案 2 :(得分:0)

我刚开始尝试使用 w3m 在终端中浏览。您可以将所有键绑定更改为类似 vim(对于特定于 Web 的内容,我在 Vimium 中复制了绑定),并直接使用 vim 编辑站点上的文本字段。我只使用了一天,我还不知道如何处理“你是机器人吗”的检查……但是缩小 vim 编码与谷歌搜索 + 复制和将内容粘贴回 vim。

我已经设置好了,所以当我在 w3m 中按 v 时,它会在 vim 中打开页面,然后我将 vim 设置为立即将文件另存为 /tmp/w3m_scratch 并返回到 w3m。然后我转到我正在编码的 vim 实例,并使用另一个映射切换水平分割与 /tmp/w3m_scratch 文件(即我感兴趣的网页)。这让我可以快速将页面上的所有信息获取到我正在编码的同一个 vim 实例中,并且可以使用 vim 的所有功能将来自 stackoverflow(或某些其他站点)的文本集成到我的工作中:

function! WriteW3MToScratch()
    " only if the file matches this highly specific reg exp will we do anything
    "(e.g. a file that looks like: .w3m/w3mtmp7352-3)
    if match(@%, "\.w3m/w3mtmp\\d\\+-\\d") != -1
        :silent! wq! /tmp/w3m_scratch
    endif
endfunction

function! ToggleW3M()
    if bufexists("/tmp/w3m_scratch")
        :bwipe! /tmp/w3m_scratch
    else
        :silent! split /tmp/w3m_scratch
    endif
endfunction

" anytime we read in a buffer, if it came from w3m then write to scratch
autocmd BufReadPost * :call WriteW3MToScratch()

" open/close horizontal split containing w3m_scratch
nnoremap <leader>w :call ToggleW3M()<cr>

我使用 this git repo 上的键盘映射文件作为基础,这是我目前所拥有的。我不得不说,使用这些设置确实感觉非常像 vim。

# w3m keymap file with Vim key bindings
# by Felipe Saa (https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m)
# adapted by Matthew Bennett
#
# Ctrl      : C-, ^
# Escape    : ESC-, M-, ^[
# Space     : SPC, ' '
# Tab       : TAB, ^i, ^I
# Shift+Tab : ^[[Z
# Delete    : DEL, ^?
# Up        : UP, ^[[A
# Down      : DOWN, ^[[B
# Right     : RIGHT, ^[[C
# Left      : LEFT, ^[[D
# Re Pag    : M-[5~
# Av Pag    : M-[6~
# Enter     : C-j  RET(pendant confirm)

#-custom map commands..........................................................
# switch the color of links for light/dark colourscheme
keymap  SPCd    COMMAND         "SET_OPTION  anchor_color=yellow"
keymap  SPCl    COMMAND         "SET_OPTION  anchor_color=blue"
# skip past all the cruft on the stack sites to where the question is asked
keymap  st      COMMAND         "WHEREIS Ask\ Question;  CENTER_V;  NEXT_HALF_PAGE"

#-scrolling....................................................................
keymap  C-y     DOWN
keymap  C-e     UP
keymap  gg      BEGIN
keymap  G       END
keymap  C-d     NEXT_HALF_PAGE
keymap  C-u     PREV_HALF_PAGE
keymap  C-f     COMMAND         "NEXT_HALF_PAGE;  NEXT_HALF_PAGE"
keymap  C-b     COMMAND         "PREV_HALF_PAGE;  PREV_HALF_PAGE"
keymap  zz      CENTER_V
keymap  zt      COMMAND         "CENTER_V;        NEXT_HALF_PAGE"
keymap  zb      COMMAND         "CENTER_V;        PREV_HALF_PAGE"

#-cursor.......................................................................
keymap  l       MOVE_RIGHT1
keymap  h       MOVE_LEFT1
keymap  j       MOVE_DOWN1
keymap  k       MOVE_UP1
keymap  0       LINE_BEGIN
keymap  $       LINE_END
keymap  w       NEXT_WORD
keymap  b       PREV_WORD
keymap  C-o     UNDO            # Undo cursor movement.
# keymap  C-i  REDO             # Undo undone cursor movement (confused with TAB)

#-tab..........................................................................
# Close current tab and save it to be able to restore it.
keymap  x       COMMAND         "EXTERN 'echo %s >> ~/.w3m/RestoreTab.txt' ; CLOSE_TAB"

# new search in new tab (drops right into google search)
keymap  o       COMMAND         "GOTO https://google.com; GOTO_LINE 6; NEXT_LINK; GOTO_LINK"

# new search (drops right into google search)
keymap O        COMMAND         "TAB_GOTO https://google.com; GOTO_LINE 6; NEXT_LINK; GOTO_LINK"

keymap J        PREV_TAB        # Change focus to right tab
keymap K        NEXT_TAB        # Change focus to left tab
keymap gJ       TAB_LEFT        # Move tab to the left
keymap gK       TAB_RIGHT       # Move tab to the right
keymap yt       NEW_TAB         # Duplicate current tab
keymap gt       TAB_MENU        # Tab menu
keymap :t       TAB_MENU        # Tab menu
# keymap X        TAB_GOTO        /usr/lib/w3m/cgi-bin/restore_tab.cgi # Restore last closed tab

#-url operations...............................................................
keymap f        GOTO_LINK       # Follow link in current tab
keymap gf       TAB_LINK        # Follow link in a new foreground tab
keymap F        COMMAND         "TAB_LINK; PREV_TAB" # follow link under cursor in new background tab
keymap gF       MOVE_LIST_MENU  # link list --> move cursor to link
keymap r        RELOAD          # Reload current page.

#-link navigation..............................................................
keymap [        NEXT_LEFT_UP
keymap ]        NEXT_RIGHT_DOWN

#-history navigation...........................................................
keymap L        NEXT            # Go forward in history
keymap H        PREV            # Go back in history
keymap :b       SELECT_MENU     # Recent pages
keymap :B       HISTORY         # Show history

#-bookmarks....................................................................
# keymap C-d      ADD_BOOKMARK  # Add current page to bookmarks
# keymap gb       VIEW_BOOKMARK # Show bookmarks
# keymap :b       VIEW_BOOKMARK # Show bookmarks

#-search.......................................................................
keymap /        ISEARCH         # Enter find mode
keymap ?        ISEARCH_BACK    # Enter find mode backwards (incremental)
keymap n        SEARCH_NEXT     # Find next
keymap N        SEARCH_PREV     # Find previous

#-commands.....................................................................
keymap !        COMMAND         
keymap |        PIPE_BUF        # Send rendered document to pipe

keymap :h       HELP            # View help
keymap :o       OPTIONS         # Option setting panel
keymap :q       QUIT            # Quit w3m with confirmation (q alone works too)
keymap ZZ       EXIT            # Quit w3m without confirmation.

# Reload configuration files.
keymap :s       REINIT

#-info.........................................................................
keymap gC-g     INFO            # current page info
keymap C-g      LINE_INFO       # line under cursor info

#-miscellaneous................................................................
keymap v        EDIT_SCREEN     # Edit current rendered document with sensible-editor

#-unused url operations.......................................................
# keymap        PEEK                        # Show current page url.
# Focus in address bar.
# keymap ef    PEEK_LINK                    # Show link under cursor.
# Execute external browser = open current link in $BROWSER
# tip: number(2-9) + external browser shortcut(M-o) executes executes the
# external browser command linked to the prefix number.
# See "External Program Settings" in "Option Setting Panel"(OPTIONS)
# Open current link with external browser = sensible browser
# keymap M-o   EXTERN
# copy current url and remove newline at the end.
# keymap yy    EXTERN     copy_url.sh
# keymap yy       EXTERN     "echo -n %s | xclip -i -selection clipboard"
# keymap yy       EXTERN     "echo -n %s | xsel -b"
# open link under cursor with external browser = sensible browser
# keymap M-p   EXTERN_LINK
# Copy link under cursor, It does not copy images urls
# keymap yf       EXTERN_LINK 'env printf %s "$0" | xsel -b'
# keymap yf    EXTERN_LINK  copy_url.sh
# follow link in clipboard in the current tab.
# keymap p   GOTO       /usr/lib/w3m/cgi-bin/goto_clipboard.cgi
# follow link in clipboard in new foreground tab.
# keymap P     TAB_GOTO /usr/lib/w3m/cgi-bin/goto_clipboard.cgi

#-.............................................................................