VIM #9 ~ TUTORIALSsteemCreated with Sketch.

in #linux6 years ago (edited)

VIM

Published with SteemPeak

$ ./configure
$ make
# make install

ScreenshotScreenshot by Willi Glenz

SUMMARY

    VIM ~ A PROGRAMMER'S EDITOR

008 first-steps                                                         v1 19-06
009 tutorials                                                           v1 19-06 new
005 modes                                                               v1 19-06
001 movements                                                           v2 19-06
004 buffers                                                             v1 19-06
006 macros                                                              v1 19-06 
003 cheat-sheet                                                         v2 19-06 
002 documentation                                                       v2 19-06 

007 ~/.vimrc                                                            v1 19-06

:h user-manual ....................... <ctrl-w_> ................... User manual
:h reference  ........................ <ctrl-w_> .............. Reference manual



#009

009 TUTORIALS
• TutorialsPoint    : tutorialspoint.com/vim/index.htm
• Bram Moolenaar    : moolenaar.net/habits.html
• Ben McCormick I   : benmccormick.org/2014/06/30/learning-vim-in-2014-the-basics
• Ben McCormick II  : benmccormick.org/2014/07/02/learning-vim-in-2014-vim-as-language


008 FIRST-STEPS
01 INSTALL VIM

   # apt-get install vim gvim vim-doc vim-scripts ...... DEBIAN     
   # pacman -S vim ..................................... ARCH
   $ dpkg -L vim-doc
   # update-alternatives --config editor
   $ vim --version | less

02 REMAP <CAPS LOCK> TO <ESC>

   • GNOME-TWEAK-TOOL: Typing-Tab > Caps Lock key behaviour > Make Caps Lock an additional ESC

03 LEARN AND TRAIN THE BASICS

   $ vimtutor en
   $ firefox vim-adventures.com
   • vim, :h user-manual :resize

04 DISABLE YOUR ARROW KEYS

   $ vim ~/.vimrc 
     map <up> <nop>
     imap <up> <nop>
     map <down> <nop>
     imap <down> <nop>
     map <left> <nop>
     imap <left> <nop>
     map <right> <nop>
     imap <right> <nop>
   :wq

05 CONFIGURE YOUR BASH-ENVIRONMENT

   : echo $MYVIMRC
   # update-alternatives --config editor
   $ vim ~/.bashrc
     EDITOR=/usr/bin/vim
     VISUAL=$EDITOR
     export EDITOR VISUAL
   :wq

06 ACTIVATE VIM-MODE IN BASH

   $ vim ~/.bashrc
     set -o vi
     bind -m vi-insert "\C-l"       # clear-screen
   :wq

07 ACTIVATE VIM-PLUGIN IN FIREFOX

   Plugin: Vim Vixen


007 VIMRC
colorscheme desert                      "desert default
let mapleader = ","                     "Leaderkey
set scrolloff=99                        "Scrolling behaviour
set splitright                          "Splitting behaviour
set rnu                                 "Relative line numbers
set nonu                                "Line numbers
set nocompatible
set showmode
set ruler                               
set linebreak
set showcmd
set laststatus=2
set background=dark
set encoding=utf8
filetype on
filetype plugin on
set mouse=a
"set colorcolumn=80
"set cursorline

"IDE
syntax on
set autoindent
set smartindent
set cindent

"FOLDING
autocmd BufWinLeave *.* mkview          
"autocmd BufWinLeave *.* mks!           
autocmd BufWinEnter *.* silent loadview

"DISABLE ARROW KEYS
map <up> <nop>
imap <up> <nop>
map <down> <nop>
imap <down> <nop>
map <left> <nop>
imap <left> <nop>
map <right> <nop>
imap <right> <nop>

"SEARCH
set nohlsearch
set incsearch

"TABs
set tabstop=4
set softtabstop=4
set shiftwidth=4
"set expandtab

"KEY MAPPINGS
"map <F2> :echo 'Current time is ' . strftime('%c')<CR>
nmap <F2> ggVG"+yzm
map <F5> :set list!<CR>
map <F6> :setlocal spell! spelllang=en_us<CR>
map <F8> :set nonu nornu<CR>
map <F9> :set rnu<CR>
map <F10> :set nu<CR>
map <Leader><F8> :set rnu!<CR>
map <Leader>, :mks!<CR> :wa<CR>
map <Leader>q zm:mks!<CR> :wqa<CR>

"ABBREVIATIONS
:iab ii <esc>
:iab psv public static void(String[] args) {<cr>}<esc>ko 
:iab sout System.out.println(                            


006 MACROS
:reg .................................... register
qa q @a ......................... start stop run a
:put a .................................... edit a
0"ay$ ................................... update a

:map <F2> a<C-R>=strftime("%c")<CR><ESC>
:map <F2> ggVG"+y
:map <F2> :set list!


005 MODES 
:h vim-modes 

:h Normal-mode ..........<ctrl-w_>.................. Normal mode
:h Visual-mode ..........<ctrl-w_>.................. Visual mode
:h Select-mode ..........<ctrl-w_>.................. Select mode
:h Insert-mode ..........<ctrl-w_>.................. Insert mode
:h Command-line-mode ....<ctrl-w_>............ Command-line mode
:h Ex-mode ..............<ctrl-w_>...................... Ex mode
:h Terminal-mode ........<ctrl-w_>................ Terminal mode


004 BUFFERS
:ls :buffers .............................................. list
:b1 :b2 :bn :bp :bf :bl :b# ....... 1 2 next previous first last
:badd <ctrl-d> ............................................. add
:bd ..................................................... delete
:set hidden|nohidden .................................... hidden

:mks :mks! ........................................ save session


003 CHEAT-SHEET
:ve :version ............................................ version
:ab :abc :unab ^v .................................... abbreviate
a A i I o O s S C ~ .................... append insert substitute
$ vim -u NONE -N ....................................... baseline
r x ~ ..................................... replace delete change
ci( ci{ ci< ci" .................................... change inner
v j " + y ............................................. clipboard
<esc> gg v G "+ y .......................................... copy
dd D x d$ dip diw daw dit di" das ........................ delete
$ vim -O ~/.vimrc ~/.bashrc ^ww ^wr ^wc ^wq ................ edit
~ :e :edit $ ^xe ........................................... edit
zf5j zo zc zd ........................................... folding
:ve ^g g^g .......................................... information
m1 '1 `1 marks ............................................. mark
[InsertMode] ^n ........................................... match
:set nu|nonu :set rnu|nornu ............................. numbers
. ........................................................ repeat
/ f * # q/ q? q: :%s/one/two/g ........................... search
/\cabc /\Cabc /\<abc\> :nohl ............................. search
:set incsearch noincsearch :set hls nhls ................. search
$ vimtutor en .......................................... tutorial
u U ^r ................................................ undo redo
^wv ^ws ^wq ^ww ^wr ^wc ................................. windows
gg G ^g 50% ^e ^y ^n ^u ^d ^f ^b ........................ windows
:set ruler noruler ...................................... windows
:set linebreak nolinebreak .............................. windows
:call matchadd('colorColumn', '\%81v', 100) ............. windows
:q :q! :qa :qa! :wq :wqa :exit ZZ ZQ ....................... exit


002 DOCUMENTATION
:h user-manual ........... <ctrl-w_> ..................... User manual
:h reference  ............ <ctrl-w_> ................ Reference manual
$ man vim .................................................. man-pages
file:///usr/share/doc/vim-doc/html/index.html ............ file-system 
:h :resize ............... <ctrl-w_> ................. vim-help-system
Documentation I     : vimhelp.org
Documentation II    : vimhelp.org/usr_toc.txt.html
FAQ                 : vimhelp.org/vim_faq.txt.html
Wiki                : vim.wikia.com/wiki/Vim_Tips_Wiki


001 MOVEMENTS
zz z. zb z- zt z<enter> ... cursor ....................... move cursor
h j k l gj gk ............. character .......... left, down, up, right 
b w B W ge e .............. word ....................... back, forward
0 ^ gm $ .................. sentence .............. start, middle, end
( ) ....................... sentence .................. next, previous
{ } ....................... paragraph ................. next, previous
H M L ..................... window ................. high, middle, low
gg G 1% 50% 100% .......... document ................ first, last line
% ......................... brace, bracket, comment ............. next
Homepage    : vim.org
Reference   : vimhelp.org/quickref.txt.html