Screen Vim

(Almost) All you need to use Vim and GNU Screen daily for coding.

First I am going to left my minimalist .vimrc:

set expandtab tabstop=4 shiftwidth=4
; tab = 4 spaces
map <C-a> ma:%!perltidy<CR>`a
; To autoformat perl with Control + a
set timeoutlen=0
; So O takes less time to open a new line.
set wildmode=longest:full,list
; To have the menu completion similar to the bash/readline one.

And my .screenrc:

hardstatus alwayslastline
hardstatus string '%{= kg}[ %{r}%H %{g}][%+17= %{= kw}%?%-Lw%?%{+b m}(%{W}%n*%f %t%?(%u)%50>%?%{m})%{-b w}%?%+Lw%?%?%= %{g}%-21=][%{c} %D %M %d %{r}%c %{g}]'
screen calcurse
title calendar
screen bash
title development
screen bash
title testing

select 0
bind ^\ quit

This lines are pretty useful in the .bashrc in a GNU screen and Vim development environment:

set -o vi
perl -e 'exit 1 if `pidof screen` || `screen -ls` !~ /No Sockets found in/; exit !($ENV{TERM} = /xterm/)' && exec screen

Now once you restart your terminal if have installed calcurse, perl and screen you should be drop into calcurse where you can take note of events you should attend.

To go to the next window you can use C-a n. Voila, you are in a terminal.

With C-a [ you should enter into the GNU screen copy mode which will be very useful if you run long commands to be able to navigate by the output and of course copy content from it using vim like key bindings.

There is a main difference, in screen to yank you use enter or C-m.

To copy the content from the clipboard you use C-a ].

In copy mode you can go a Page up with C-b and a page down with C-f and a line up with k, a line down with j, right with l and left with h.

With / you may do a forward search with regex and with ? you may do a backwards search.

You can also go a word right with e and a complete word right with E and a word left with b and a complete word left with B.

You can jump to the start of the line with ^ and to the end with $.

If you know a little of vim this keybindings will be very familiar to you since are the ones Vim uses.

Let’s get into vim to test what it can do.

Open a random text file you have with Vim to test what I am going to explain.

vim <random_file>

You start in normal mode, if you press i you will enter in insert mode at the cursor position while if you press a you will enter insert mode one character right from your current position.

You can use C-x n to complete words based in other words present on the file, if you start in the beginning of the line you can complete the entire line using C-x l and if you have other buffers open with C-n you can complete from any opened buffer.

With Esc or C-[ you may return to the normal mode.

The navigation in Vim has pretty much the flavour of the Screen one, but thinked for editing.

With o you can create a new line just at the bottom of the one your cursor is in and start in insert mode in the beginning of that line, O does the same but creates the line at the top of the current one.

With gg you may go to the start of the file, with G you can go to the end of the file and with 5G you may get internet go to the fith line of the file, that applies to every number.

dd deletes the current line, de deletes until the end of the current word or the next word if you are not in a word, dE does the same, but including puntuation, db deletes the previous word and dB the same including puntuation. There are more combinations for example 2de deletes the next 2 words.

To copy in Vim you can use the y which is used pretty much like d or use the visual mode.

The visual mode is entered with v and when you use it you select what you want to paste navigating with the normal mode keybindings until you end selecting everything you need and then press y and everything gets copied into the vim clipboard, if you want to cut you use d.

You can now paste with p or P.

If you want to open a new file in a new tab you use :tabnew <new_file> in normal mode, it allows you to autocomplete the filename using tab.

To comment multiple lines at once in a language without comment blocks C-v can be handy, it allows you to insert the same text on a position on multiple lines at once, for example 0C-vjjjIHola mundo<esc> will insert Hola mundo in the beginning of the current line and in the two lines after the current one.

The * allows you to jump to the next time some word appears while # allows you to jump to the previous time.

There are lots of things you can learn still about vim, if you are seriously into using it as IDE take a look at :vimtutor.


By sergiotarxz

I am a software developer with high interest on free software.

Leave a Reply

Your email address will not be published. Required fields are marked *