6 minute read

”—————————————————————- “ 4. User interface “—————————————————————- “ Set X lines to the cursor when moving vertically set scrolloff=0

” Always show mode set showmode

” Show command keys pressed set showcmd

” Enable the WiLd menu set wildmenu

” Show the current position set ruler

” Command bar height set cmdheight=2

” Backspace works on Insert mode set backspace=eol,start,indent

” Don’t redraw while executing macros (good performance config) set lazyredraw

” Show matching brackets when text indicator is over them set showmatch

” How many tenths of a second to blink when matching brackets set matchtime=2

” No annoying sound on errors set noerrorbells set novisualbell

” Mouse set mouse=a

” Highlight cursor line and cursor column set cursorline set nocursorcolumn

” Always show the status line set laststatus=2

” Change the cursor shape if !has(“nvim”) let &t_SI = “<Esc>[6 q” let &t_SR = “<Esc>[4 q” let &t_EI = “<Esc>[2 q” else set guicursor=n-v:block-Cursor/lCursor-blinkon0 set guicursor+=i-ci-c:ver100-Cursor/lCursor-blinkon0 set guicursor+=r-cr:hor100-Cursor/lCursor-blinkon0 endif

” Omni completion if has(‘autocmd’) && exists(‘+omnifunc’) autocmd Filetype * \ if &omnifunc == “” | \ setlocal omnifunc=syntaxcomplete#Complete | \ endif endif

” Fix italics issue if !has(“nvim”) let &t_ZH=”\e[3m” let &t_ZR=”\e[23m” endif

”—————————————————————- “ 5. Scheme and colors “—————————————————————- “ True color “ if !has(“nvim”) “ if has(“termguicolors”) “ let &t_8f = “<Esc>[38;2;%lu;%lu;%lum” “ let &t_8b = “<Esc>[48;2;%lu;%lu;%lum” “ set termguicolors “ endif “ else “ set termguicolors “ endif

” Syntax highlighting syntax enable

” Color scheme colorscheme atomic

” Show syntax highlighting groups nnoremap B :call SynStack()

”—————————————————————- “ 6. Files and backup “—————————————————————- “ Disable swap files set noswapfile

” No backup (use Git instead) set nobackup

” Prevents automatic write backup set nowritebackup

” Use UTF-8 as default encoding set encoding=utf8

” Use Unix as the standard file type set fileformats=unix,dos,mac

” Autoread a file when it is changed from the outside set autoread

” Reload a file when it is changed from the outside let g:f5msg = ‘Buffer reloaded.’ nnoremap :e:echo g:f5msg

” Enable filetype plugins filetype plugin on filetype indent on

” Allow us to use Ctrl-s and Ctrl-q as keybinds “ Restore default behaviour when leaving Vim. if !has(“nvim”) silent !stty -ixon autocmd VimLeave * silent !stty ixon endif

” Save the current buffer nnoremap s :update

” Save all buffers nnoremap S :bufdo update

” :W sudo saves the file “ (useful for handling the permission-denied error) cnoremap WW w !sudo tee > /dev/null %

” Rename file nnoremap :call RenameFile()

” Work on buffer nnoremap yab :%y nnoremap dab :%d nnoremap vab ggVG

”—————————————————————- “ 7. Buffers management “—————————————————————- “ Buffer hidden when it is abandoned set hidden

” Close the current buffer nnoremap bd :call CustomCloseBuffer()

” Move between buffers nnoremap :bprev nnoremap :bnext

” Edit and explore buffers nnoremap bb :edit =expand("%:p:h")/ nnoremap bg :buffers:buffer

” Switch CWD to the directory of the current buffer nnoremap bw :lcd %:p:h:pwd

” Copy the filepath to clipboard nnoremap by :let @+=expand("%:p")

” Ignore case when autocompletes when browsing files set fileignorecase

” Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set showtabline=2 catch endtry

” Remember info about open buffers on close “ set viminfo^=%

”—————————————————————- “ 8. Tabs management “—————————————————————- “ Create and close tabs nnoremap td :tabclose nnoremap to :tabonly

” Open a new tab with the current buffer’s path “ Useful when editing files in the same directory nnoremap tt :tabedit =expand("%:p:h")/

” Move tabs position nnoremap tr :execute 'silent! tabmove ' . (tabpagenr()-2) nnoremap ty :execute 'silent! tabmove ' . tabpagenr()

”—————————————————————- “ 9. Multiple windows “—————————————————————- “ Remap wincmd map ,

set winminheight=0 set winminwidth=0 set splitbelow set splitright set fillchars+=stlnc:\/,vert:│,fold:―,diff:―

” Split windows map - :split map . :vsplit map j :close map x :q! map , =

” Resize windows if bufwinnr(1) map + :resize +1 map - :resize -1 map < :vertical resize +1 map > :vertical resize -1 endif

” Toggle resize window nnoremap f :call ToggleResize()

” Last, previous and next window; and only one window nnoremap l :wincmd p:echo "Last window." nnoremap p :wincmd w:echo "Previous window." nnoremap n :wincmd W:echo "Next window." nnoremap o :wincmd o:echo "Only one window."

” Move between Vim windows and Tmux panes “ - It requires the corresponding configuration into Tmux. “ - Check it at my .tmux.conf from my dotfiles repository. “ - URL: https://github.com/gerardbm/dotfiles/blob/master/tmux/.tmux.conf “ - Plugin required: https://github.com/christoomey/vim-tmux-navigator if !has(“nvim”) set =h set =j set =k set =l endif

nnoremap :TmuxNavigateLeft nnoremap :TmuxNavigateDown nnoremap :TmuxNavigateUp nnoremap :TmuxNavigateRight

” Remove the Windows ^M - when the encodings gets messed up noremap mmHmt:%s///ge'tzt`m

” Close the preview window nnoremap . :pclose

” Scroll the preview window if !has(“nvim”) set =d set =u endif

nnoremap :wincmd P5:wincmd p nnoremap :wincmd P5:wincmd p

”—————————————————————- “ 10. Indentation tabs “—————————————————————- “ Enable autoindent & smartindent set autoindent set smartindent

” Use tabs, no spaces set noexpandtab

” Be smart when using tabs set smarttab

” Tab size (in spaces) set shiftwidth=2 set tabstop=2

” Remap indentation nnoremap >> nnoremap <<

vnoremap >gv vnoremap <gv

inoremap inoremap

” Don’t show tabs set list

let g:f6msg = ‘Toggle list.’ nnoremap :set list!:echo g:f6msg

” Show tabs and end-of-lines set listchars=tab:│\ ,trail:¬

”—————————————————————- “ 11. Moving around lines “—————————————————————- “ Specify which commands wrap to another line set whichwrap+=<,>,h,l

” Many jump commands move the cursor to the start of line set nostartofline

” Wrap lines into the window set wrap

” Don’t break the words “ Only works if I set nolist (F6) set linebreak set showbreak=├——»

” Stop automatic wrapping set textwidth=0

” Column at 80 width set colorcolumn=80

” Listings don’t pause set nomore

” Color column let g:f10msg = ‘Toggle colorcolumn.’ nnoremap :call ToggleColorColumn():echo g:f10msg

” Show line numbers set number set numberwidth=2

let g:f3msg = ‘Toggle line numbers.’ nnoremap :set number!:echo g:f3msg

” Set relative line numbers set relativenumber

let g:f4msg = ‘Toggle relative line numbers.’ nnoremap :set norelativenumber!:echo g:f4msg

” Treat long lines as break lines (useful when moving around in them) nnoremap k (v:count == 0 ? 'gk' : 'k') nnoremap j (v:count == 0 ? 'gj' : 'j')

vnoremap k (v:count == 0 ? 'gk' : 'k') vnoremap j (v:count == 0 ? 'gj' : 'j')

nnoremap g^ nnoremap g$

vnoremap g^ vnoremap g$

” Toggle the cursor position start/end of the line nnoremap ñ :call ToggleCPosition('') vnoremap ñ :call ToggleCPosition('normal! gv')

” Join / split lines nnoremap J nnoremap i

” Duplicate a line nnoremap cx yyP nnoremap cv yyp

” Folding set foldmethod=marker

” Return to last edit position when opening files autocmd BufReadPost * \ if line(“’"”) > 0 && line(“’"”) <= line(“$”) | \ exe “normal! g`"” | \ endif

” — Readline commands — “—————————————————————- “ Move the cursor to the line start inoremap 0

” Move the cursor to the line end inoremap $

” Moves the cursor back one character inoremap deoplete#smart_close_popup()."\"

” Moves the cursor forward one character inoremap deoplete#smart_close_popup()."\"

” Remove one character inoremap

” Command Mode cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap " cnoremap

”—————————————————————- “ 12. Paste mode “—————————————————————- “ Bracketed paste mode “ - Source: https://ttssh2.osdn.jp/manual/en/usage/tips/vim.html if !has(“nvim”) if has(“patch-8.0.0238”) if &term =~ “screen” let &t_BE = “\e[?2004h” let &t_BD = “\e[?2004l” exec “set t_PS=\e[200~” exec “set t_PE=\e[201~” endif endif endif

”—————————————————————- “ 13. Search, vimgrep and grep “—————————————————————- “ Highlight search results set hlsearch

” Makes search act like search in modern browsers set incsearch

” Search, wrap around the end of the buffer set wrapscan

” Ignore case when searching set ignorecase

” When searching try to be smart about cases set smartcase

” For regular expressions turn magic on set magic

” Maximum amount of memory in Kbyte used for pattern matching set maxmempattern=1000

” — Highlight — “—————————————————————- “ Map to / (search) nnoremap / nnoremap ?

” Highlight the word under the cursor and don’t jump to next nnoremap :let @/='\<=expand("")\>':set hlsearch

” Highlight the selected text and don’t jump to next vnoremap :call VSetSearch():set hlsearch

” Disable highlight nnoremap m :noh

” Search into a Visual selection vnoremap :call RangeSearch('/') \ :if strlen(g:srchstr) > 0 \ \|exec '/'.g:srchstr\|endifn vnoremap ? :call RangeSearch('?') \ :if strlen(g:srchstr) > 0 \ \|exec '?'.g:srchstr\|endifN

Updated: