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/
Related
I would like to define a command, gv, which jumps to definition in a split window. I'm aware that gd is the command to jump to definition but in the existing window.
I tried this mapping:
nnoremap <silent> gv :vsplit<CR>gd
But it didn't work. It opened up the exactly same file in a split window, without actually jumping to definition. Seems like the gd command after <CR> was ignored. How do I fix this?
I saw some answers mentioning <C-]> but is there away to implement this without generating tags?
Hopefully this makes sense. Thanks in advance!
:help gd jumps to the local definition of the word under the cursor. That "local definition" is always in the same buffer no matter what so I hope you don't expect it to jump to some other buffer.
Your mapping:
nnoremap <silent> gv :vsplit<CR>gd
works as expected, here: the window is split and the cursor jumps to the local definition of the word under the cursor:
First jump is with gd, second jump is with your gv.
If you want a "jump to definition" that works across files, gd and gD are not what you want. See :help ctags, :help cscope and :help include-search. Note that those features are not particularly smart. If you want something that understands your code better than you do, look elsewhere.
You don't actually need to define a new mapping/command for this. If you press CTRL-W d (or type :dsp <word>), it will show you the definition in a new window. From the documentation:
CTRL-W CTRL-D *CTRL-W_CTRL-D* *CTRL-W_d*
CTRL-W d Open a new window, with the cursor on the first
macro definition line that contains the keyword
under the cursor. The search starts from the
beginning of the file. If a count is given, the
count'th matching line is jumped to.
However, if you really want to press gv and have the definition shown, an alternative to romainl's solution is the following:
nnoremap gv :vertical dsplit <C-R><C-w><cr>
I am using easymotion plugin (https://github.com/easymotion/vim-easymotion) with vim.
If you use f/F motions in VIM (with easymotion plugin), easy motion highlights all possible positions when there are multiple matches, that way you can easily jump to the position you want.
But it doesn't work with y/c/d commands, how can I achive that ?
I have provided an example below for clarification:
This is some line.
Say I am working on the above line in vim and the cursor is at the i in "This". If I do "yfs" in vim, I would like easy motion to mark the three "s"s present to the right of the cursor. That way, I can easily yank/change/delete upto the s I want.
Thanks in advance !
You can, use something like this in your .vimrc:
" Find next occurence of a char using easymotion
map <Leader>f <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
Now you can do something like y<Leader>fs and it will highlight the three s-characters. Selecting one will then yank from your cursor's position to that character.
If this does not work
This means that there are other key bindings that are using the same combination. You can check this with :map and then look for the key combination you are trying to map to the easy-motion. Removing that keybinding from your .vimrc or removing the plugin that created the binding should solve the problem.
If it's the YankRing plugin that's hijacking the y/c/d keystrokes, you can add the following to your vimrc to prevent it from doing that (Check :h yankring for more info):
let g:yankring_zap_keys = ''
Is there an option to auto-complete a currently typed command with one from the history, without using the direction keys?
This an extension to this question: How do you search through vim's command history?.
The answer was, after typing :somecommand to use the <up> key. I would think it is more vim-like not to have to lift the hand to go to the direction keys.
From :help cmdline-completion, I tried, Ctrl-N, Ctrl-P, Ctrl-D, Ctrl-L without success.
Here's maybe a related part of my vimrc.
set completeopt=menu,longest,preview
set showcmd
set wildchar=<Tab> wildmenu wildmode=longest,list,full
set wildcharm=<C-Z>
I'm aware of the command line window invoked with q: or :Ctrl-F and the Ctrl-N and Ctrl-P to go through the history linearly after typing :.
You can always map this to something. I once tried using
cnoremap <C-p> <Up>
, but this will disable completion cycling so you should better deduce something else (there is no way like pumvisible() to determine whether completion is active in command mode).
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>
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.