February 9th, 2025

Automating the Vim Workplace (2020)

The article outlines automation techniques for GVim to boost productivity, emphasizing personal configurations, efficient mode switching, clipboard commands, and running Git commands, while encouraging customization for individual workflows.

Read original articleLink Icon
Automating the Vim Workplace (2020)

The article discusses various automation techniques for enhancing productivity in GVim, a popular text editor among programmers. The author, Shrikant Sharat Kandula, shares personal insights and configurations that have improved his coding workflow over ten years of using GVim, particularly for Python, Markdown, and JavaScript. Key topics include switching between normal and insert modes efficiently, starting GVim maximized on Windows, saving all buffers without errors, and copying to the system clipboard with simplified commands. The author emphasizes the importance of tailoring Vim to individual work styles rather than relying solely on plugins. Other notable configurations include ensuring directories exist before saving files, switching between alternate buffers, and running Git commands directly within Vim. The article encourages readers to identify their own repetitive tasks and create custom mappings to streamline their workflow, ultimately transforming Vim into a more effective workplace.

- The author shares personal configurations to enhance productivity in GVim.

- Emphasis is placed on customizing Vim to fit individual work styles.

- Key automation techniques include efficient mode switching and simplified clipboard commands.

- The article encourages identifying repetitive tasks for potential automation.

- Running Git commands directly within Vim is highlighted as a productivity booster.

Link Icon 7 comments
By @toprerules - 3 months
Can't really say enough good things about Vim. I retired early as a staff software engineer because of the work I did using Vim. From hacking silly games in C in high school to now, I've always been able to use Vim and run circles around any "modern" text editor or IDE. I feel like I owe Vim as much public praise as I can give so others can reap the rewards like I did.

What really frustrates me is how little people seem to want to invest in their tools, or the outright lies they tell themselves about how much configuration they need to use Vim on a daily basis. My Vim config is 200 lines, and my last commit was 3 years ago. I've invested maybe a few days of my life into configuring Vim and I use it 8-16 hours a day.

Vim can do so much on its own. It has autocomplete, fuzzy finding, integration with build systems, file search, navigation using a directory browser, jump to symbol, parse compiler output to jump to bugs, support for gdb and breakpoints, a built in terminal, copy to and from the system clipboard, and with literally 8 lines of code you can get support for every linter, LSP, etc. known to man, fuzzy finding, and git integration that let's you use native git commands with seamless editor integration.

By @porridgeraisin - 3 months
> 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.

By @rgomez - 3 months
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>.
By @usrme - 3 months
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'.
By @wruza - 3 months
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
By @jmux - 3 months
> This articles looks an awful lot like a list of Vim tips

honestly, I like articles that are “a list of vim tips”. I can usually find some really good ideas that I didn’t consider. The tip about remapping copy to system clipboard to something easier than ‘“+y’ is genius, definitely using that.

By @iammrpayments - 3 months
The sort and reverse stuff is a bit overkill to me, maybe the guy writing tables?