markonm / traces.vim Goto Github PK
View Code? Open in Web Editor NEWRange, pattern and substitute preview for Vim
License: MIT License
Range, pattern and substitute preview for Vim
License: MIT License
When using the following minimal vimrc:
if &compatible
set nocompatible " don't try to be compatible with Vi
endif
set runtimepath+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'markonm/traces.vim'
let g:traces_preview_window = "below 5new"
and I try and use :g/^
(or :v/^
) on a non-empty file, vim completely
freezes until I hit ctrl
+c
(escape doesn't work).
vim version info:
:version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31)
Included patches: 1-2269
Modified by [email protected]
Compiled by [email protected]
Huge version with GTK3 GUI. Features included (+) or not (-):
PRs neovim/neovim#12721, neovim/neovim#12905 merge Vim's incsearch patches to Neovim master branch. There are nighly releases available for testing.
Please update the feature comparison table at https://github.com/markonm/traces.vim#feature-comparison to reflect Neovim's current features.
I think it would be awesome to see both "old" and "new" text:
Today I found using ":%s" in any file will cause the following error:
Error detected while processing function <lambda>70[1]..traces#init[45]..<SNR>190_preview_substitute[13]..<SNR>190_highlight:
line 12:
E487: Argument must be positive
I compiled vim recently after pulled the latest version. I tested with older version of vim and it worked fine so my guess is either the latest vim breaks this plugin or my compile is not configured correctly and breaks the plugin
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 7 2022 19:13:45)
Included patches: 1-4710
Huge version with GTK2 GUI. Features included (+) or not (-):
+acl +channel +cscope +ex_extra -hangul_input +linebreak +mouse_dec -mzscheme +profile -sodium -tcl +user_commands +wildmenu
+arabic +cindent +cursorbind +extra_search +iconv +lispindent -mouse_gpm +netbeans_intg -python +sound +termguicolors +vartabs +windows
+autocmd +clientserver +cursorshape -farsi +insert_expand +listcmds -mouse_jsbterm +num64 +python3 +spell +terminal +vertsplit +writebackup
+autochdir +clipboard +dialog_con_gui +file_in_path +ipv6 +localmap +mouse_netterm +packages +quickfix +startuptime +terminfo +vim9script +X11
-autoservername +cmdline_compl +diff +find_in_path +job -lua +mouse_sgr +path_extra +reltime +statusline +termresponse +viminfo -xfontset
+balloon_eval +cmdline_hist +digraphs +float +jumplist +menu -mouse_sysmouse -perl +rightleft -sun_workshop +textobjects +virtualedit +xim
+balloon_eval_term +cmdline_info +dnd +folding +keymap +mksession +mouse_urxvt +persistent_undo -ruby +syntax +textprop +visual +xpm
+browse +comments -ebcdic -footer +lambda +modify_fname +mouse_xterm +popupwin +scrollbind +tag_binary +timers +visualextra +xsmp_interact
++builtin_terms +conceal +emacs_tags +fork() +langmap +mouse +multi_byte +postscript +signs -tag_old_static +title +vreplace +xterm_clipboard
+byte_offset +cryptv +eval +gettext +libcall +mouseshape +multi_lang +printer +smartindent -tag_any_white +toolbar +wildignore -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cai
ro -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/gli
b-2.0/include -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp
-lSM -lICE -lm -ltinfo -lselinux -lcanberra -ldl -L/usr/lib/python3.7/config-* -lpython3.7m
Pressing d once deletes the line under the cursor instead of dd.
To reproduce:
I'm using Neovim 0.2. and vimplug as the plugin manager
This is the init.vim (vimrc) required to reproduce the issue
call plug#begin()
Plug 'xtal8/traces.vim'
call plug#end()
I have noticed a similar bug logged with deoplete
Shougo/deoplete.nvim#460
Thanks :)
I have found that whenever using traces, a split window that's currently "minimized" (i.e. having 0 height) would open themselves after the highlight (e.g. :%s/foo/bar
). A simple repro below after opening a new Vim instance with a fresh .vimrc:
:set winminheight=0
:split
<C-W>_
:%s/foo/bar
The fourth line would trigger traces' highlight code, and expand the first window which has been minimized.
Digging through the code, it seems like the issue comes from the spurrious win_gotoid()
calls from s:highlight()
and traces#cmdl_leave()
. Each time the script enter a new window via win_gotoid
, if winheight
is larger than winminheight
, the window will get expanded causing this bug.
It seems to me a simple way to fix this is to not visit the other windows, maybe through a setting called g:traces_only_current_window=1
that will only update the current window instead of the other ones too. Also the following lines may have to be re-thought as well:
if bufname('%') !=# '[Command Line]'
noautocmd call win_gotoid(alt_win)
noautocmd call win_gotoid(cur_win)
endif
Other option may be to make sure to restore the proper heights of each window. That seems more error prone to me but it would allow us to keep the existing functionality of updating multiple windows.
When a range is highlighted, the cursor moves to the last line of the range until the command is executed. When using relative numbering this makes it hard to use commands like :t and :m, since the displayed relative numbers will change, but vim will still expect the relative numbers as displayed before the highlighting moves the cursor.
Is it possible to make a fix to keep the cursor position on the same line during the highlight, or alternatively create a setting to disable range highlighting for certain commands?
https://github.com/tpope/vim-abolish#substitution
With vim-abolish, instead of this:
:%s/facility/building/g
:%s/Facility/Building/g
:%s/FACILITY/BUILDING/g
:%s/facilities/buildings/g
:%s/Facilities/Buildings/g
:%s/FACILITIES/BUILDINGS/g
You can do this:
:%Subvert/facilit{y,ies}/building{,s}/g
I think if traces.vim supported previews for this, it would be amazing!
Would it be possible to create a new highlight group, perhaps called TracesReplace
that highlights all the replacement text, perhaps mapped to IncSearch
by default? I really like the way vim-fnr highlights its replacement, but I sometimes need to use regexen for more complex substitutions. Thanks!
Great plugin BTW.
Substitution preview is pretty awesome, but it would be great to have support for https://github.com/tpope/vim-abolish#substitution.
Example:
!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function g(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}return function e(l){function C(e,n,o){var t;if("undefined"!=typeof document){if(1<arguments.length){if("number"==typeof(o=g({path:"/"},C.defaults,o)).expires){var r=new Date;r.setMilliseconds(r.getMilliseconds()+864e5*o.expires),o.expires=r}o.expires=o.expires?o.expires.toUTCString():"";try{t=JSON.stringify(n),/^[\{\[]/.test(t)&&(n=t)}catch(e){}n=l.write?l.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=(e=(e=encodeURIComponent(String(e))).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)).replace(/[\(\)]/g,escape);var i="";for(var c in o)o[c]&&(i+="; "+c,!0!==o[c]&&(i+="="+o[c]));return document.cookie=e+"="+n+i}e||(t={});for(var a=document.cookie?document.cookie.split("; "):[],s=/(%[0-9A-Z]{2})+/g,f=0;f<a.length;f++){var p=a[f].split("="),d=p.slice(1).join("=");this.json||'"'!==d.charAt(0)||(d=d.slice(1,-1));try{var u=p[0].replace(s,decodeURIComponent);if(d=l.read?l.read(d,u):l(d,u)||d.replace(s,decodeURIComponent),this.json)try{d=JSON.parse(d)}catch(e){}if(e===u){t=d;break}e||(t[u]=d)}catch(e){}}return t}}return(C.set=C).get=function(e){return C.call(C,e)},C.getJSON=function(){return C.apply({json:!0},[].slice.call(arguments))},C.defaults={},C.remove=function(e,n){C(e,"",g(n,{expires:-1}))},C.withConverter=e,C}(function(){})});
function(temperature, useless) { }
If you place your cursor on the second line on temperature
and execute SidewaysRight, there is a noticable delay in execution. This goes away if the long line is after the cursor
function(temperature, useless) { }
!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function g(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}return function e(l){function C(e,n,o){var t;if("undefined"!=typeof document){if(1<arguments.length){if("number"==typeof(o=g({path:"/"},C.defaults,o)).expires){var r=new Date;r.setMilliseconds(r.getMilliseconds()+864e5*o.expires),o.expires=r}o.expires=o.expires?o.expires.toUTCString():"";try{t=JSON.stringify(n),/^[\{\[]/.test(t)&&(n=t)}catch(e){}n=l.write?l.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=(e=(e=encodeURIComponent(String(e))).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)).replace(/[\(\)]/g,escape);var i="";for(var c in o)o[c]&&(i+="; "+c,!0!==o[c]&&(i+="="+o[c]));return document.cookie=e+"="+n+i}e||(t={});for(var a=document.cookie?document.cookie.split("; "):[],s=/(%[0-9A-Z]{2})+/g,f=0;f<a.length;f++){var p=a[f].split("="),d=p.slice(1).join("=");this.json||'"'!==d.charAt(0)||(d=d.slice(1,-1));try{var u=p[0].replace(s,decodeURIComponent);if(d=l.read?l.read(d,u):l(d,u)||d.replace(s,decodeURIComponent),this.json)try{d=JSON.parse(d)}catch(e){}if(e===u){t=d;break}e||(t[u]=d)}catch(e){}}return t}}return(C.set=C).get=function(e){return C.call(C,e)},C.getJSON=function(){return C.apply({json:!0},[].slice.call(arguments))},C.defaults={},C.remove=function(e,n){C(e,"",g(n,{expires:-1}))},C.withConverter=e,C}(function(){})});
I'm not sure why this is happening. Is it possible that the multi-line parsing gets slowed down? If so, would it be possible to add an option for only movements taking place on the same line?
Hey Marko,
Thanks for an awesome plugin!
One thing I noticed after recent update is that ranges are no longer being previewed for commands such as :1,10d
or :32,55y
. Although commit 46e01b6 aims to prevent ambiguous matches, I don't quite understand why these are considered ambiguous in this case, so decided to file a bug report.
Best regards,
Sergey
I often perform substitutions with :cdo
. For example,
:cdo %s/this/that/gc
That will apply the substitution across all files in my quickfix window from an ag search.
Think it might be possible to highlight & preview this type of substitution with traces.vim?
Is it possible to skip the range highlight is the hole file, using %
?
Could this be done by adding a condition at https://github.com/xtal8/traces.vim/blob/cb67127f0735118bfdda22ce977a3b75077bc561/plugin/traces.vim#L135
What about adding the possibility to automatically turn the highlight off after an operation is completed (like, if substitute command was performed on a range โ it still highlights search patterns outside the range then), or if the cursor was moved after a search (surely, that should exclude n/N
movements)?
I use the command window (opened with q: q/ or q?) and have noticed that this does not work there.
Is it possible to make a split display upon starting a substitution showing matches and replacements, akin to set inccomand=split
in NeoVim? Thanks.
Loving traces.vim so far! Also nice to see .vader tests
Curious though, you mention it's inspired by vim-over? How does this compare to vim-over, differences/pros/cons?
In any archive, hitting
:%substitute:\v::cgI<Left><Left><Left><Left><Left>
inserts line breaks where spaces are. Same for any other regular expression syntax modifier, such as \m
or \V
.
I just found out about this plugin and so far I like it a lot.
While the live substitution preview, if the substitution string gets long enough for the line to wrap (set wrap
is on), the preview wraps 8 characters before the end of the visual line is reached.
This isn't a big deal, but when a live substitution early-wraps on a line that otherwise wouldn't wrap, the opening of a new visual line that gets closed the moment a user hits <CR>
and the command executes.
Hello,
I've found an odd behaviour which seems to be related to traces.vim.
Steps to reproduce:
vim
:g/foo
or any other command that traces.vim has an effect on. (:s
, :v
)/
.<BS>
Expected behaviour (<CURSOR>
denotes cursor position): :<CURSOR>/foo
.
Actual behaviour: :/<CURSOR>foo
.
The reason I believe this is caused by traces.vim is because removing it made the unexpected cursor movement go away.
Hi, this plugin is super great! Unfortunately I use a dark theme terminal and the bright yellow highlighting makes it impossible to read the light-colored text. It would be so great if the highlighting color was configurable!
How about the plugin make better like incsearch.vim?
For example: set
let g:traces_auto_nohlsearch = v:true
to enable the new feature.
To reproduce:
> vim -E ~/.bash_logout
"~/.bash_logout" 7L, 174C
Entering Ex mode. Type "visual" to go to Normal mode.
:ver
Error detected while processing CmdlineLeave Autocommands for ":":
E121: Undefined variable: s:incsearch
This would probably fix it:
plugin/traces.vim
, line 97:
autocmd CmdlineLeave,CmdwinEnter : if exists("s:incsearch") | noautocmd let &incsearch = s:incsearch | endif
Used vim-plug to install.
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 12 2017 04:34:55)
Included patches: 1-172
Is there something that I am missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.