Posts Tagged ‘vim’

edit crontab with emacs

March 8, 2015 Leave a comment

You can edit your crontab file with “crontab -e“. It worked fine as long as I used vim. However, when I switched to emacs and set the EDITOR environment variable to point to emacs, I couldn’t edit my crontab file normally. Emacs is started in the background and somehow it caused problems.

I made a script for editing my crontab file. This script sets EDITOR back to vim, thus “crontab -e” opens vim. Here is the script:

#!/usr/bin/env bash

# crontab_e

crontab -e

I call this script “crontab_e”, so it’s easy to remember its name.

Categories: bash Tags: , ,

sending vim to background then bringing it back

December 13, 2013 Leave a comment

You are working in vim and you want to switch quickly to the terminal to do something. Then you want to get back to vim and continue editing where you left off.

Simply do the same you do with other programs:

  • CTRL+Z: suspends vim and you find yourself in the terminal
  • do your terminal business
  • fg: brings you back to vim
Categories: Uncategorized Tags: ,

sachet: customize your vim through a web interface

December 13, 2013 Leave a comment

Vim is a very nice text editor but for its full potential, you need a good config. file :) If you are new to vim, you can start with sachet. Sachet is a web application where you select the features you want in your vim editor and it prepares the config. file for you that you can download and install. Simple!

sachet allows you to handcraft your VIM development environment. By allowing you to select features and functionality that you are comfortable with, sachet generates you a small package with the appropriate configuration files, plugins, and theme so you can leverage the potential of your VIM editor.” (source)

Later on you can customize your .vimrc file.

Categories: Uncategorized Tags: ,

Learn Vimscript

December 13, 2013 Leave a comment

I don’t want to encourage anyone, but if you are interested in customizing your vim editor, check out Learn Vimscript the Hard Way.

The book is divided roughly into three sections:

  • The first covers basic Vim commands that you can use in your ~/.vimrc file to customize Vim quickly and easily.
  • The second looks more deeply at Vimscript as a programming language, covering things like variables, comparisons, and functions.
  • The third walks through the creation of a sample plugin intended for distribution to other Vim users.
Categories: Uncategorized Tags: ,

Text file encoding

March 23, 2011 2 comments

Detect the encoding of a text file:

$ file all.txt 
all.txt: ISO-8859 text

Get more verbosity:

$ file --mime all.txt 
all.txt: text/plain; charset=iso-8859-1


$ file -i all.txt 
all.txt: text/plain; charset=iso-8859-1

Change the encoding of a text file:

iconv --from-code=UTF-8 --to-code=ISO-8859-2 file.txt >tmp.txt

This latter tip is from here.

Convert from UTF-16LE to UTF-8:

iconv -f UTF-16LE -t UTF-8 infile -o outfile

Update (20110918)
You can also use “chardet” for detecting charcter encoding. Usage:

$ chardet test.txt 
test.txt: utf-8 (confidence: 0.99)

Update (20140106)
vim has also an excellent detector. If you open a file in vim and it looks good, check out what encoding is being used by vim:

:set fileencoding

Update (20170116)
I wrote a Python script for this task called ““. See the blog post here.

My .vimrc settings

November 19, 2010 Leave a comment

Here is my VIM config file: download. I didn’t paste it here since it’s quite long and contains some special characters. After download you will have to rename it; in the header of the file it is explained.


Categories: ubuntu Tags: , , ,