I want to be able to click (or cmd+click on my Mac) on a function name in Gvim (or vim with set mouse=a) and have it run the command :tag to follow a ctag, but I don't know how to include a mouse click in a Vim mapping.
A good place to start:
:help click
:help mouse
Perhaps something like this will work:
:map <RightMouse> :tag <CR>
Related
I am using project and minibufexpl(mbx) with my vim.
The problem is using <C-6>, the buffer only toggles between last two open buffer, and not the all buffers open.
I checked vim's wiki but it says about listing the buffer and then selecting them manually i.e. map for :ls and :b. Not much helpful.
Though, I can move through all the open buffers using mbx's way, (go to mbx window and keep pressing arrow), a like alternative would have been helpful if it can span through all open buffers.
Any help please?
The simplest solution to your problem seems to be to use Vim's built-in :bn and :bN.
See :help buffers.
I've tested this in vim 7.3 on a Linux installation.
To have Vim insert a character sequence instead of doing the action, prefix it with Ctrl+v or Ctrl+q (in Windows). So to get the map sequence for Ctrl+right arrow press Crtl+v, then Ctrl+right arrow to get Vim to insert ^[[1;5C, similarly ^[[1;5D for Ctrl+left arrow.
You can then add the following to your .vimrc file to cycle through all buffers by pressing Ctrl+right arrow or Ctrl+left arrow:
nmap ^[[1;5C :bn^M
nmap ^[[1;5D :bN^M
nmap does the mapping only for normal mode. The ^M means Ctrl+v, then <return>.
While working with some Vim scripts, I found myself typing
:help {subject}
quite a bit. I want CTRL+] (jump to definition of keyword under cursor) functionality, but instead of running :tag {ident} I want it to do :help {subject}, where {subject} is the word under the cursor.
Just press K. If you have set a global 'keywordprg', you need to unset it (or set it to the special :help value) in ~/.vim/after/ftplugin/vim.vim:
:setlocal keywordprg=:help
The simplest solution is
nnoremap K :help <C-r><C-w><CR>
To check the documentation of the keyword under your cursor, you can press Ctrl+] to go to its documentation.
If you have enable mouse support in nvim with the following options:
set mouse=a
you can double click the keyword to go to its documentation.
By the way, to go back to previous position in the help file, press Ctrl+O or Ctrl+T.
The above is also true for Neovim.
References
https://vimhelp.org/
I'a writing a plugin. I opened a buffer, and drap some menu items in it. I want to trigger some special function when a enter key is pressed. I used nmap :func() , but enter key triggered the func in other buffers as well.
Can anybody tell me how to do keymapping that works only in the specified buffer?
Or any ideas about how to make a menu is welcome, I don't have any experience in writing plugins before.
Thanks in advance.
Regards,
Dean
You can restrict a keymapping to the current buffer by adding <buffer> to the mapping, like this:
nmap <buffer> <CR> :call func()<CR>
See :help map-arguments for details.
You can add menu items to the main menu via the amenu command:
amenu &MyMenu.MyMenu&Item :call MyFunc()<CR>
This command adds a new menu MyMenu and a new menu item MyMenuItem to MyMenu.
You can remove the menu item (or the whole menu) via the aunmenu command.
See :help amenu and :help aunmenu for details.
I just discovered :set mouse=a. Amazing thing, it allows my coworkers to scroll over my openend files.
But here is the thing : I really don't want the cursor to move when I left-click somewhere. I don't want either the standard cursor which :set mouse=a brings (I want to keep the default text cursor).
In others words : is there a way to enable mouse scrolling in VIm without enable other support mouse stuff ?
Thanks.
EDIT - other idea : can I bind the wheel mouse UP to do the same thing that Page Up key ? It would be awesome !
Try this mapping:
:nnoremap <LeftMouse> <nop>
By default, I think my vimrc setttings enable the auto-wrapping. However, sometimes, I would like to see text lines are not wrapped. Is there any command I toggle the text line wrapping enabled and disabled? This would avoid me to exit and to change settings.
I think what you want is:
:set wrap!
This will toggle line wrapping.
More about using ! (bang) to alter commands can be found at:
:help :_!
In your vimrc, create a function such as this:
:function ToggleWrap()
: if (&wrap == 1)
: set nowrap
: else
: set wrap
: endif
:endfunction
Then map a key (such as F9) to call this function, like so:
map <F9> :call ToggleWrap()<CR>
map! <F9> ^[:call ToggleWrap()<CR>
Whenever you press F9, it should toggle your wrapping on and off.
:set nowrap
There is also the linebreak option that controls whether wrapped text is broken at word boundaries or not.
Add the following to have CTRL+W toggle wrapping. You can change it to some other key if you don't want w to be it.
map <C-w> :set wrap!<CR>
The quickref suggests (no)wrap
I happen to like tpopeās unimpaired plugin, where yow will toggle wrap settings.
For those who want to change the text instead of just visual effect, for example in git commit, just press qt in a roll and press enter. This will properly wrap the current paragraph your cursor is in. The paragraph is only delimited by blank lines. or you can select some area to press qt.
I found this by total accident.