Not to start a editor war or anything, but VIM is and always will be the best editor (emacs are vscode are okey).
I used different setups (.vimrc
and plugins) over the years but for the last couple of years i found cool a setup that i like. Here is breakdown of some useful plugins and VIM built-in features that i use every day.
windows vs buffers vs tabs Link to heading
Probably everyone using vim used these feature in a way or another.
From vim docs:
Summary:
A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.
A window is a viewport onto a buffer. You can use multiple windows on one buffer, or several windows on different buffers.
A buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.
Buffers cheat sheet Link to heading
:e <FILE>
:buffers
:buffer <n>
Widows cheat sheet Link to heading
open windows >> :split
open vertical >> :vsplit
close window >> :q
<CTRL-W> Left
<CTRL-W> Right
<CTRL-W> Up
<CTRL-W> Down
Tabs cheat sheet Link to heading
:tabclose
:tabnew
:tabnext
:tabprev
<n> g t
plugins Link to heading
Vundle vim plugin manager Link to heading
Vundle
downloads plugins from github with relative path. For example,
Plugin 'vim-airline/vim-airline'
To install all plugins
:PluginInstall
list of important plugins Link to heading
- vim-airline
- nerdtree
- buffergator (Move around buffers)
- fzf
fzf important commands Link to heading
To search for files
:Files
To search for text
:Rg <TEXT>
Sample .vimrc Link to heading
set nocompatible " be iMproved, required
filetype off " required
" Vundle
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'preservim/nerdtree'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'frazrepo/vim-rainbow'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
call vundle#end() " required
filetype plugin indent on " required
"""""""""""""""""""""""""""""
" Configuration
""""""""""""""""""""""""""""
" Search
set incsearch
set hlsearch
highlight Search ctermfg=LightYellow
"set spell spelllang=en_us
" Indentation
set autoindent
set smartindent
autocmd FileType make setlocal noexpandtab
set title
set cursorline
set hidden
" highlight Spaces at the end
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
"""""""""""""""""""""""""""""
" Shortcuts
""""""""""""""""""""""""""""
" map CTRL-SPACE to enter exit
nnoremap <C-@> i
inoremap <C-@> <Esc>
" map CTRl-/ to comment
nnoremap <C-_> I//<Esc>A<Esc>
" map leader \s for search and replace
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
" Tabs
"nnoremap <C-Left> :tabprevious<CR>
"nnoremap <C-Right> :tabnext<CR>
"nnoremap <C-t> :tabnew<CR>
"inoremap <C-S> <Esc>:tabprevious<CR>i
"inoremap <C-tab> <Esc>:tabnext<CR>i
"inoremap <C-t> <Esc>:tabnew<CR>
"" Buffers and Splits
map <C-Right> :bn<cr>
map <C-Left> :bp<cr>
map gd :bp\|bd #<cr> " move to open buffer when one is closed
nnoremap <A-Up> :wincmd k<CR>
nnoremap <A-Down> :wincmd j<CR>
nnoremap <A-Left> :wincmd h<CR>
nnoremap <A-Right> :wincmd l<CR>
" NerdTree
nnoremap <leader>n :NERDTreeToggle<CR>
"nnoremap <C-n> :NERDTree<CR>
"nnoremap <C-t> :NERDTreeToggle<CR>
"nnoremap <C-f> :NERDTreeFind<CR>
"nnoremap <leader>n :NERDTreeFocus<CR>
" Start NERDTree when Vim is started without file arguments.
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
" Start NERDTree. If a file is specified, move the cursor to its window.
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
" Start NERDTree when Vim starts with a directory argument.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
\ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif
" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * silent NERDTreeMirror
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
\ quit | endif
let g:NERDTreeWinSize=40
"" airline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#fnamemod = ':t'
"" fzf.vim
" Search for work under cursor
nnoremap <silent> <C-f> :Rg <C-R><C-W><CR>
autocmd VimEnter * noremap <silent> <C-p> :Files <CR>
"" Buffergator
let g:buffergator_viewport_split_policy = "R"
let g:buffergator_autoupdate=1
let g:buffergator_autodismiss_on_select=0
"" Rainbow Parentheses
let g:rainbow_active = 1
"" Indent Guides
let g:indent_guides_enable_on_vim_startup = 1