New answers tagged

0

I have ended up with: nnoremap * :keepjumps normal! mi*`i<CR> Source: https://stackoverflow.com/a/4257175/4565485


3

This will do for the * search, I'm not sure how to do that for /. nnoremap <silent> * :let @/= '\<' . expand('<cword>') . '\>' <bar> set hls <cr> @/ is the search register, which we set to <cword>, the word under the cursor, surrounded by words boundaries \< \> to match actual words rather than parts of words. g* ...


3

The global command marks every line matching a pattern and executes a list of actions on them. Each action is separated by the pipe symbol, |. In :g/^/s/foo/bar/|+t+|-d the pattern is ^, so all the lines are marked. Then, three actions are executed on the marked lines: s/foo/bar/: substitute "foo" by "bar". +t+: Duplicate the next line. ...


2

I found that /^\( inflating: \| extracting: \)\@!<CR> works. For years if not decades, I found that zero-width matches evaded intuitive comprehension, especially those of the backward and non-matching type. For this reason, I've posted this answer rather than erasing the question. If this is too elementary, just let me know in the comments and I ...


2

In recent versions of vim (around patch 8.2.0915), search takes a skip argument which can be used to create a move forward/backward to syntax group motion. Here is a rudimentary implementation: function! SynMatches(syn) abort return synIDattr(synID(line('.'), col('.'), 1), "name") =~# a:syn endfunction function! SynMove(syn, dir) abort let l:...


1

Here is a quick starter implementation which simply moves forward until the syntax is matched. synID is generally quite slow, but fortunately, vim accelerates it in the forward direction using caching. nnoremap <plug>(forward) <space> function! s:forward_to(syn) abort let l:save_view = winsaveview() let [l:ol, l:oc] = [line('.'), col('.')] ...


0

With Neovim, you can use nvim-treesitter for parsing the syntax together with nvim-treesitter-textobjects to achieve this. Treesitter provides a parser rather than using regular expressions to find the objects, and can be used to replace Vim's native highlighting as well.


Top 50 recent answers are included