From f4dd4f0804d41910f4fe5d81022659066e0aeb48 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Thu, 26 Oct 2023 13:53:14 +0200 Subject: [PATCH] add nvim config --- .config/nvim/init.vim | 592 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 592 insertions(+) create mode 100644 .config/nvim/init.vim diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim new file mode 100644 index 0000000..3d51d28 --- /dev/null +++ b/.config/nvim/init.vim @@ -0,0 +1,592 @@ +let mapleader ="," + +if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"')) + echo "Downloading junegunn/vim-plug to manage plugins..." + silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/ + silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim + autocmd VimEnter * PlugInstall +endif + +call plug#begin(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"')) +Plug 'tpope/vim-surround' +Plug 'preservim/nerdtree' +Plug 'junegunn/goyo.vim' +Plug 'jreybert/vimagit' +Plug 'lukesmithxyz/vimling' +Plug 'vimwiki/vimwiki' +Plug 'vim-airline/vim-airline' +Plug 'tpope/vim-commentary' +Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'} +Plug 'ap/vim-css-color' +Plug 'lervag/vimtex' +Plug 'arcticicestudio/nord-vim' +Plug 'rhysd/vim-grammarous' +Plug 'jalvesaq/Nvim-R', {'branch': 'stable'} +Plug 'luk400/vim-jukit' +Plug 'yaegassy/coc-astro', {'do': 'yarn install --frozen-lockfile'} +call plug#end() + +set title +set bg=light +set go=a +set mouse=a +set nohlsearch +set clipboard+=unnamedplus +set noshowmode +set noruler +set laststatus=0 +set noshowcmd +set undofile +colorscheme nord + +" Some basics: + nnoremap c "_c + set nocompatible + filetype plugin on + syntax on + set encoding=utf-8 + set number relativenumber + " respects camel case as different words + set iskeyword-=_ + + +" Enable autocompletion: + set wildmode=longest,list,full +" Disables automatic commenting on newline: + autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o +" Perform dot commands over visual blocks: + vnoremap . :normal . +" Goyo plugin makes text more readable when writing prose: + map f :Goyo \| set bg=light \| set linebreak +" Spell-check set to o, 'o' for 'orthography': + map o :setlocal spell! spelllang=en_us +" Splits open at the bottom and right, which is non-retarded, unlike vim defaults. + set splitbelow splitright + +" Python Notebooks using jukit +let g:_jukit_python_os_cmd = 'python' +let g:jukit_shell_cmd = 'ipython' +" - Specifies the command used to start a shell in the output split. Can also be an absolute path. Can also be any other shell command, e.g. `R`, `julia`, etc. (note that output saving is only possible for ipython) +let g:jukit_terminal = 'nvimterm' +" - Terminal to use. Can be one of '', 'kitty', 'vimterm', 'nvimterm' or 'tmux'. If '' is given then will try to detect terminal (though this might fail, in which case it simply defaults to 'vimterm' or 'nvimterm' - depending on the output of `has("nvim")`) +let g:jukit_auto_output_hist = 0 +" - If set to 1, will create an autocmd with event `CursorHold` to show saved ipython output of current cell in output-history split. Might slow down (n)vim significantly, you can use `set updatetime=` to control the time to wait until CursorHold events are triggered, which might improve performance if set to a higher number (e.g. `set updatetime=1000`). +let g:jukit_use_tcomment = 0 +" - Whether to use tcomment plugin (https://github.com/tomtom/tcomment_vim) to comment out cell markers. If not, then cell markers will simply be prepended with `g:jukit_comment_mark` +let g:jukit_comment_mark = '#' +" - See description of `g:jukit_use_tcomment` above +let g:jukit_mappings = 1 +" - If set to 0, none of the default function mappings (as specified further down) will be applied +let g:jukit_mappings_ext_enabled = "*" +" - String or list of strings specifying extensions for which the mappings will be created. For example, `let g:jukit_mappings_ext_enabled=['py', 'ipynb']` will enable the mappings only in `.py` and `.ipynb` files. Use `let g:jukit_mappings_ext_enabled='*'` to enable them for all files. + +let g:jukit_highlight_markers = 1 +" - Whether to highlight cell markers or not. You can specify the colors of cell markers by putting e.g. `highlight jukit_cellmarker_colors guifg=#1d615a guibg=#1d615a ctermbg=22 ctermfg=22` with your desired colors in your (neo)vim config. Make sure to define this highlight *after* loading a colorscheme in your (neo)vim config +let g:jukit_enable_textcell_bg_hl = 0 +let g:jukit_textcell_bg_colors_guibg='#888888' +let g:jukit_textcell_bg_colors_ctermbg='#ffffff' +" - Whether to highlight background of textcells. You can specify the color by putting `highlight jukit_textcell_bg_colors guibg=#131628 ctermbg=0` with your desired colors in your (neo)vim config. Make sure to define this highlight group *after* loading a colorscheme in your (neo)vim config. +let g:jukit_enable_textcell_syntax = 1 +" - Whether to enable markdown syntax highlighting in textcells +let g:jukit_text_syntax_file = $VIMRUNTIME . '/syntax/' . 'markdown.vim' +" - Syntax file to use for textcells. If you want to define your own syntax matches inside of text cells, make sure to include `containedin=textcell`. +let g:jukit_hl_ext_enabled = '*' +" - String or list of strings specifying extensions for which the relevant highlighting autocmds regarding marker-highlighting, textcell-highlighting, etc. will be created. For example, `let g:jukit_hl_extensions=['py', 'R']` will enable the defined highlighting options for `.py` and `.R` files. Use `let g:jukit_hl_extensions='*'` to enable them for all files and `let g:jukit_hl_extensions=''` to disable them completely +let g:jukit_convert_overwrite_default = -1 +" - Default setting when converting from .ipynb to .py or vice versa and a file of the same name already exists. Can be of [-1, 0, 1], where -1 means no default (i.e. you'll be prompted to specify what to do), 0 means never overwrite, 1 means always overwrite +let g:jukit_convert_open_default = -1 + +let g:jukit_hist_use_ueberzug = 1 +" - Set to 1 to use Überzug to display saved outputs instead of an ipython split window +let g:jukit_ueberzug_use_cached = 1 +" - Whether to cache created images of saved outputs. If set to 0, will convert saved outputs to png from scratch each time. Note that this will make displaying saved outputs significantly slower. +let g:jukit_ueberzug_pos = [0.25, 0.25, 0.4, 0.6] +" - position and dimension of Überzug window WITH output split present - [x, y, width, height]. Use `:call jukit#ueberzug#set_default_pos()` to modify/visualize. +let g:jukit_ueberzug_pos_noout = [0.25, 0.25, 0.4, 0.6] +" - position and dimension of Überzug window WITHOUT output split present - [x, y, width, height]. Use `:call jukit#ueberzug#set_default_pos()` to modify/visualize. +let g:jukit_kill_ueberzug_on_focus_lost = 1 +" - whether to kill ueberzug when the focus to neovim is lost (detecting focus might only work on neovim). if set to 0, the ueberzug image keeps being displayed even when neovim loses focus (e.g. when switching tabs in terminal). + +let g:jukit_ueberzug_border_color = get(g:, 'jukit_ueberzug_border_color', 'blue') +" - border color of Überzug images +let g:jukit_ueberzug_theme = 'dark' +" - choose dark or light theme for markdown cells +let g:jukit_ueberzug_term_hw_ratio = -1 +" - this is relevant in case the shown ueberzug image is cut off horizontally. In that case, the determined width/height ratio of your terminal cells is determined incorrectly. A value of -1 means the ratio should be determined automatically. A ratio of 2.2 is used by default if the ratio can't be determined automatically. If you get a cut off image, try setting this parameter and vary the values around 2.0 (e.g. `let g:jukit_ueberzug_term_hw_ratio = 2.3` or `let g:jukit_ueberzug_term_hw_ratio = 1.9`) until the image is displayed correctly to determine your needed ratio. +let g:jukit_ueberzug_python_cmd = 'python3' +" - path to python3 executable for which the überzug requirements (beautifulsoup4, pillow, ueberzug) are installed. By default it just uses the python3 command found in your environment. If you started an output split in a virtual environment, make sure that you either have all the requirements in the virtual requirements or set the absolute path to the python3 command. +let g:jukit_ueberzug_jupyter_cmd = 'jupyter' +" - path to jupyter executable. By default it just uses the jupyter command found in your environment. If you started an output split in a virtual environment, make sure that you either have jupyter installed in that environment or set the absolute path to the python3 command. +let g:jukit_ueberzug_cutycapt_cmd = 'CutyCapt' +" - path to cutycapt executable +let g:jukit_ueberzug_imagemagick_cmd = 'convert' +" - path to imagemagick (`convert` command) executable + +" Nerd tree + map n :NERDTreeToggle + autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif + if has('nvim') + let NERDTreeBookmarksFile = stdpath('data') . '/NERDTreeBookmarks' + else + let NERDTreeBookmarksFile = '~/.vim' . '/NERDTreeBookmarks' + endif + +" Nvim-R Defintions for R IDE +let g:R_assign = 3 " do (not) map _ to <- for assignment +vmap RDSendSelection +nmap RDSendLine +let R_nvimpager = 'tab' " display R docs in new tab +let R_start_libs = 'base,stats,graphics,grDevices,utils,methods' +let R_hl_term = 0 +" let Rout_more_colors = 1 + +" AirLatex +" your login-name +let g:AirLatexUsername="cookies:overleaf_session2=s%3AMANcnaAAj4VeIgXsNIiCINZ0QgwtYNzn.9x0PVRqOp8egbGYpnIHuffJUxmH%2F%2F2W%2FFnTBPmDny1M" + +"This allows for change paste motion cp{motion} +nmap cp :set opfunc=ChangePasteg@ +function! ChangePaste(type, ...) + silent exe "normal! `[v`]\"_c" + silent exe "normal! p" +endfunction + +" optional: set server name +let g:AirLatexDomain="www.overleaf.com" + +let g:AirLatexAllowInsecure=0 + +" vimtex: +let g:vimtex_view_method = 'zathura' +let g:vimtex_compiler_latexmk = { 'build_dir' : '', + \ 'callback' : 1, + \ 'continuous' : 1, + \ 'executable' : 'latexmk', + \ 'hooks' : [], + \ 'options' : [ + \ '-pdflatex="pdflatex --shell-escape %O %S"', + \ '-verbose', + \ '-file-line-error', + \ '-synctex=1', + \ '-interaction=nonstopmode', + \ ], + \} + + +" vimling: + "nm d :call ToggleDeadKeys() + "imap d :call ToggleDeadKeys()a + "nm i :call ToggleIPA() + "imap i :call ToggleIPA()a + "nm q :call ToggleProse() + +" Shortcutting split navigation, saving a keypress: + map h + map j + map k + map l + +" Replace ex mode with gq + map Q gq + +" Check file in shellcheck: + map s :!clear && shellcheck -x % + +" Open my bibliography file in split + map b :!( st nvim $BIB & ) > /dev/null 2>&1 + map r :vsp$REFER + +" Replace all is aliased to S. + nnoremap S :%s//g + +" Compile document, be it groff/LaTeX/markdown/etc. + map c :w! \| !compiler "%" + +" Open corresponding .pdf/.html or preview + map p :!opout % + +" start browser-sync for easier refresh with web-dev + nnoremap bs :!browser-sync start --server --files . > /dev/null 2>&1 & +" Runs a script that cleans out tex build files whenever I close out of a .tex file. + autocmd VimLeave *.tex !texclear % + +" Ensure files are read as what I want: + let g:vimwiki_ext2syntax = {'.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'} + map v :VimwikiIndex + let g:vimwiki_list = [{'path': '~/vimwiki', 'syntax': 'markdown', 'ext': '.md'}] + autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown + autocmd BufRead,BufNewFile *.ms,*.me,*.mom,*.man set filetype=groff + autocmd BufRead,BufNewFile *.tex set filetype=tex + +" Save file as sudo on files that require root permission + cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' edit! + +" Enable Goyo by default for mutt writing + autocmd BufRead,BufNewFile /tmp/neomutt* let g:goyo_width=80 + autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo | set bg=light + autocmd BufRead,BufNewFile /tmp/neomutt* map ZZ :Goyo\|x! + autocmd BufRead,BufNewFile /tmp/neomutt* map ZQ :Goyo\|q! + +" Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position + autocmd BufWritePre * let currPos = getpos(".") + autocmd BufWritePre * %s/\s\+$//e + autocmd BufWritePre * %s/\n\+\%$//e + autocmd BufWritePre *.[ch] %s/\%$/\r/e + autocmd BufWritePre * cal cursor(currPos[1], currPos[2]) + +" When shortcut files are updated, renew bash and ranger configs with new material: + autocmd BufWritePost bm-files,bm-dirs !shortcuts +" Run xrdb whenever Xdefaults or Xresources are updated. + autocmd BufRead,BufNewFile Xresources,Xdefaults,xresources,xdefaults set filetype=xdefaults + autocmd BufWritePost Xresources,Xdefaults,xresources,xdefaults !xrdb % +" Recompile dwmblocks on config edit. + autocmd BufWritePost ~/.local/src/dwmblocks/config.h !cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid -f dwmblocks } + +" Navigating with guides + inoremap /<++>"_c4l + vnoremap /<++>"_c4l + map /<++>"_c4l + + +" Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable. +if &diff + highlight! link DiffText MatchParen +endif + +" Function for toggling the bottom statusbar: +let s:hidden_all = 1 +function! ToggleHiddenAll() + if s:hidden_all == 0 + let s:hidden_all = 1 + set noshowmode + set noruler + set laststatus=0 + set noshowcmd + else + let s:hidden_all = 0 + set showmode + set ruler + set laststatus=2 + set showcmd + endif +endfunction +nnoremap h :call ToggleHiddenAll() +"""LATEX + " Word count: + autocmd FileType tex map w :w !detex \| wc -w + " Code snippets + """autocmd FileType tex inoremap ,fr \begin{frame}\frametitle{}<++>\end{frame}<++>6kf}i + autocmd FileType tex inoremap ,fi \begin{fitch}\end{fitch}<++>3kA + autocmd FileType tex inoremap ,exe \begin{exe}\ex\end{exe}<++>3kA + autocmd FileType tex inoremap ,bf \textbf{}<++>T{i + autocmd FileType tex vnoremap , ``>2la}?\\{a + autocmd FileType tex inoremap ,it \textit{}<++>T{i + autocmd FileType tex inoremap ,ct \textcite{}<++>T{i + autocmd FileType tex inoremap ,cp \parencite{}<++>T{i + autocmd FileType tex inoremap ,glos {\gll<++>\\<++>\\\trans{``<++>''}}2k2bcw + autocmd FileType tex inoremap ,x \begin{xlist}\ex\end{xlist}kA + autocmd FileType tex inoremap ,ol \begin{enumerate}\end{enumerate}<++>3kA\item + autocmd FileType tex inoremap ,ul \begin{itemize}\end{itemize}<++>3kA\item + autocmd FileType tex inoremap ,li \item[] + autocmd FileType tex inoremap ,ref \ref{}<++>T{i + autocmd FileType tex inoremap ,tab \begin{tabular}<++>\end{tabular}<++>4kA{}i + autocmd FileType tex inoremap ,ot \begin{tableau}\inp{<++>}\const{<++>}<++><++>\end{tableau}<++>5kA{}i + autocmd FileType tex inoremap ,can \cand{}<++>T{i + autocmd FileType tex inoremap ,con \const{}<++>T{i + autocmd FileType tex inoremap ,v \vio{}<++>T{i + autocmd FileType tex inoremap ,a \href{}{<++>}<++>2T{i + autocmd FileType tex inoremap ,sc \textsc{}<++>T{i + autocmd FileType tex inoremap ,chap \chapter{}<++>2kf}i + autocmd FileType tex inoremap ,sec \section{}<++>2kf}i + autocmd FileType tex inoremap ,ssec \subsection{}<++>2kf}i + autocmd FileType tex inoremap ,sssec \subsubsection{}<++>2kf}i + autocmd FileType tex inoremap ,st F{i*f}i + autocmd FileType tex inoremap ,beg \begin{DELRN}<++>\end{DELRN}<++>4k0fR:MultipleCursorsFindDELRNc + autocmd FileType tex inoremap ,up /usepackageo\usepackage{}i + autocmd FileType tex nnoremap ,up /usepackageo\usepackage{}i + autocmd FileType tex inoremap ,tt \texttt{}<++>T{i + autocmd FileType tex inoremap ,bt {\blindtext} + autocmd FileType tex inoremap ,nu $\varnothing$ + autocmd FileType tex inoremap ,col \begin{columns}[T]\begin{column}{.5\textwidth}\end{column}\begin{column}{.5\textwidth}<++>\end{column}\end{columns}5kA + autocmd FileType tex inoremap ,rn (\ref{})<++>F}i + autocmd FileType tex inoremap ,fr \dfrac{}{<++>} <++> T{2hi + autocmd FileType tex inoremap ,sqrt \sqrt{}<++> T{i + autocmd FileType tex inoremap ,b( \left(\right)<++>T(i + autocmd FileType tex inoremap ,bb \mathbb{}<++>T{i + autocmd FileType tex inoremap ,b{ \left\{\right\}<++>T{i + autocmd FileType tex inoremap ,b[ \left[\right]<++>T[i + autocmd FileType tex inoremap ,rm \mathrm{}<++>T{i + autocmd FileType tex inoremap ,abs \left\|\right\|<++>3ba + autocmd FileType tex inoremap ,em \emph{}<++>T{i + autocmd FileType tex inoremap ,tabb \begin{tabbing}\hspace*{3cm}\=\hspace*{3cm}\= \kill\end{tabbing}<++>3kA + autocmd FileType tex inoremap ,txt \text{}<++>T{i + autocmd FileType tex inoremap ,sfr \sfrac{}{<++>}<++>2T{i + + + + +"""HTML + autocmd FileType html inoremap ,b <++>FbT>i + autocmd FileType html inoremap ,it <++>FeT>i + autocmd FileType html inoremap ,1

<++>2kf<++>2kf<++>2kf

<++>02kf>a + autocmd FileType html inoremap ,a href=""><++><++>14hi + autocmd FileType html inoremap ,e target="_blank"href=""><++><++>14hi + autocmd FileType html inoremap ,ul
<++>03kfo
  • F>a + autocmd FileType html inoremap ,ol
    <++>03kf<++>Fcf"a + autocmd FileType html inoremap ,td <++>Fdcit + autocmd FileType html inoremap ,tr <++>kf<++>Fhcit + autocmd FileType html inoremap ,tab
    O + autocmd FileType html inoremap ,gr F>a + autocmd FileType html inoremap ,rd F>a + autocmd FileType html inoremap ,yl F>a + autocmd FileType html inoremap ,dt
    <++>
    <++>2kcit + autocmd FileType html inoremap ,dl
    <++>3kcc + "autocmd FileType html inoremap & & + autocmd FileType html inoremap ,fr <++><++>2T/2hi + autocmd FileType html inoremap ,o + autocmd FileType html inoremap ,cr + autocmd FileType html inoremap ,pl

    Taa + autocmd FileType html inoremap ,pd

    Tea + autocmd FileType html inoremap ,dg °C + "autocmd FileType html inoremap á á + "autocmd FileType html inoremap é é + "autocmd FileType html inoremap í í + "autocmd FileType html inoremap ó ó + "autocmd FileType html inoremap ú ú + "autocmd FileType html inoremap ä ä + "autocmd FileType html inoremap ë ë + "autocmd FileType html inoremap ï ï + "autocmd FileType html inoremap ö ö + "autocmd FileType html inoremap ü ü + "autocmd FileType html inoremap ã ã + "autocmd FileType html inoremap ẽ &etilde; + "autocmd FileType html inoremap ĩ ĩ + "autocmd FileType html inoremap õ õ + "autocmd FileType html inoremap ũ ũ + "autocmd FileType html inoremap ñ ñ + "autocmd FileType html inoremap à à + "autocmd FileType html inoremap è è + "autocmd FileType html inoremap ì ì + "autocmd FileType html inoremap ò ò + "autocmd FileType html inoremap ù ù + + +""".bib + autocmd FileType bib inoremap ,a @article{author={<++>},year={<++>},title={<++>},journal={<++>},volume={<++>},pages={<++>},}<++>8kA,i + autocmd FileType bib inoremap ,b @book{author={<++>},year={<++>},title={<++>},publisher={<++>},}<++>6kA,i + autocmd FileType bib inoremap ,c @incollection{author={<++>},title={<++>},booktitle={<++>},editor={<++>},year={<++>},publisher={<++>},}<++>8kA,i + +"MARKDOWN + autocmd Filetype markdown,rmd map w yiWi[Ea](pa) + autocmd Filetype markdown,rmd inoremap ,n --- + autocmd Filetype markdown,rmd inoremap ,b ****<++>F*hi + autocmd Filetype markdown,rmd inoremap ,s ~~~~<++>F~hi + autocmd Filetype markdown,rmd inoremap ,e **<++>F*i + autocmd Filetype markdown,rmd inoremap ,h ====<++>F=hi + autocmd Filetype markdown,rmd inoremap ,i ![](<++>)<++>F[a + autocmd Filetype markdown,rmd inoremap ,a [](<++>)<++>F[a + autocmd Filetype markdown,rmd inoremap ,1 #<++>kA + autocmd Filetype markdown,rmd inoremap ,2 ##<++>kA + autocmd Filetype markdown,rmd inoremap ,3 ###<++>kA + autocmd Filetype markdown,rmd inoremap ,l -------- + autocmd Filetype markdown,rmd inoremap ,r ```{r}```2kO + autocmd Filetype markdown,rmd inoremap ,p ```{python}```2kO + autocmd Filetype mardown,rmd inoremap ,c ``````2kO + +""".xml + autocmd FileType xml inoremap ,e <++>isPermaLink="false"><++>:put=strftime('%a, %d %b %Y %H:%M:%S %z')kJA<++>]]>?<enter>cit + autocmd FileType xml inoremap ,a <a href="<++>"><++></a><++><Esc>F"ci" + + +"""I like COC +let g:coc_global_extensions = ['coc-json', 'coc-texlab', 'coc-svg', 'coc-docker', 'coc-lua', 'coc-perl', 'coc-r-lsp', 'coc-tsserver', 'coc-emmet', 'coc-clangd', 'coc-html-css-support', 'coc-go', 'coc-css', 'coc-perl', 'coc-yaml', 'coc-svelte', 'coc-sql'] +" Set internal encoding of vim, not needed on neovim, since coc.nvim using some +" unicode characters in the file autoload/float.vim +set encoding=utf-8 + +" TextEdit might fail if hidden is not set. +set hidden + +" Some servers have issues with backup files, see #649. +set nobackup +set nowritebackup + +" Give more space for displaying messages. +set cmdheight=2 + +" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable +" delays and poor user experience. +set updatetime=300 + +" Don't pass messages to |ins-completion-menu|. +set shortmess+=c + +" Always show the signcolumn, otherwise it would shift the text each time +" diagnostics appear/become resolved. +if has("nvim-0.5.0") || has("patch-8.1.1564") + " Recently vim can merge signcolumn and number column into one + set signcolumn=number +else + set signcolumn=yes +endif + +" Use tab for trigger completion with characters ahead and navigate. +" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by +" other plugin before putting this into your config. +inoremap <silent><expr> <TAB> + \ pumvisible() ? "\<C-n>" : + \ "\<tab>" +inoremap <expr><S-tab> pumvisible() ? "\<C-p>" : "\<C-h>" + +" Use <c-space> to trigger completion. +if has('nvim') + inoremap <silent><expr> <c-space> pumvisible() ? coc#_select_confirm() + \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" +else + inoremap <silent><expr> <c-@> coc#refresh() +endif + +" Make <CR> auto-select the first completion item and notify coc.nvim to +" format on enter, <cr> could be remapped by other vim plugin +inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() + \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" + +" 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 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) + +" Use K to show documentation in preview window. +nnoremap <silent> K :call <SID>show_documentation()<CR> + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('<cword>') + elseif (coc#rpc#ready()) + call CocActionAsync('doHover') + else + execute '!' . &keywordprg . " " . expand('<cword>') + endif +endfunction + +" Highlight the symbol and its references when holding the cursor. +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming. +nmap <leader>rn <Plug>(coc-rename) + +" Formatting selected code. +xmap <leader>f <Plug>(coc-format-selected) +nmap <leader>f <Plug>(coc-format-selected) + +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 + +" Applying codeAction to the selected region. +" Example: `<leader>aap` for current paragraph +xmap <leader>a <Plug>(coc-codeaction-selected) +nmap <leader>a <Plug>(coc-codeaction-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) + +" Map function and class text objects +" NOTE: Requires 'textDocument.documentSymbol' support from the language server. +xmap if <Plug>(coc-funcobj-i) +omap if <Plug>(coc-funcobj-i) +xmap af <Plug>(coc-funcobj-a) +omap af <Plug>(coc-funcobj-a) +xmap ic <Plug>(coc-classobj-i) +omap ic <Plug>(coc-classobj-i) +xmap ac <Plug>(coc-classobj-a) +omap ac <Plug>(coc-classobj-a) + +" 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 + +" Use CTRL-S for selections ranges. +" Requires 'textDocument/selectionRange' support of language server. +nmap <silent> <C-s> <Plug>(coc-range-select) +xmap <silent> <C-s> <Plug>(coc-range-select) + +" Add `:Format` command to format current buffer. +command! -nargs=0 Format :call CocActionAsync('format') + +" 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') + +" Add (Neo)Vim's native statusline support. +" NOTE: Please see `:h coc-status` for integrations with external plugins that +" provide custom statusline: lightline.vim, vim-airline. +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} + + +"powerline symbols +if !exists('g:airline_symbols') +let g:airline_symbols = {} +endif + +let g:airline_left_sep = '' +let g:airline_left_alt_sep = '' +let g:airline_right_sep = '' +let g:airline_right_alt_sep = '' +let g:airline_symbols.branch = '' +let g:airline_symbols.readonly = '' +let g:airline_symbols.linenr = '' +"let g:airline_symbols.maxlinenr = ' ' +let g:airline_symbols.maxlinenr = '' +let g:airline_symbols.colnr = ':' + +" Mappings for CoCList +" Show all diagnostics. +nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> +" Manage extensions. +nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> +" Show commands. +nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> +" Find symbol of current document. +nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> +" Search workspace symbols. +nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> +" Do default action for next item. +nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> +" Do default action for previous item. +nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> +" Resume latest coc list. +nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR> + +inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" + +inoremap <silent><expr> <NUL> coc#refresh()