Skip to content

Instantly share code, notes, and snippets.

@alsolovyev
Last active March 3, 2023 05:38
Show Gist options
  • Save alsolovyev/0b7b02fcc850eeeb21b55c3a031976e4 to your computer and use it in GitHub Desktop.
Save alsolovyev/0b7b02fcc850eeeb21b55c3a031976e4 to your computer and use it in GitHub Desktop.
Vim configuration
syntax on
" Plugins
call plug#begin() " Specify a directory for plugins
Plug 'airblade/vim-gitgutter'
" Plug 'HerringtonDarkholme/yats.vim'
"Plug 'junegunn/fzf.vim'
"Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
"Plug 'leafgarland/typescript-vim'
"Plug 'maxmellon/vim-jsx-pretty'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'pangloss/vim-javascript'
Plug 'preservim/nerdtree'
"Plug 'ryanoasis/vim-devicons'
Plug 'tpope/vim-commentary'
"Plug 'tikhomirov/vim-glsl'
"Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
"Plug 'leafOfTree/vim-vue-plugin'
"Plug 'storyn26383/vim-vue'
"Plug 'voldikss/vim-floaterm'
call plug#end()
" Coc extentions
" - @yaegassy/coc-tailwindcss3
" - coc-eslint
" - coc-pretty
" - coc-tsserver
let g:coc_global_extensions = [
\'@yaegassy/coc-tailwindcss3',
\'coc-eslint',
\'coc-prettier',
\'coc-tsserver',
\]
" Configuration
set autoindent " Autoindent new lines
set clipboard^=unnamed,unnamedplus " Use system clipboard
set cursorline " highlight the current line
set encoding=utf-8 " Change the output encoding that is shown in the terminal
set expandtab " Expand TABs to spaces
set fileencodings=utf8,cp1251 " Change the output encoding of the file that is written
set fillchars+=vert:\ " Change vert character to whitespace
set foldlevel=20 " Open all folds by default
set foldmethod=indent " Folds are defined by syntax highlighting(syntax)
set hidden " Hide file instead of closing if current buffer unsaved
set hlsearch " Highlight all search matches
set incsearch " Highlight all search matches while typing
set linebreak " Do not cross words across two lines
set mouse=a " Enbale mouse support
set mousehide " Hide cursor while typing
set nobackup " Remove backup files on file close
set nocompatible " Disable compatibility to venerable old vi
set noerrorbells " Disable error bell
set noswapfile " Disable swapfile(*.swp)
set noundofile " Switch off automatic creation of *.un~ files
set novisualbell " Disable visual bell
set nowritebackup " Switch off automatic creation of backup files
set number " Enable the line numbering
set path=.,,** " Change path to сurrent directory and subdirectories
set re=0 " Change regex engine to improve perfomance in TS files
set relativenumber " Show numbers relative to the cursor's current position
set ruler " Show ruler (line number and letter)
set shiftwidth=2 " Indents will havea width of 2
set smarttab " Indent according to 'shiftwidth' at the beginning of the line
set softtabstop=2 " Sets the number of columns for a TAB
set t_Co=256 " Enable full color support
set t_vb= " Disable
set tabstop=2 " Tab width
set tm=500 " Disable
set wildignore+=**/node_modules/** " Exclude node_modules from path
set wrap " Wrap long lines
" Remove all trailing whitespaces
autocmd BufWritePre * :%s/\s\+$//e
" Change cursor shape in iTerm2.app
" 0 -> block
" 1 -> vertical
" 2 -> underscore
if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>]50;CursorShape=2\x7" " Insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Normal mode
let &t_SR = "\<Esc>]50;CursorShape=2\x7" " Replace mode
" autocmd VimEnter * let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" autocmd BufWinEnter * redraw!
autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=2\x7" " Revert the cursor shape to it's initial
endif
" Keep cursor centered vertically on the screen
augroup VCenterCursor
au!
au BufEnter,WinEnter,WinNew,VimResized *,*.* let &scrolloff=winheight(win_getid())/2
augroup END
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <silent><expr> <Tab>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) : "\<C-d>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
" Keybinding
vnoremap § <ESC>
inoremap § <ESC>
inoremap jj <ESC>
inoremap kk <ESC>
inoremap <silent><expr> <c-space> coc#refresh()
nnoremap ; <C-w>
" Scroll below the end of a file
nnoremap j jzz
nnoremap k kzz
nnoremap n nzz
nnoremap G Gzz
" Delete a line without putting it into the buffer
nnoremap <leader>d "_d
vnoremap <leader>d "_d
" Move lines
nnoremap <S-j> :m .+1<CR>==
nnoremap <S-k> :m .-2<CR>==
vnoremap <S-j> :m '>+1<CR>gv=gv
vnoremap <S-k> :m '<-2<CR>gv=gv
" Tab Navigation
noremap <S-Tab> :<C-U>tabnext<CR>
" inoremap <S-Tab> <C-\><C-N>:tabnext<CR>
" cnoremap <S-Tab> <C-C>:tabnext<CR>
" Prettier
command! -nargs=0 Format :CocCommand prettier.forceFormatDocument
command! -nargs=0 Prettier :CocCommand prettier.forceFormatDocument
" NERDTree
nnoremap <leader>n :NERDTreeToggle<CR>
let NERDTreeQuitOnOpen=1
" let NERDTreeDirArrowExpandable=''
" let NERDTreeDirArrowCollapsible=''
" Devicons
" let WebDevIconsNerdTreeBeforeGlyphPadding=''
" let WebDevIconsNerdTreeAfterGlyphPadding=''
" let WebDevIconsUnicodeDecorateFolderNodes=1
" Exit Vim if NERDTree is the only window remaining in the only tab.
" autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" FzF
" Depends:
" https://github.com/sharkdp/fd
" https://github.com/BurntSushi/ripgrep
let g:fzf_preview_window=['hidden,right,50%,<70(up,40%)', 'ctrl-/']
map <Leader>ff :Files<CR>
map <Leader>fg :GFiles<CR>
"map <Leader>fa :Rg<CR>
"let $FZF_DEFAULT_COMMAND = 'fd --type f'
" GitGutter
" Floaterm
let g:floaterm_keymap_toggle='<Leader>ft'
let g:floaterm_keymap_kill='<Leader>fq'
let g:floaterm_title=''
let g:floaterm_width=0.85
let g:floaterm_position='bottom'
" highlight Floaterm guibg=black
" Set floating window border line color to cyan, and background to orange
" highlight FloatermBorder guibg=orange guifg=cyan
" highlight FloatermBorder guifg=16
" hi FloatermBorder guibg=orange guifg=cyan
" hi Floaterm guibg=black
" Golang
" let g:go_auto_type_info=1
" let g:go_highlight_types = 1
" let g:go_highlight_fields = 1
" let g:go_highlight_functions = 1
" let g:go_highlight_function_calls = 1
" let g:go_highlight_extra_types = 1
" let g:go_highlight_operators = 1
" Highlighting
highlight CocFloating ctermbg=16 " Coc popup window
highlight CursorLine cterm=NONE ctermbg=16 " Selected line
highlight CursorLineNr cterm=NONE ctermbg=16 ctermfg=8 " Selected line number
highlight Error cterm=NONE ctermbg=NONE ctermfg=9 "
highlight ErrorMsg cterm=NONE ctermbg=9 ctermfg=7 "
highlight GitGutterAdd cterm=NONE ctermbg=NONE ctermfg=2 "
highlight GitGutterChange cterm=NONE ctermbg=NONE ctermfg=4 "
highlight GitGutterDelete cterm=NONE ctermbg=NONE ctermfg=1 "
highlight LineNr cterm=NONE ctermfg=8 " Line numbers
highlight Pmenu ctermbg=16 ctermfg=8 " Popup menu
highlight PmenuSel ctermbg=0 ctermfg=4 " Selected item in popup menu
highlight SignColumn cterm=NONE ctermbg=NONE ctermfg=8 "
highlight TabLine cterm=NONE ctermbg=NONE ctermfg=8 " Tab bar
highlight TabLineFill cterm=NONE ctermbg=NONE " Empty space next to tabs
highlight TabLineSel cterm=NONE ctermbg=NONE ctermfg=5 " Selected tab
highlight VertSplit cterm=NONE ctermfg=16 " Separator between windows
# Set iTerm position
osascript \
-e 'tell application "iTerm"' \
-e 'set newBounds to {495, 44, 1305, 1169}' \
-e 'set bounds of front window to newBounds' \
-e 'end tell'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment