vim – Paolo Redaelli https://monodes.com/predaelli A civil engineer with a longlife fondness for Software Libero Tue, 05 Dec 2023 08:52:36 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 91795679 Search and replace in multiple files using vim https://monodes.com/predaelli/2023/12/05/search-and-replace-in-multiple-files-using-vim/ https://monodes.com/predaelli/2023/12/05/search-and-replace-in-multiple-files-using-vim/#respond Tue, 05 Dec 2023 08:52:31 +0000 https://monodes.com/predaelli/?p=10992 Search and replace in multiple files using vim – (source Stack Overflow)

It is as simple as

Use:

:set aw
:argdo %s/happy999/happy111/g

The first line sets auto-write mode, so when you switch between files, vim will write the file if it has changed.

The second line does your global search and replace.

Note that it doesn’t use wq! since that exits. If you don’t want to use auto-write, then you could use:

:argdo %s/happy999/happy111/g | w

This avoids terminating vim at the end of editing the first file.

]]>
https://monodes.com/predaelli/2023/12/05/search-and-replace-in-multiple-files-using-vim/feed/ 0 10992
Why Vim is better than VSCode. https://monodes.com/predaelli/2022/03/18/why-vim-is-better-than-vscode/ https://monodes.com/predaelli/2022/03/18/why-vim-is-better-than-vscode/#respond Fri, 18 Mar 2022 21:08:00 +0000 https://monodes.com/predaelli/?p=9160
  • di’ —delete inside the ‘single quotes’.
  • da” — delete around the “double quotes”.
  • dit — delete inside the html tags.
  • ci[ — change inside the [square brackets].

From: Why Vim is better than VSCode. After Github was bought by Microsoft it… | by Sean | Feb, 2022 | Medium

Of course Sean is right. Master, my vim-fu is weak, I didn’t event knew all those techniques!

]]>
https://monodes.com/predaelli/2022/03/18/why-vim-is-better-than-vscode/feed/ 0 9160
5 lines I put in a blank .vimrc | Sword and Signals https://monodes.com/predaelli/2021/01/04/5-lines-i-put-in-a-blank-vimrc-sword-and-signals/ https://monodes.com/predaelli/2021/01/04/5-lines-i-put-in-a-blank-vimrc-sword-and-signals/#respond Mon, 04 Jan 2021 16:24:42 +0000 https://monodes.com/predaelli/?p=8003

TL;DR To make a default Vim installation more useful, type the following 5 lines into its .vimrc file:

set hlsearch " highlight all search results

set ignorecase " do case insensitive search
set incsearch " show incremental search results as you type

set number " display line number

set noswapfile " disable swap file

Source: 5 lines I put in a blank .vimrc | Sword and Signals

To make a default Vim installation more useful, type the following 5 lines into its .vimrc file:

set hls
set ic
set is
set nu
set noswf

Or if you prefer, copy and paste the spelled out and annotated version:

set hlsearch    " highlight all search results
set ignorecase  " do case insensitive search 
set incsearch   " show incremental search results as you type
set number      " display line number
set noswapfile  " disable swap file

For what it’s worth, the acronym for the 5 lines is HIINN.

Edit: Multiple people on HN have pointed out that the 5 lines can be combined into a single line like below. I didn’t know about this capability, but will definitely start doing this from now on:

set hls ic is nu noswf

Also, as mentioned below, this is for temporary environments where you read more than you edit. For your local set up, it’s better to take the time to properly maintain the config file and install plugins as needed.

Motivation

Vim is a powerful text editor for Unix/Linux, and I use it frequently to view and edit files. Unfortunately, Vim’s default configurations lack several important usability features compared to popular alternative text editors, such as VSCode.

The undesirable defaults are not an issue on my own computer, as I can take the time to configure them. However, often I’d find myself debugging or reading logs on near-fresh Linux installations (eg. virtual machines spun up to do integration testing), where Vim had not yet been configured.

So over time, I distilled the text editor features that I needed the most, and came up with the list above. To set it up, I would run vim ~/.vimrc, manually enter those 5 lines in whichever order that I remembered them, then quit and restart Vim to pick up the new configurations.

Discussion

The first 4 lines are straightforward – most popular modern text editors already come with all of them out of the box. The last one could be controversial, since swap file is designed to help users recover work. In practice though, I find it to be more in the way, due to the additional dialogue that pops up when opening a file that has an existing swap file. The recovery feature itself is also not useful to me, as I more often read logs rather than make edits in those cases.

The next time you find yourself in a similar situation, I recommend you to also try putting those 5 lines into the .vimrc. It could make your Vim experience just a bit bet

]]>
https://monodes.com/predaelli/2021/01/04/5-lines-i-put-in-a-blank-vimrc-sword-and-signals/feed/ 0 8003
How do I paste from PuTTY into Vim 8.0? https://monodes.com/predaelli/2019/01/22/5144/ https://monodes.com/predaelli/2019/01/22/5144/#respond Tue, 22 Jan 2019 18:46:35 +0000 https://monodes.com/predaelli/?p=5144 How do I paste from PuTTY into Vim 8.0?

Well, nice question, as I found it quite annoying that the usual right click on the mouse doesn’t work. In fact


Open a web browser, copy / paste some text from a website (eg. GitHub)
Use PuTTY 0.67 to SSH to a Linux VM (eg. Ubuntu 16 Xenial Xerus)
Open a file in Vim
Hit i to change into Insert mode
Right-click to paste the clipboard contents
Issue
Unfortunately, when I right-click in the PuTTY session, rather than pasting clipboard contents, what’s actually happening is that Vim is going from INSERT mode to (insert) VISUAL mode. I don’t think I’ve ever seen anything like this before.

Luckly it seems that there’s an easy workaround.


Adapt to it: With mouse mode turned on, the new way to paste is shift-right-click (at least in PuTTY)

]]>
https://monodes.com/predaelli/2019/01/22/5144/feed/ 0 5144
Vim lessons https://monodes.com/predaelli/2015/10/30/vim-lessons/ https://monodes.com/predaelli/2015/10/30/vim-lessons/#respond Fri, 30 Oct 2015 18:15:48 +0000 http://monodes.com/predaelli/?p=757 Oldies but goldies. I found those in the Download directory at work. I downloaded them in 2006, 9 years ago. Of course they are still ripe and useful, as vi/vim is a wonderful, time-resistant tool

Click to view slideshow.

 

 

]]>
https://monodes.com/predaelli/2015/10/30/vim-lessons/feed/ 0 757
https://monodes.com/predaelli/2015/06/29/501/ https://monodes.com/predaelli/2015/06/29/501/#respond Mon, 29 Jun 2015 18:20:10 +0000 http://monodes.com/predaelli/?p=501
Time to install a proper plugin manager for my modular, infinitely-ductile Vim: Vundle, the plug-in manager for Vim http://github.com/gmarik/vundle
]]>
https://monodes.com/predaelli/2015/06/29/501/feed/ 0 501