Vim can run shell commands as filters over selections as well.
Although vim does provide its own `:sort`, you can also sort the current selection like
v{motion}!sort
Which uses the external sort command (coreutils)
For reversing,
v{motion}!tac
Which uses `tac` to reverse the order of the lines.
This general concept is quite useful in many other ways, since it is quite universal - selection goes to stdin of arbitrary program, stdout of that program replaces selection.
For example, if you want to quickly test a function that takes a json string, and you're in a language where instantiating good mock objects and serialising it takes quite a bit of code, you can quickly make a mock by writing JS code within the string quotes and have the code console.log json and then `vi'!node` will replace it there.
qazxcvbnm 3 hours ago [-]
This is very powerful. Unfortunately, as an Ex command, `!` only works on full lines. One can of course also teach vim to operate `!` over any motion (or visual selection), whether it is part of a line, a full line, or a block https://vi.stackexchange.com/a/46304/48750.
PhilipRoman 8 minutes ago [-]
It always infuriates me how well nano handles this out of the box as opposed to vim. I don't see any reason why this shouldn't be the default. If you're in visual mode and want the whole-line behavior, it takes just 1 extra key press (V).
billfruit 5 hours ago [-]
What if those external utilities are not available? Which might very well be the case if you run Vim on Windows.
It is better to have atleast some fall back capabilities(for searching across files, searching within files, sorting etc) build in.
ttyprintk 47 minutes ago [-]
I don’t think that effort is necessary.
The author likely has git, which provides a userland. And she/he is talking about gvim.exe, so is not restricted in what she/he can choose to install, and by now, might be using nvim-qt.exe.
Edit: just realized it always posed itself as a “building platform”, lol. It really is a full-blown GNU system that works on windows. As in GNU/Linux, but there’s no linux kernel. All the /usr/bin tools are there, including pacman as a package manager (from Arch). You can install virtually everything from there.
billfruit 5 hours ago [-]
Now you need a whole userland to get basic functionality of the editor. Who will vett the correctness and suitability and efficiency of the 3rd party user-land?
Notwithstanding that the third party userland is possibly not necessarily, since the windows userland most likely has all the features needed for Vim to make these functionalities work.
Since the editor is intended to be a multi-plaform product, it is better if atleast a windows userland based mechanism could be provided on windows platform, if the mechanisms could not be achieved through an inbuilt platform-agnostic manner.
What if you need a "portable" ( in the windows sense of the term, it means that the program can be used without need for an installation process) version of the editor?
I think it all is a huge time sink on the end user, who would instead get some usefull progress done on their projects.
wruza 4 hours ago [-]
Agreed, ideally a multi-platform editor should include all the features an OS might have, or at least use a compatibility layer that equalizes all functionality and paradigms over all supported platforms.
wruza 5 hours ago [-]
I use `:'<,'>!html-to-m` to convert arbitrary html snippets into mithril.js m() hyperscript.
rgomez 5 hours ago [-]
The Vim configuration is something deeply personal, but I'd recommend as a wise choice always explore first the default settings because assuming those in your workflow gives an huge advantage using any new unconfigured vim environment eg to get out of any of the edit modes <C-c> works by default and is a great choice.
To use CUA alike shortcuts there's already:
```
source $VIMRUNTIME/mswin.vim
```
And finally, is also a good idea to get used to use <Leader> as a prefix for your own shortcuts, in my case I use the space bar as <Leader>.
ulbu 11 minutes ago [-]
note that exiting a mode with <c-c> prevents autocmd events from firing.
windward 5 hours ago [-]
Strong agree. Failure to grok what comes with Vim often results in a permenent Nerdtree pane.
kombine 2 hours ago [-]
I've been using Neovim for about 6 months now but as a former VS Code user I was mostly investing into the various plugins. Fairly recently I started digging deeper into vim's built-in features such as vimgrep and quickfix and they are incredibly powerful. It will take me probably another year to learn to use all these tools effectively.
ttyprintk 35 minutes ago [-]
In its contrib directory, git comes with jump. `git jump grep` will load grep results into quickfix.
wruza 3 hours ago [-]
I often use the :wa command to save all my open buffers. But it has the nasty habit of throwing an error when it’s not able to save all buffers
nmap <F2> :silent! wa<CR>
Copy to System Clipboard
if has('unix')
set clipboard=unnamedplus
else
set clipboard=unnamed
endif
Also, to type word under cursor into command line:
cmap <M-w> <C-R>=expand("<cword>")<CR>
Paste without replacing clipboard (for the lazy):
vnoremap p P
usrme 4 hours ago [-]
I had no idea Vim had a terminal mode with ':ter|:terminal'! Definitely something I'll look into to improve my own Vim + Git workflow. I've usually just moved Vim to the background with Ctrl+Z, done my committing, and then moved Vim back to the foreground with 'fg'.
kmarc 1 hours ago [-]
I found that once you use tmux+vim, the built in terminal is not much of use, it's even slowing me down
lelanthran 3 hours ago [-]
I tend to use it as `:vert terminal`, then start up mysql/psql in that terminal, and use <C-c> in the other pane to send SQL statements to the 'terminal'.
Works better than MySQL workbench and other things like that, for me, because it works in a terminal over ssh too.
iammrpayments 4 hours ago [-]
The sort and reverse stuff is a bit overkill to me, maybe the guy writing tables?
Vim can run shell commands as filters over selections as well.
Although vim does provide its own `:sort`, you can also sort the current selection like
Which uses the external sort command (coreutils)For reversing,
Which uses `tac` to reverse the order of the lines.This general concept is quite useful in many other ways, since it is quite universal - selection goes to stdin of arbitrary program, stdout of that program replaces selection.
For example, if you want to quickly test a function that takes a json string, and you're in a language where instantiating good mock objects and serialising it takes quite a bit of code, you can quickly make a mock by writing JS code within the string quotes and have the code console.log json and then `vi'!node` will replace it there.
It is better to have atleast some fall back capabilities(for searching across files, searching within files, sorting etc) build in.
The author likely has git, which provides a userland. And she/he is talking about gvim.exe, so is not restricted in what she/he can choose to install, and by now, might be using nvim-qt.exe.
Edit: just realized it always posed itself as a “building platform”, lol. It really is a full-blown GNU system that works on windows. As in GNU/Linux, but there’s no linux kernel. All the /usr/bin tools are there, including pacman as a package manager (from Arch). You can install virtually everything from there.
Notwithstanding that the third party userland is possibly not necessarily, since the windows userland most likely has all the features needed for Vim to make these functionalities work.
Since the editor is intended to be a multi-plaform product, it is better if atleast a windows userland based mechanism could be provided on windows platform, if the mechanisms could not be achieved through an inbuilt platform-agnostic manner.
What if you need a "portable" ( in the windows sense of the term, it means that the program can be used without need for an installation process) version of the editor?
I think it all is a huge time sink on the end user, who would instead get some usefull progress done on their projects.
Works better than MySQL workbench and other things like that, for me, because it works in a terminal over ssh too.