Skip to content

Instantly share code, notes, and snippets.

@ghost355
Created December 12, 2022 20:08
Show Gist options
  • Select an option

  • Save ghost355/48580c202a40b3e3f0c3de4581c6ee5c to your computer and use it in GitHub Desktop.

Select an option

Save ghost355/48580c202a40b3e3f0c3de4581c6ee5c to your computer and use it in GitHub Desktop.

Revisions

  1. ghost355 created this gist Dec 12, 2022.
    309 changes: 309 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,309 @@
    let mapleader = ' '
    "======================================================================
    " Плагины
    "======================================================================
    call plug#begin()

    Plug 'morhetz/gruvbox'
    Plug 'nlknguyen/papercolor-theme'
    " Поддержка русского языка при переключении режимов
    Plug 'lyokha/vim-xkbswitch'

    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    Plug 'neovimhaskell/haskell-vim'

    Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
    Plug 'junegunn/fzf.vim'

    Plug 'tpope/vim-surround'
    Plug 'tpope/vim-unimpaired'
    Plug 'tpope/vim-commentary'
    Plug 'tpope/vim-fugitive'
    Plug 'tpope/vim-rhubarb'
    Plug 'tpope/vim-repeat'
    Plug 'tpope/vim-vinegar'
    Plug 'markonm/hlyank.vim' " подсветить скопированное
    Plug 'godlygeek/tabular' " выравнивание
    Plug 'luochen1990/rainbow' " цветные скобки
    let g:rainbow_active = 1

    Plug 'kana/vim-textobj-entire'
    Plug 'kana/vim-textobj-user'
    Plug 'airblade/vim-gitgutter'

    call plug#end()
    "======================================================================
    "======================================================================
    " Общие настройки
    "======================================================================
    set nocompatible
    set timeoutlen=1000 ttimeoutlen=100
    set updatetime=250
    set history=1000
    set wildmenu
    set wildoptions=pum
    set backspace=eol,start,indent
    set noswapfile
    set nobackup
    set nowritebackup
    " Use UTF-8 as default encoding
    set encoding=utf-8
    set fileencoding=utf-8
    set fileencodings=utf-8
    " Use Unix as the standard file type
    set fileformats=unix,dos,mac

    set hidden
    set fileignorecase
    set viminfo^=%
    set autoindent
    set smartindent
    set expandtab
    set smarttab
    set shiftwidth=4
    set tabstop=4
    set whichwrap+=<,>,h,l
    set wrap
    set linebreak
    set textwidth=100
    " Обновлять файл если был изменен
    set autoread
    au FocusGained,BufEnter * checktime
    " Aктивировать .vimrc после сохранения файла
    autocmd! bufwritepost ~/.vimrc source ~/.vimrc

    " Опции поиска
    set hlsearch
    set incsearch
    set wrapscan
    set ignorecase
    set smartcase
    nnoremap <silent><leader><cr> :noh<cr>

    " Visual mode pressing * or # searches for the current selection
    vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
    vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>

    function! VisualSelection(direction, extra_filter) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", "\\/.*'$^~[]")
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'gv'
    call CmdLine("Ack '" . l:pattern . "' " )
    elseif a:direction == 'replace'
    call CmdLine("%s" . '/'. l:pattern . '/')
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
    endfunction

    " Remap highlited search of current word with * and # to stay in place
    nnoremap * *``
    nnoremap # #``

    set magic
    set maxmempattern=1000


    "======================================================================
    " Внешний вид
    "======================================================================
    set langmenu=en_US
    let $LANG = 'en_US'
    if !has('gui_running') "
    set t_Co=256
    endif
    set cmdheight=2
    set background=dark
    colorscheme gruvbox
    set number
    set virtualedit=onemore

    set foldcolumn=2
    set signcolumn=yes
    set lazyredraw
    set ruler
    set showcmd
    set scrolloff=10
    set mouse=a

    " No annoying sound on errors
    set noerrorbells
    set novisualbell

    " Подсвечивать строку на которой находится курсор
    set cursorline
    " Прекратить подсвечивать её при переходе в режим INSERT
    autocmd InsertEnter,InsertLeave * set cursorline!

    " при перемещении вверх/вниз считает строку, разбитую на несколько линий как одну
    nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
    nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')

    " Splits open more natural
    set splitbelow
    set splitright

    " Change the cursor shape in different modes
    let &t_SI = "\<Esc>[5 q"
    let &t_SR = "\<Esc>[3 q"
    let &t_EI = "\<Esc>[1 q"

    " let g:netrw_list_hide= '.*\.o$,.*\.hi$,.DS_Store,'
    set wildignore+=*.hi,*.o,.DS_Store,
    let g:netrw_liststyle = 2


    "======================================================================
    " Привязка клавиш
    "======================================================================

    inoremap <silent>jj <esc>

    " _____ Copy to OS clipboard _____
    " Copy all buffer to OS clipboard
    nnoremap YYY mggg"+yG`gzz
    " Copy line to OS clipboard
    nnoremap YY "+yy
    " Copy line to OS clipboard
    vnoremap YY "+yy
    " Copy to OS clipboard
    nnoremap Y "+y
    " Copy to OS clipboard
    vnoremap Y "+y

    " Fzf-vim
    nnoremap <Leader>ff :Files<CR>
    nnoremap <Leader>fF :Files
    nnoremap <Leader>fr :Rg
    nnoremap <Leader>fb :Buffers<CR>
    nnoremap <Leader>fc :Commands<CR>
    nnoremap <Leader>fl :BLines<CR>
    nnoremap <Leader>fm :Marks<CR>
    nnoremap <Leader>fw :Windows<CR>
    nnoremap <Leader>fh :Helptags<CR>
    nnoremap <Leader>fk :Maps<CR>
    nnoremap <Leader>f: :History:<CR>
    nnoremap <Leader>f/ :History/<CR>
    "nnoremap <Leader>fH :Hoogle<CR>

    " Windows manage
    nnoremap <Leader>wc <C-W>c
    " Open window splits in various places
    nnoremap <silent><leader>wh :leftabove vnew<CR>
    nnoremap <silent><leader>wl :rightbelow vnew<CR>
    nnoremap <silent><leader>wk :leftabove new<CR>
    nnoremap <silent><leader>wj :rightbelow new<CR>

    "======================================================================
    " Coc setting
    "======================================================================

    set completeopt=menu,menuone,preview,noselect,noinsert

    " Tab and Enter keys setting for autocomplete

    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-h>"

    inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm(): "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
    function! CheckBackspace() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1] =~# '\s'
    endfunction

    " Highlight the symbol and its references when holding the cursor.
    autocmd CursorHold * silent call CocActionAsync('highlight')


    " Remap <C-f> and <C-b> for scroll float windows/popups.
    if has('nvim-0.4.0') || has('patch-8.2.0750')
    nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
    nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
    inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
    inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
    vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
    vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
    endif

    " Add `:Format` command to format current buffer.
    command! -nargs=0 Format :call CocActionAsync('format')

    augroup mygroup
    autocmd!
    " Setup formatexpr specified filetype(s).
    autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
    " Update signature help on jump placeholder.
    autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
    augroup end

    " Add `:Fold` command to fold current buffer.
    command! -nargs=? Fold :call CocAction('fold', <f-args>)

    " Add `:OR` command for organize imports of the current buffer.
    command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')

    " Autocometition off for some FileTypes
    autocmd FileType markdown let b:coc_suggest_disable = 1
    autocmd FileType text let b:coc_suggest_disable = 1

    " Use K to show documentation in preview window.
    nnoremap <silent> K :call ShowDocumentation()<CR>

    function! ShowDocumentation()
    if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
    else
    call feedkeys('K', 'in')
    endif
    endfunction

    " GoTo code navigation.
    nmap <silent> gd <Plug>(coc-definition)
    nmap <silent> gy <Plug>(coc-type-definition)
    nmap <silent> gi <Plug>(coc-implementation)
    nmap <silent> gr <Plug>(coc-references)

    nmap <silent> [g <Plug>(coc-diagnostic-prev)
    nmap <silent> ]g <Plug>(coc-diagnostic-next)

    " Remap keys for apply refactor code actions.
    nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
    xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
    nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)

    " Formatting selected code.
    xmap <leader>F <Plug>(coc-format-selected)
    nmap <silent><leader>F :Format<CR>

    " Apply AutoFix to problem on the current line.
    nmap <leader>qf <Plug>(coc-fix-current)

    " Remap keys for applying codeAction to the current buffer.
    nmap <leader>ac <Plug>(coc-codeaction-cursor)
    nmap <leader>al <Plug>(coc-codeaction-line)

    " Symbol renaming.
    nmap <leader>rn <Plug>(coc-rename)

    " Mappings for CoCList
    " Show all diagnostics.
    nnoremap <silent><nowait> <Leader>ld :<C-u>CocList diagnostics<cr>
    " Manage extensions.
    nnoremap <silent><nowait> <Leader>le :<C-u>CocList extensions<cr>
    " Show commands.
    nnoremap <silent><nowait> <Leader>lc :<C-u>CocList commands<cr>
    " Find symbol of current document.
    nnoremap <silent><nowait> <Leader>lo :<C-u>CocList outline<cr>
    " Search workspace symbols.
    nnoremap <silent><nowait> <Leader>ls :<C-u>CocList -I symbols<cr>
    " Do default action for next item.
    nnoremap <silent><nowait> <Leader>lj :<C-u>CocNext<CR>
    " Do default action for previous item.
    nnoremap <silent><nowait> <Leader>lk :<C-u>CocPrev<CR>
    " Resume latest coc list.
    nnoremap <silent><nowait> <Leader>lp :<C-u>CocListResume<CRy