Category: Editors

How to indent a source code block in VIM?

VIM

VIM is a powerful editor with a rich ecosystem and many many features it's used by many users around the world in their daily administrations and development tasks.

This tip is very useful if you want to use VIM (mainly) as your source code editor.

Geany a lightweight text editor

Geany is a powerful, stable and lightweight text editor that has a modular architecture which allows to extend the basic functionality by selecting a set of plugins. It's developed under GPL v2 license. Geany requires few space on hard disk, has few dependencies (not depends on KDE or GNOME libs)

VIM case sentive / insensitive search

VIM

How to make VIM insensitive to uppercase and lowercase letters in a search?

Vim by default is case sensitive but this behavior can be modified through the options: ignorecase, ic, noignorecase, noic or adding c to the search pattern

Note: If you are in insert mode you must press Esc to switch to Normal mode

Case insentive temporarily

:set ignorecase

O

:set ic

Case sensitive

:set noignorecase

O

:set noic

Using c

/category\c

Find all words that contain category regardless of uppercase and lowercase letters

Case insensitive permanently

Edit the file /etc/vimrc (global) or ~/.vimrc (at the level of user) and add:

set ic

O

set ignorecase

Further reading

  • man vim
  • :help 'ignorecase', :help ignorecase

Nano: lightweight and flexible text editor

Nano, improved version of Pico, is a friendly, lightweight and flexible text editor, it is ideal to make simple edits. Nano is a modeless text editor (no need to run any command or key combination to start editing the selected file). Once started it shows in the first line: the current version, the name of the file being edited and whether it has been modified or not; then the file in question, in the third line from the bottom up the important messages and in the last 2 lines the most common shortcuts, see figure. The main keys for Nano are: Ctrl (^) and Esc (M), ie with Esc or Ctrl and another key combination we can execute an action. Within its essential features we can mention:

  • Clean interface
  • Low learning curve
  • Internationalization
  • Syntax highlighting for C, C++, Python, Perl, Ruby, HTML, TeX and other
  • Searches / replacement by keywords or regular expressions
  • Forward / back one screen
  • File Explorer
  • Edit multiple files
  • Mouse support
  • Help integrated into the editor
[caption id="attachment_2937" align="aligncenter" width="911"]nano flexible and lightweight text editor nano flexible and lightweight text editor[/caption]

Edition

General syntax

nano [OPCIONES] [+LINE,COLUMN] file

Open the apache2.conf file and go to 20 line, column 23

nano +20,23 /etc/apache2/apache2.conf 

Edit file1.txt

nano file1.txt

Make relevant modifications and

Save the changes

Ctrl o

Nano it will request confirmation on the file that you want to modify, press:

Enter

Copy the current line and store it in the buffer

Esc 6

Cut the current line and store it in the buffer

Ctrl k

Paste what is in the buffer

Ctrl u

Use the mouse to select various lines

Esc a

To copy / cut / paste the selected lines use

Esc 6/Ctrl k/Ctrl u

respectively

Movement

Go to the first line of the file

Esc \

Go to the last line of the file

Esc /

Go to line 10, column 20

Esc g

Nano will request the line and column number to which you want to go, type:

10,20

Go to the beginning of the current line

Ctrl a

Go to the end of the current line

Ctrl e

Moving to matching braces

Esc ]

Advance one screen

Ctrl v

Go back one screen

Ctrl y

Advanced options

Search by keywords

Ctrl w

Search using regular expressions

Ctrl w Esc r

Repeat last search

Esc w

Enable / disable the mouse support

Esc m

Launch integrated help

Ctrl g

Further reading

Copy a range of lines from a file to another

VIM

To copy a range of lines from a file to another:

1. Open the file in VIM

$ vim fich 

2. Execute the following command within the editor (press Esc while in insert mode)

:num-sup-line,num-inf-linew! file-name

Example:

:10,50w! file-name

Further reading

- help write

VIM a powerful and flexible text editor

VIM

The first version was released in November 1991, for the Amiga platform. A year later came the first version for UNIX. Its author, Bram Moolenar, was inspired by VI editor, very popular among the UNIX followers. Vim inherits the features of VI and adds new ones, being a 99% compatible with its predecessor when it starts in compatible mode.

Its development model under a GPL compatible license and the new built-in features made VIM gain a lot of followers very quickly becoming one of the most popular editors. Currently the most GNU/Linux distributions incorporate it as the text editor by default.

Basic modes

  • Normal. Using key combinations you can perform actions such as: copy and delete words, groups of words, lines, go to start, at the end of the file, etc. It is the default mode when you start the editor
  • Insert. Allows you to edit the file on which we are working
  • Command-line, Cmdline. Allows to execute complex commands such as: searches by key words, searches using regular expressions, read an external file, open an external file, etc.
  • Visual. Allows you to select a block of text in a simple and flexible way and execute operations such as: delete, copy, change to upper case or to lower case as applicable, space to the right, to the left, etc.
  • Select. Similar to selection mode implemented by OpenOffice/LibreOffice by typing a printable character delete the selection and starts the insert mode
  • Ex. Similar to the Cmdline mode, but after running a command mode remains
Change from one mode to another
From / toNormalInsertCmdlineVisualSelectEx
Normali, Shift i:, /, ?, !v, Shift v, Ctrl vgh, g Shift h, g Ctrl hShift q
InsertEsc--------
CmdlineEnter, Esc, Ctrl c:start------
VisualEsc, vc, Shift c:Ctrl g--
Select***--Ctrl o, Ctrl g--
Ex:vi--------

* You can change from Select selection to Normal mode pressing one of the buttons ← → ↑ ↓
** You can enter in insert mode holding any printable character

Relevant characteristics

  • Highlighting of syntax for more than 200 programming languages (Java, Perl, PHP, Python, Bash, etc.)
  • Integration with a large number of compilers, interpreters and debuggers (GCC, MANX AZTEC C, TEX COMPILER, other)
  • Autocomplete
  • Search by key words
  • Allows to execute operations (searches, substitutions of words) based on regular expressions
  • Undo and redo
  • Command completion (similar to bash)
  • Horizontal, vertical, or multiple windows which allow you to edit various file at the same time
  • Flexible architecture that allows the integration of additional functionality through scripts developed by contributors
  • Online documentation and integrated to the editor

Vim also has a user interface (gVim), which may be more friendly for beginners, however veterans administrators prefer use it in text mode

The latest stable version is the 7.4.x Also the binary is available for the following platforms: UNIX, MS-DOS / MS-Windows, Macintosh, Amiga, OS/2, Cygwin, other.

Further reading

Schulz, Kim. Hacking Vim
http://en.wikipedia.org/wiki/Vim