linux-unix

recent posts related to linux and unix

An example vim vimrc configuration file

vim/vimrc FAQ: Can you share an example vim vimrc configuration file?

Sure. I don't use vim for programming much these days, so I don't have the vimrc configuration commands I used to use with various programming languages, but I'll be glad to share my vimrc configuration file that I use every day, along with a few extra lines to demonstrate some of the vim configuration possibilities.

Example vim vimrc configuration file

Here's an example vimrc file:

Convert vi/vim tabs to spaces

vim tabs/spaces FAQ: How do I convert vi/vim tabs to spaces?

You can convert tabs to spaces in vim using the usual vim search and replace command. Specifically, this vim "tabs to spaces" command is all you need:

:1,$s/\t/  /g

In short, this command can be read like this:

vim tip: How to configure vim autoindent

vim autoindent FAQ: How do I configure vim to automatically indent newlines? That is, if my current line is indented three spaces, and I hit [enter], I want the next line to autmatically be indented three spaces as well.

To configure vim autoindent, just use this vim command:

vim backup files - how to move

vim FAQ: How do I move vim backup files to another directory? (Those files that end with the "~" character.)

To move vim backup files to another directory, just use commands like these in your "vimrc" configuration file:

vim delete blank lines command

vim FAQ: How do I delete blank lines in vim?

To delete blank lines in vim (empty lines), use this vim last line mode command:

:g/^$/d

Here's a brief explanation of how this "vim delete blank lines" command works:

The vim delete all lines command

vim FAQ: How do I delete all lines in the current text file in vim?

To delete all lines in vim, use this command:

:1,$d

This "vim delete all lines" command can be read like this:

  • Beginning at line 1, and
  • Ending at the last line in the file (represented by the '$'),
  • Delete each line.

I hope this vim "delete all lines" command example has been helpful. If you need any more details/discussion just leave a command below.

The vim delete line command

vim delete FAQ: How do I delete a line in vim? (Also, how do I delete multiple lines in vim?)

To delete the current line in your vim editor, use this vim delete line command:

dd

You can use this same command to delete multiple lines in vim. Just precede the command by the number of lines you want to delete. For instance, to delete five lines in vim, use this command:

Shell script counter FAQ - How to increment a counter in a shell script

Unix/Linux shell script FAQ: Can you share a simple Linux shell script that shows how to count, i.e., a shell script that increments a counter in a for loop or while loop?

Sure, I just needed to increment a while loop counter myself, so I thought I'd share my example shell script code here.

Use vimdiff to see the difference between multiple files

I was just reminded of the Unix/Linux vimdiff command that lets you visually see the differences between multiple files. I normally just use vimdiff to look at the differences between two files, but I know it can also work with three files.

A quick vimdiff example with two files

To demonstrate how vimdiff works, here's a quick example. Suppose you have one file named getty1 that has these contents:

A long Unix "file management" tutorial page

If you happen to be looking for a collection of Unix "file management" commands, look no further than the Unix/Linux file management page of my "Introduction to Unix" tutorial.

Syndicate content