Editing Comparing files

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 45: Line 45:
 
# Add following lines to your <code>vifmrc</code>:<code>
 
# Add following lines to your <code>vifmrc</code>:<code>
 
     command! cmpinternal compare-cmd %a %S
 
     command! cmpinternal compare-cmd %a %S
     command! cmp : if expand('%%c') == expand('%%f')
+
     command! cmp : if expand('%c') == expand('%f')
               \ |    echo expand('Comparing %%"c and %%"C:t ...')
+
               \ |    echo expand('Comparing %"c and %"C:t ...')
 
               \ |    cmpinternal %c %C
 
               \ |    cmpinternal %c %C
 
               \ | else
 
               \ | else
               \ |    echo expand('Comparing files: %%"f ...')
+
               \ |    echo expand('Comparing files: %"f ...')
 
               \ |    cmpinternal %f
 
               \ |    cmpinternal %f
 
               \ | endif
 
               \ | endif
Line 56: Line 56:
 
Explanation of key parts:
 
Explanation of key parts:
 
* <code>cmpinternal</code> — a trick to invoke external command. Calling <code>execute "!compare-cmd ... %S"</code> reparses command-line which leads to loosing results of command execution (they are overwritten by execution of <code>if-else-endif</code> block).
 
* <code>cmpinternal</code> — a trick to invoke external command. Calling <code>execute "!compare-cmd ... %S"</code> reparses command-line which leads to loosing results of command execution (they are overwritten by execution of <code>if-else-endif</code> block).
* Double percent sign in arguments for the <code>expand()</code> function (e.g. <code>expand('%%c')</code>) — macros are automatically expanded for user-defined commands, so <code>%</code> symbol should be escaped with itself for expansion to be performed by <code>expand()</code> function. It's important as otherwise unescaped quotes or other special characters in file names can break command syntax.
+
* <code>expand('%c') == expand('%f')</code> — check whether only one file is selected in current pane.
* <code>expand('%%c') == expand('%%f')</code> — check whether only one file is selected in current pane.
 
  
 
== Usage ==
 
== Usage ==

Please note that all contributions to Vifm Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Vifm:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)