Tag Archives: vim

vim: multiple buffers

In order to work with several view ports of the same file in the same Vim window, type: :sp:sp You may also open another file in the same window. To do so issue the command:: :sp filename :sp filename To … Continue reading

Posted in Linux | Tagged | Leave a comment

vim: create function to remove white spaces

In the .vimrc file, add the following lines ( here ^M is a special character for the return carriage created using CTRL+V): #remove tabs function removeM() %s/^M// :endfunction   function removeWhiteSpace() %s/^ \+ $// %s/^ $// %s/ \+$// %s/ $// … Continue reading

Posted in Linux | Tagged | Leave a comment

VIM : copy and paste reformats the text with lots of spaces

When I paste a piece of code or text from a copy (or the clipboard), lots of extra spaces are added at the start of each new line. The solution is to turn off the autoindent: :set paste:set paste After … Continue reading

Posted in Linux | Tagged | 1 Comment

VIM: switch all text to lower case

You can change the case of a character by typing ~ , however, if you want to change all text to the same case (let us say lower case here), then you should enter the visual mode. Go to the … Continue reading

Posted in Linux | Tagged | Leave a comment

vim usage: wrapping, spelling, completion, indentation, …

code folding To fold a number of lines (5 for example) press zf5j. To fold code within curly brackets use za The folded lines will be replaced in the buffer with a line that looks like: +—– 5 lines: }—– … Continue reading

Posted in Linux | Tagged | Leave a comment

vim: replace tabs by spaces

In the vim editor, the default behaviour of the tab key is to print a tab … not surprising. When coding, you may prefer tab to be replaced by spaces (because this is your coding style for instance). This feature … Continue reading

Posted in Linux | Tagged | Leave a comment

vim: replace the windows ^M character under Linux

Within VIM, there is a way to replace all the return carriage from Windows (that appear as ^M) by replacing them with the Linux version: % s/^M/\r/g% s/^M/\r/g When \r stands for the return carriage in Linux (not \n as … Continue reading

Posted in Computer Science | Tagged | Leave a comment

VIM: pasting text from GUI

In VIM, when you copy and paste text from a GUI application (e.g., firefox), VIM may insert a lot of extra white spaces by indenting the code automatically. The rendering is sometimes completely wrong, or you just do not want … Continue reading

Posted in Linux | Tagged | Leave a comment