Difference between revisions of "Vi, Vim, Vscode editors"

From Ever changing code
Jump to navigation Jump to search
Line 115: Line 115:
  call vundle#begin()
  call vundle#begin()
  " alternatively, pass a path where Vundle should install plugins
  " alternatively, pass a path where Vundle should install plugins
  "call vundle#begin('~/some/path/here')
  " call vundle#begin('~/some/path/here')
   
   
  " let Vundle manage Vundle, required
  " let Vundle manage Vundle, required
Line 125: Line 125:
  Plugin 'scrooloose/syntastic'
  Plugin 'scrooloose/syntastic'
  Plugin 'glench/vim-jinja2-syntax'
  Plugin 'glench/vim-jinja2-syntax'
Plugin 'scrooloose/nerdtree'      " usage :NERDTree then :?
   
   
  " All of your Plugins must be added before the following line
  " All of your Plugins must be added before the following line

Revision as of 14:22, 16 September 2017

VI or VIM

This section describes both editors however these days vi command is an alias to vim. Therefore bear in mind although all have been tested the test itself was made on VIM.

delete till space
d, t, space   - d(elete) t(ill) space, but you can replace space with any printable character
drop to bash
:!bash   or   :!sh
edit other file
:e file.txt    #autocomplite works
redirect command STDOUT to the current edited file in the cursor position
:r!dir
show line number
:set number    or  :set nu
find and replace in VI called substitute (ref. sed)
:%s/wily/trusty/g    #substitute all wily with trusty in all document
:s/wily/trusty/g     #substitute only in the current line
find and print only lines that match the search
:g/string-to-search/p       #   :g -global search,  /p -print out on a screen
Undo and redo
 u -undo last change
 Ctrl-R -redo changes which were undone (undo the undos). '.' to repeat a previous change, at the current cursor position
Visual mode
v -visual selection using arrows and navigation keys
^v -visual block selection, y-yank, d-delete, i-insert still work
Multi-line insert in visual block selection

Press I to start a special form of insert mode, then type the wanted text (s:). When you press Esc to exit from insert mode, the text will be inserted in the same position on each of the lines affected by the visual block selection.

Insert comments sign # at the begging each line between 10 and 12th line
:set number
:10,12s/^/#
Wrap text
:set wrap    or    :set nowrap

Show current file name

Ctrl+g    -shows the current file name
1, Ctrl+g -shows relative to vim full path. Press '1' then Ctrl+g

VIM only

Split windows, multiple windows
:split   or   :vsplit
C^w, c -close current window
C^w, C^w - switch between windows

Change colour of dark blue comments

You can do it manually with the command below, where ABCDEF is an appropriate colour hex code.

:hi Comment guifg=#ABCDEF

To make it permanent, add these lines to your ~/.vimrc file (using green as an example):

syntax on
:highlight Comment ctermfg=green

Oneliner

echo "syntax on" >> ~/.vimrc && echo ":highlight Comment ctermfg=green" >> ~/.vimrc

Show special characters

:set list    #and to unset ->   :set nolist

Vimdiff - diff compare

Compare multiple files using Screen program widows like

vimdiff -d file1 file2

Comparison tools

user@server1:/etc/cups# sdiff cupsd.conf -RE cupsd.conf     #side-by-side merge of file differences
LogLevel debug                                                  LogLevel debug
MaxLogSize 0                                                    MaxLogSize 0
# Allow remote access                                           # Allow remote access
Port 631                                                        Port 631
Listen /var/run/cups/cups.sock                                  Listen /var/run/cups/cups.sock

Another tools:

  • colourdiff - this takes the standard diff options like -y for side-by-side compare

Vim plugins

  • VimAwesome
    • FUGITIVE.VIM - Git integration
    • Syntastic - syntax and style checker that uses other plugins
    • flake8 - Python syntax checker
    • jedi-vim - Python autocompletion, use ctr+space

Vundle - plugin manager

Follow these steps to installe it Vundle Vim bundle/plugins manager. Just remember to comment out plugin examples otherwise it will not work. As an alternative you can use my .vimrc configuration file.

Use following commands inside Vim

  • :PluginList - lists configured plugins
  • :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
  • :PluginSearch foo - searches for foo; append `!` to refresh local cache
  • :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal

Read more how to use Vim as Python IDE integrated development environment

my .vimrc

This is my Vim configuration file that uses Vundle as a package manager and has Python syntax autocomplete, checker and style

vim ~/.vimrc
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialise
set rtp+=~/.vim/bundle/Vundle.vim

" Syntastic setting - basic settings for beginners 
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
" call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Keep Plugin commands between vundle#begin/end.
Plugin 'tpope/vim-fugitive'
Plugin 'davidhalter/jedi-vim'
Plugin 'scrooloose/syntastic'
Plugin 'glench/vim-jinja2-syntax'
Plugin 'scrooloose/nerdtree'      " usage :NERDTree then :?

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

References