Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tips & tricks] #62

Open
leo-fp opened this issue Oct 18, 2021 · 1 comment
Open

[tips & tricks] #62

leo-fp opened this issue Oct 18, 2021 · 1 comment

Comments

@leo-fp
Copy link

leo-fp commented Oct 18, 2021

This page is used to collect tips and tricks that can inspire novice or advanced users.

If you think this plugin is useful or fun, just show us how you use it. The idea comes from
here.

note: The user manual is highly recommended to read.

Rules

  • Many posts allowed
  • ...
@leo-fp
Copy link
Author

leo-fp commented Oct 18, 2021

The Menu and Context menu are the two widgets i use most.

I usually can't remember how to use some infrequently used plug-ins, so as long as these plug-ins are allowed to be used by
functions or commands, I will put them in these two widgets.

The true trick i think is adding an item for some functions that needs selected text.

For example, if you have openbrowser installed, select a text, then press <leader>q, and execute the item, your browser will be opened and search the selected text automatically.

usage: put this in your vimrc

note: if your leader key has not been modified, it should be "\"

" from https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript/6271254#6271254
function! Get_visual_selection()
    " Why is this not a built-in Vim script function?!
    let [line_start, column_start] = getpos("'<")[1:2]
    let [line_end, column_end] = getpos("'>")[1:2]
    let lines = getline(line_start, line_end)
    if len(lines) == 0
        return ''
    endif
    let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
    let lines[0] = lines[0][column_start - 1:]
    return join(lines, "\n")
endfunction
function! Demo()
    let l:content = [
                \ ["search", "call openbrowser#search(Get_visual_selection(), \"baidu\")"],
                \ ]
    " set cursor to the last position
    let opts = {'index':g:quickui#context#cursor}
    call quickui#context#open(content, opts)
endfunction
vnoremap <leader>q :<c-u>call Demo()<CR>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant