Skip to content

Instantly share code, notes, and snippets.

@ciases
Last active June 14, 2021 10:06
Show Gist options
  • Save ciases/d09b5d31e2389c8e5f30863f318f1ab3 to your computer and use it in GitHub Desktop.
Save ciases/d09b5d31e2389c8e5f30863f318f1ab3 to your computer and use it in GitHub Desktop.
neovim settings
" Plugins list ---------------------- {{{
call plug#begin()
Plug 'Shougo/denite.nvim'
Plug 'ctrlpvim/ctrlp.vim'
" GIT
Plug 'neoclide/vim-easygit'
Plug 'airblade/vim-gitgutter'
Plug 'machakann/vim-sandwich'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'terryma/vim-multiple-cursors'
Plug 'jiangmiao/auto-pairs'
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'mattn/emmet-vim'
"snippets
Plug 'Shougo/neosnippet.vim'
Plug 'ciases/neosnippet-snippets'
" Interface
Plug 'chriskempson/base16-vim'
call plug#end()
" }}}
set runtimepath+=~/.vim,~/.vim/after
set packpath+=~/.vim
set termguicolors
" TODO: move all these settings to ~/.vimrc someday
" source ~/.vimrc
filetype plugin indent on
syntax enable
set hidden
set scrolloff=2
set laststatus=2
set cursorline
" Indentation
set shiftwidth=4
set softtabstop=4
set tabstop=4
set expandtab
set smartindent
"set nofoldenable
"set colorcolumn=80
" Redraw only when we need to
set lazyredraw
" Disabling cursor blinking
set guicursor=a:blinkon500-blinkwait500-blinkoff500
" Show invisible characters
""set lcs=tab:>-,trail:·,eol:¬,nbsp:_
set lcs=tab:>-,trail:·,nbsp:_
set list
set lazyredraw
set splitright
set splitbelow
" Turn off swap files
set noswapfile
set nobackup
" Show ↪ at the beginning of wrapped lines
if has("linebreak")
let &sbr = nr2char(8618).' '
endif
" Line break like in ST3
set breakindent
"Reload files changed outside vim
set autoread
" Search
set hlsearch
set ignorecase
set smartcase
set incsearch
set gdefault " use g search flag by default
" Use mouse in all mode
set mouse=a
set iskeyword+=-
"
" Mapping --------------- {{{
let mapleader = ","
nnoremap <leader>s :w<CR>
nnoremap <Leader>q :q<CR>
inoremap jk <Esc>
if has('win32') || has('win64')
nnoremap <leader>ev :tabedit ~\AppData\Local\nvim\init.vim<CR>
nnoremap <leader>eg :vsplit ~\AppData\Local\nvim\ginit.vim<CR>
else
nnoremap <leader>ev :tabedit ~/.config/nvim/init.vim<CR>
endif
" Change current working directory
nnoremap ,cd :cd %:p:h<CR>:pwd<CR>
" Disable ex mode mapping
nnoremap Q <NOP>
" Disable recording macroses too
" nnoremap q <NOP>
" Add line above and below
nnoremap <C-Up> O<Esc><Down>
nnoremap <C-Down> o<Esc><Up>
" Down is really the next line
nnoremap j gj
nnoremap k gk
" Search visual selection
vnoremap // y/<C-R>"<CR>
" Clear selection
nnoremap <silent> <Esc> :nohlsearch<CR>
" Copy to system clipboard
vnoremap <C-c> "*y<CR>
vnoremap y "*y<CR>
" Align blocks of text and keep them selected
vnoremap < <gv
vnoremap > >gv
" Provide hjkl movements in Insert mode
inoremap <M-h> <Left>
inoremap <M-j> <Down>
inoremap <M-k> <Up>
inoremap <M-l> <Right>
" Split navigation
nnoremap <M-h> <C-w>h
nnoremap <M-j> <C-w>j
nnoremap <M-k> <C-w>k
nnoremap <M-l> <C-w>l
" Paste from clipboard with Shift + Insert
nnoremap <silent> <S-Insert> "+p
inoremap <silent> <S-Insert> <Esc>"+pa
" Move lines around easily
nnoremap <M-Up> :m-2<cr>==
nnoremap <M-Down> :m+<cr>==
xnoremap <M-Up> :m-2<cr>gv=gv
xnoremap <M-Down> :m'>+<cr>gv=gv
"" }}}
"" Plugins preferences ----- {{{
" Denite
" TODO: add shortcut
nnoremap <F2> :<C-u>Denite menu<CR>
" Change mappings.
call denite#custom#map(
\ 'insert',
\ '<C-j>',
\ '<denite:move_to_next_line>',
\ 'noremap'
\)
call denite#custom#map(
\ 'insert',
\ '<C-k>',
\ '<denite:move_to_previous_line>',
\ 'noremap'
\)
" Add custom menus
let s:menus = {}
let s:menus.zsh = {
\ 'description': 'Edit your import zsh configuration'
\ }
let s:menus.zsh.file_candidates = [
\ ['zshrc', '~/.zshrc'],
\ ['zshenv', '~/.zshenv'],
\ ]
let s:menus.commands = {
\ 'description': 'Custom commands'
\ }
let s:menus.commands.command_candidates = [
\ ['Split the window', 'vnew'],
\ ['Open zsh menu', 'Denite menu:zsh'],
\ ['Workspace', 'Denite menu:folders'],
\ ['Reveal file in sidebar', 'NERDTreeFind'],
\ ]
let s:menus.folders = {
\ 'description': 'Open file/folder/workspace'
\ }
let s:menus.folders.command_candidates = [
\ ['Open folder', 'CtrlPBookmarkDir'],
\ ['Add folder', 'CtrlPBookmarkDirAdd'],
\ ['Reveal file in sidebar', 'NERDTreeFind'],
\ ]
call denite#custom#var('menu', 'menus', s:menus)
" CtrlP
" TODO: read help and pick up some tips and trick
" Excluding version control directories
" See help for Windows pattern
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX
" TODO: remove 'target', 'dist' folders from custom ignore?
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](node_modules|target|dist)|(\.(swp|ico|git|hg|svn))$',
\ 'file': '\v\.(exe|so|dll)$',
\ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
\ }
" Setup ripgrep to use with CtrlP
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
nnoremap <Leader>b :CtrlPBuffer<CR>
" TODO: pick good shortcuts for `recent files`, `select folder` commands
" TODO: check CtrlP extensions
nnoremap <C-e> :CtrlPMRU<CR>
nnoremap <C-M-e> :CtrlPBookmarkDir<CR>
" Setup ctlp extensions
let g:ctrlp_extensions = ['bookmarkdir']
" NERDTree
" TODO: setup 'reveale in sidebar' shortcut
nnoremap <silent> <BS> :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
" TODO: what?
let g:NERDTreeWinSize=45
" Use deoplete
let g:deoplete#enable_at_startup = 1
" Neosnippets
" Tell Neosnippet about the other snippets
" let g:neosnippet#snippets_directory='~/.vim/bundle/neosnippet-snippets/neosnippets, ~/Github/ionic-snippets
" Neosnippet (don't use nore map!)
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
" TODO: !important
" set neosnippet dir for using 'quick edit' feature
if has('win32') || has('win64')
let g:neosnippet#snippets_directory = '$HOME\Documents\neosnippet-snippets\neosnippets'
else
let g:neosnippet#snippets_directory = '~/Projects/neosnippet-snippets/neosnippets'
endif
" Emmet
let g:user_emmet_mode='a' " enable all function in all mode
" I guest it's better not to define leader_key because <Tab> begin works slow,
" not instant
"let g:user_emmet_leader_key = '<C-i>'
let g:user_emmet_expandabbr_key = '<Tab>'
" Easygit
let g:easygit_enable_command = 1
"" }}}
"" Utils ------------------- {{{
" Save on focus lost
augroup save_on_focus_lost
autocmd!
autocmd BufWritePre,FocusLost * silent! wall
augroup END
" Restore cursor position when opening file
augroup restore_cursor_pos
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
"" }}}
augroup update_settings
autocmd!
autocmd bufwritepost init.vim source $MYVIMRC
autocmd bufwritepost ginit.vim source %
augroup END
"" Interface ------------------- {{{
set background=dark
if has('win32') || has('win64')
colorscheme base16-flat
else
colorscheme desert
endif
"
" set guifont in ginit.vim file
" TODO: add function that can easily can switch colorscheme
"" }}}
" TODO: doesn't work?
let g:indentLine_char="|"
" TODO:
" - add russian lang support
" - Plug 'w0rp/ale', { 'do': 'npm install -g prettier' }
" - check this vimrc https://github.com/kristijanhusak/neovim-config/blob/master/init.vim
" - check folding functions here: https://github.com/mhartington/dotfiles/blob/master/vimrc#L166
" - add lazyloading setting for emmet (see ciases config)
" - change colors when switching layout to 'ru' lang
"
" - install some git plugin and commit neosnippet changes
" - read help about Neosnippets
" - store dotfiles (.gitignore, .gitconfig, .vimrc, etc.) in bare git repo
" - reread sandwich.vim docs, because it's epic!
" - create denite menu for usefull but rare commands
" - check denite as file opener (as ctrlp)
" - add stars to plugins on GitHub
" - at the end read all plugin's documentation
" - add incsearch.vim plugin
" - add some search plugin (ctrlsf, far, ack?)
" - Windows: fix 'Insert' button (add hotkeys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment