Fix auto-indentation in Vim

Here are a few VIM commands to type within the editor to check the current settings and enable what is missing to make VIM auto-indent your file.

:filetype

If disabled, the output will be :

filetype detection:ON plugin:ON indent:OFF

To enable it :

:filetype indent on

To list all the indentations file available (for any programming language for instance)

:e $VIMRUNTIME/indent

If you find one that matches the programming language that you are typing in your editor, to indent your code :

gg=G

To make it permanent, add the following line in your .vimrc file :

filetype indent on

Advertisements

Python auto-completion in Vim with python-jedi on Ubuntu 19.04

python-jedi is a plugin available for Vim that features auto-completion for the Python programming language.
It is available as an Ubuntu package :


apt install vim-python-jedi

To enable it as a user :


vim-addons install python-jedi

or


vam install python-jedi

To start using it in Vim, the keyboard shortcut CTRL+Space is a good start for auto-completing.

Further readings :

jedi autocompletion library for VIM

VIM for development on Stackabuse

Windows PowerShell Syntax Plugin set up in gVim

Windows PowerShell Syntax Plugin provides Syntax coloring, indenting and filetype detection for Windows PowerShell.

It is available at :

http://www.vim.org/scripts/script.php?script_id=1327

http://github.com/PProvost/vim-ps1

If you use Pathogen, just extract into your bundle folder.

If not, just set up Pathogen as follows below :

https://github.com/tpope/vim-pathogen

Additional actions to make it work on Windows 7 :

cd C:\Program Files (x86)\Vim\vimfiles
mkdir autoload
mkdir bundle

Install pathogen.vim in C:\Program Files (x86)\Vim\vimfiles\autoload

To enable Pathogen, add this to your gvimrc :

execute pathogen#infect()
syntax on
filetype plugin indent on

On Windows 7/10, the gvimrc file must be named as _gvimrc and located in one of the folders :

$HOME/_gvimrc
$HOME/vimfiles/gvimrc
$VIM/_gvimrc

$HOME points to your home directory in Windows 7 and $VIM points to your directory where Vim/gVim have been installed.

The personal initialization files are searched in the order specified above
and only the first one that is found is read.

http://vimhelp.appspot.com/gui.txt.html#gvimrc

This plugin is now enabled. Enjoy !

Auto-closing HTML tags in Vim on Debian Buster

Debian provides deb packages for Vim and Vim scripts. Vim scripts are a set of addons to vim to automate repetitive tasks or adding new functionalities to the Vim editor.

This addon, closetag.vim, will be installed and enabled and ready for use when editing an HTML file.

Debian provide a central way to manage Vim addons, vim-addons-manager, system-wide or a per-user configuration.
To install it :

apt install vim-addon-manager vim-scripts

To enable it just for you :

vim-addons install closetag

A local copy of closetag.vim is created in ~/.vim/macros

To enable it in your Vim editor :

:let g:closetag_html_style=1
:source ~/.vim/macros/closetag.vim

The auto-closing function is available in insert mode by typing Ctrl-_

More infos :

https://github.com/vim-scripts/closetag.vim
http://www.vim.org/scripts/script.php?script_id=13

Debian Packaging Policy for Vim

Inserting a bunch of lines for any new file in vim

To avoid typing the same lines each time you open up a new file in vim, here is a little trick to do it. Let’s have a try with a simple perl template.

fool@localhost:~$ mkdir .vim

fool@localhost:.vim$cat > perl.template <<EOF
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
EOF

Now, in your vim’s configuration file :

fool@localhost:~$ cat >> .vimrc <<EOF
au BufNewFile *.pl 0r ~/.vim/perl.template
EOF

Anytime you create a new perl script with vim, you will find a few lines already it. Hope it helps !