init.vim (6330B) - raw


      1 " set leader prior to anything else
      2 let mapleader=","
      3 
      4 filetype plugin indent on
      5 augroup vimrc | autocmd! | augroup END  " reset all autocmd in this file
      6 
      7 " change default behaviours {{{
      8 
      9 set hidden                      " hide buffers instead of closing them
     10 set path+=**                    " find in subdirectories as well
     11 set mouse=""                    " gets rid of mouse, should be by default
     12 set incsearch                   " incremental search (on by default on neovim)
     13 
     14 " indentation
     15 set expandtab                   " insert spaces instead of tabs
     16 set tabstop=4                   " number of spaces when tab is pressed
     17 set shiftwidth=4                " number of spaces for indentation
     18 
     19 " line numbers
     20 set number                      " show line numbers
     21 set relativenumber              " show numbers relative to current line
     22 
     23 " line wrapping
     24 set wrap                        " wrap lines
     25 set linebreak                   " don't cut words when wrapping
     26 set breakindent                 " keeps indentation on wrapped lines
     27 
     28 " new splits position
     29 set splitbelow
     30 set splitright
     31 
     32 " smart case searching
     33 set ignorecase                  " required for smart case
     34 set smartcase
     35 
     36 " other useful defaults
     37 syntax on                       " syntax coloring
     38 set foldmethod=marker           " using {{{ and }}} to delimit folding areas
     39 set modeline                    " enable per-file settings with modeline
     40 set colorcolumn=81              " color column 81 differently
     41 set textwidth=80                " break lines longer than 80 characters, this is done to change behaviour of gq, see next line
     42 set formatoptions-=t            " don't break lines when longer than textwidth
     43 set nojoinspaces                " joining lines: no double space after period
     44 set scrolloff=3                 " minimum #lines between cursor and edge when scrolling
     45 
     46 " undo
     47 set undofile                    " save undos after file closes
     48 set undodir=~/.local/share/nvim/undo    " where to save undo histories
     49 
     50 " show blank characters when invisible
     51 set list
     52 set listchars=tab:>-,trail:·,extends:#,nbsp:.
     53 
     54 " switch : and ;
     55 nnoremap ; :
     56 nnoremap : ;
     57 vnoremap ; :
     58 vnoremap : ;
     59 nnoremap ñ :
     60 nnoremap Ñ :
     61 vnoremap ñ :
     62 nnoremap Ñ ;
     63 
     64 " filetypes
     65 augroup vimrc
     66     autocmd BufRead,BufNewFile *.zone set filetype=bindzone
     67 augroup END
     68 
     69 " filetype specific config
     70 augroup vimrc
     71     autocmd FileType markdown,vimwiki,mail,tex,text set formatoptions+=t  " break lines when longer than textwidth
     72     autocmd FileType markdown,vimwiki,html set tabstop=2 shiftwidth=2
     73     autocmd FileType html set textwidth=100 colorcolumn=101
     74     autocmd FileType mail set textwidth=72 colorcolumn=73
     75     autocmd FileType c set noexpandtab
     76     autocmd FileType help nnoremap q <Cmd>q<CR>
     77 augroup END
     78 
     79 " netrw config
     80 let g:netrw_liststyle=3         " tree structure
     81 let g:netrw_banner=0            " get rid of banner
     82 let g:netrw_winsize=20          " when on side, only use 20% of space
     83 let g:netrw_browse_split=4      " open files in previous window
     84 let g:netrw_bufsettings="nomodifiable nomodified number nobuflisted nowrap readonly relativenumber" " adds 'number' and 'relativenumber', other options are the default ones
     85 
     86 " /change default behaviours }}}
     87 
     88 " shortcuts {{{
     89 
     90 " set up vim-like commands to switch panes
     91 noremap <C-h> <C-w>h
     92 noremap <C-j> <C-w>j
     93 noremap <C-k> <C-w>k
     94 noremap <C-l> <C-w>l
     95 
     96 " resize pane
     97 noremap <silent> <C-Up> <Cmd>resize +3<CR>
     98 noremap <silent> <C-Down> <Cmd>resize -3<CR>
     99 noremap <silent> <C-Left> <Cmd>vertical resize +3<CR>
    100 noremap <silent> <C-Right> <Cmd>vertical resize -3<CR>
    101 
    102 " quickfix list
    103 noremap <Leader>j <Cmd>cnext<CR>zz
    104 noremap <Leader>k <Cmd>cprev<CR>zz
    105 noremap <Leader>q <Cmd>copen<CR>
    106 
    107 " undo
    108 nnoremap U <C-r>
    109 
    110 " search and replace all
    111 nnoremap S :%s//g<Left><Left>
    112 
    113 " edit/reload config file
    114 nnoremap <silent> <Leader>v <Cmd>e $MYVIMRC<CR>
    115 nnoremap <silent> <Leader>r <Cmd>so $MYVIMRC<CR>
    116 
    117 " edit file
    118 nnoremap <Leader>e <Cmd>Lexplore<CR>
    119 
    120 " clean search highlights
    121 nnoremap <silent> <Leader>/ <Cmd>nohlsearch<CR>
    122 
    123 " space to toggle fold
    124 nnoremap <Space> za
    125 
    126 " shortcuts for system clipboard
    127 nnoremap <Leader>y "+y
    128 nnoremap <Leader>p "+p
    129 vnoremap <Leader>y "+y
    130 vnoremap <Leader>p "+p
    131 
    132 " toggle mouse support
    133 function! ToggleMouse()
    134     if &mouse == ""
    135         set mouse=nv
    136         echo "Mouse activated"
    137     else
    138         set mouse=
    139         echo "Mouse desactivated"
    140     endif
    141 endfunc
    142 nnoremap <Leader>m <Cmd>call ToggleMouse()<CR>
    143 
    144 " /shortcuts }}}
    145 
    146 " colorscheme {{{
    147 
    148 augroup vimrc
    149     " Bold VimWiki titles
    150     autocmd FileType vimwiki call onedark#extend_highlight("Title", { "gui": "bold", "cterm": "bold" })
    151     " Blue VimWiki links
    152     autocmd FileType vimwiki call onedark#extend_highlight("Underlined", { "fg": onedark#GetColors().blue })
    153 augroup END
    154 
    155 colorscheme onedark
    156 set t_ut=""                     " deactivates vim BCE option (messes up colors)
    157 set termguicolors
    158 
    159 " /colorscheme }}}
    160 
    161 " status line {{{
    162 
    163 " let g:word_count=wordcount().words
    164 " function WordCount()
    165 "     if has_key(wordcount(), "visual_words")
    166 "         let g:word_count=wordcount().visual_words."/".wordcount().words " count selected words
    167 "     else
    168 "         let g:word_count=wordcount().cursor_words."/".wordcount().words " words up until cursor
    169 "     endif
    170 "     return g:word_count
    171 " endfunction
    172 
    173 set statusline=
    174 " text color setting
    175 set statusline+=%#PmenuSbar#
    176 " filename
    177 set statusline+=%F
    178 " file status
    179 set statusline+=%m
    180 " vertical spacing
    181 set statusline+=%=
    182 " text color setting
    183 set statusline+=%#CursorColumn#
    184 " number of words
    185 " set statusline+=w:%{WordCount()}
    186 " filetype
    187 set statusline+=\ %y
    188 " encoding
    189 " set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
    190 " file format
    191 " set statusline+=\[%{&fileformat}\]
    192 " column and row
    193 set statusline+=\ %c:%l/%L\ (%p%%)
    194 
    195 set laststatus=2                " activate status line
    196 
    197 " /status line }}}
    198 
    199 " templates {{{
    200 
    201 nnoremap <Leader>ts <Cmd>-1read $XDG_CONFIG_HOME/nvim/templates/shebang.sh<CR><Cmd>w<CR><Cmd>e<CR>
    202 nnoremap <Leader>tp <Cmd>-1read $XDG_CONFIG_HOME/nvim/templates/shebang.py<CR><Cmd>w<CR><Cmd>e<CR>
    203 nnoremap <Leader>tb <Cmd>-1read $XDG_CONFIG_HOME/nvim/templates/shebang.bash<CR><Cmd>w<CR><Cmd>e<CR>
    204 nnoremap <Leader>tw <Cmd>lua telescope_vimwiki_categories_picker()<CR>
    205 
    206 " /templates }}}
    207 
    208 " other {{{
    209 
    210 lua require("plugins")
    211 
    212 let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 1
    213 
    214 " /other }}}