Skip to content(if available)orjump to list(if available)

Automating the Vim Workplace (2020)

Automating the Vim Workplace (2020)

15 comments

·February 9, 2025

porridgeraisin

> sorting and reversing over motion

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

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.

billfruit

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.

wruza

https://www.msys2.org/

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

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

I use `:'<,'>!html-to-m` to convert arbitrary html snippets into mithril.js m() hyperscript.

rgomez

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>.

windward

Strong agree. Failure to grok what comes with Vim often results in a permenent Nerdtree pane.

kombine

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.

wruza

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

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

I found that once you use tmux+vim, the built in terminal is not much of use, it's even slowing me down

lelanthran

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

The sort and reverse stuff is a bit overkill to me, maybe the guy writing tables?