https://wiki.vifm.info/index.php?title=Special:NewPages&feed=atom&hidebots=1&hideredirs=1&limit=50&offset=&namespace=0&username=&tagfilter=&size-mode=max&size=0Vifm Wiki - New pages [en]2024-03-29T11:28:34ZFrom Vifm WikiMediaWiki 1.35.1https://wiki.vifm.info/index.php/Creating_directories_and_files_with_a_single_commandCreating directories and files with a single command2024-01-07T16:43:57Z<p>Mahor1221: Created page with "Use this command to create directories when the last character entered is "/", and create files otherwise: <source lang="vim"> command create : \| let $last_char = expand(sy..."</p>
<hr />
<div>Use this command to create directories when the last character entered is "/", and create files otherwise:<br />
<br />
<source lang="vim"><br />
command create :<br />
\| let $last_char = expand(system("str=\"%a\"; echo \"${str: -1}\""))<br />
\| if $last_char == "/"<br />
\| mkdir "%a"<br />
\| else<br />
\| touch "%a"<br />
\| endif<br />
<br />
nnoremap a :create<space><br />
</source><br />
<br />
<br />
To create a file named <code>test_file</code>:<br />
<br />
<source lang="vim"><br />
:create test_file<br />
</source><br />
<br />
To create a directory named <code>test_dir</code>:<br />
<br />
<source lang="vim"><br />
:create test_dir/<br />
</source></div>Mahor1221https://wiki.vifm.info/index.php/Sort_dotfiles/dotdirs_separately_from_other_files/directoriesSort dotfiles/dotdirs separately from other files/directories2023-12-09T18:36:35Z<p>Noodlebrains: Created page with "By (ab)using the <code>sortgroups</code> option, you can split all the listed files into two groups - one containing items with a <code>.</code> prefix, and one containing all..."</p>
<hr />
<div>By (ab)using the <code>sortgroups</code> option, you can split all the listed files into two groups - one containing items with a <code>.</code> prefix, and one containing all the other items.<br />
<source lang="vim"><br />
" Show dotfiles/dotdirs in the first place<br />
set dotfiles<br />
<br />
set sortgroups='(|\.).*'<br />
<br />
set sort=+groups,+dir,+name<br />
</source><br />
<br />
=== Explanation ===<br />
<br />
The <code>sortgroups</code> option is used to select parts of each filename via regex group matches, and use those parts as sorting keys. <br />
<br />
In the regex <code>(|\.).*</code>, the group <code>(|\.)</code> matches either an empty string, or the literal <code>.</code> character; the <code>.*</code> part matches the rest of the filename. So our group match is either an empty string, or a single <code>.</code> character; the filenames are then sorted into two groups based on which one it is. <br />
<br />
We then set the <code>sort</code> option. Vifm will first sort the files according to the two groups generated by <code>sortgroups</code>, then sort directories above files, then sort alphabetically.<br />
<br />
Ultimately, we get the following order - directories, files, dotdirs, dotfiles. By changing the sort order of any of the options (changing <code>+</code> to <code>-</code> in the <code>sort</code> option), the ordering can be varied while keeping the grouping.</div>Noodlebrains