1. 2016-12-23 - Highlight lines in vim; Tags: Highlight lines in vim

    Highlight lines in vim

    To highlight lines that exceed more than 80 characters, we can colorize the extraneous characters.

    Add to your ~/.vimrc

    highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9
    augroup vimrc_autocmds
        autocmd BufEnter,WinEnter * call matchadd('OverLength', '\%>80v.\+', -1)
    augroup END

    Every line which is longer than 80 characters will result in: Lines gt 80

  2. 2016-11-16 - Disable auto formatting in vim; Tags: Disable auto formatting in vim

    Disable auto formatting in vim

    vim has the behavior, if you paste a beginning line with comment, the following lines get also commented and indented. To disable this behavior switch to the paste mode.

    :set paste

    Paste your stuff. To deactivate the paste mode:

    :set nopaste
  3. 2015-10-07 - Delete lines in vi; Tags: Delete lines in vi

    Delete lines in vi

    vi or vim (vi improved) has powerful ways to delete line. This post gives some examples.

    The command for delete is :d. Delete current line


    Delete line 10


    Delete from start to line 30


    Delete from line 50 to end ($)


    Delete blank line (:g will execute a command on lines which match a regex. The regex is ‘blank line’)

  4. 2015-09-06 - Set vim as default editor; Tags: Set vim as default editor

    Set vim as default editor

    Using so many years vi or vim (vi improved) it is coming quite annoying that nano is the default editor. I understand that new users find it easier to use nano, but for all old school guys out there, this post describes how to set the vi or vim as default editor on deb based distributions like Debian, Ubuntu, etc.

    Install vim with

    sudo apt-get install vim

    After this invoke sudo update-alternatives --config editor and set the editor to vim. Example

    tan@cinhtau:~$ sudo update-alternatives --config editor
    There are 5 choices for the alternative editor (providing /usr/bin/editor).
      Selection    Path                Priority   Status
    * 0            /bin/nano            40        auto mode
      1            /bin/ed             -100       manual mode
      2            /bin/nano            40        manual mode
      3            /usr/bin/mcedit      25        manual mode
      4            /usr/bin/vim.basic   30        manual mode
      5            /usr/bin/vim.tiny    10        manual mode
    Press enter to keep the current choice[*], or type selection number: 4
    update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode