Skip to content

Instantly share code, notes, and snippets.

@mesoclever
Created April 7, 2023 19:57
Show Gist options
  • Save mesoclever/0321aa86508bc47849be7d7dc689a63b to your computer and use it in GitHub Desktop.
Save mesoclever/0321aa86508bc47849be7d7dc689a63b to your computer and use it in GitHub Desktop.
Nvim configuration
"plugins
call plug#begin()
Plug 'https://github.com/neoclide/coc.nvim' " Auto Completio
Plug 'https://github.com/jiangmiao/auto-pairs'
Plug 'https://github.com/preservim/nerdtree' " NerdTree
Plug 'https://github.com/tpope/vim-commentary' " For Commenting gcc & gc
Plug 'https://github.com/vim-airline/vim-airline' " Status bar
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Scheme
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons
Plug 'https://github.com/preservim/tagbar' " Tagbar for code navigation
Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
Plug 'https://github.com/MunifTanjim/nui.nvim'
Plug 'https://github.com/erietz/vim-terminator'
"Plug 'https://github.com/rnvim-tree/nvim-web-devicons' " Recommended (for coloured icons)
"Plug 'https://github.com/ryanoasis/vim-devicons' "Icons without colours
Plug 'https://github.com/akinsho/bufferline.nvim', { 'tag': 'v3.*' }
Plug 'nvim-lua/plenary.nvim' "dependency for telescope
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' } "fuzzzy file search
Plug 'tiagovla/tokyodark.nvim' "github dark theme
Plug 'https://github.com/Pocco81/auto-save.nvim' "autosave plugin
Plug 'https://github.com/github/copilot.vim'
Plug 'projekt0n/github-nvim-theme', { 'tag': 'v0.0.7' }
Plug 'voldikss/vim-floaterm'
call plug#end()
:set number
:set autoindent
:set noexpandtab
:set tabstop=4
:set shiftwidth=4
:set scrolloff=5
:set backspace=indent,eol,start
:set fileformat=unix
:set splitbelow
:set termguicolors
syntax enable
set encoding=utf-8
colorscheme ayu
" run python
autocmd FileType python map <buffer> <F9> :w<CR>:exec '!/home/zar/code/python/venv/bin/python' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F9> <esc>:w<CR>:exec '!/home/zar/code/python/venv/bin/python' shellescape(@%, 1)<CR>
" find and replace text in visual mode
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
lua require"bufferline".setup()
let g:NERDTreeDirArrowExpandable="+"
let g:NERDTreeDirArrowCollapsible="~"
" floatterm shortcuts
" Open a terminal in a floating window
nnoremap <silent> <Leader>t :FloatermToggle<CR>
tnoremap <silent> <Leader>t <C-\><C-n>:FloatermToggle<CR>
" "telescope shortcuts
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
"nerdtree shortcuts
nnoremap <C-f> :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-l> :call CocActionAsync('jumpDefinition')<CR>
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
nmap <F8> :TagbarToggle<CR>
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code" Use K to show documentation in preview window.
nnoremap <silent> K :call ShowDocumentation()<CR>
" airline buffer switch
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
" Tab navigation airline.
nnoremap <A-[> :bprevious<CR>
nnoremap <A-]> :bnext<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" 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)
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
" Formatting selected code.
nmap <leader>f <Plug>(coc-format-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Run the Code Lens action on the current line.
nmap <leader>cl <Plug>(coc-codelens-action)
" Use autocomplete with tab
" not sure if this works
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" coc Remap <C-f> and <C-b> to 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment