From d9d9e898e591bb9f5d28b299dc44443dfe441630 Mon Sep 17 00:00:00 2001 From: praticamentetilde Date: Thu, 3 Jan 2019 17:38:39 +0100 Subject: [PATCH] Auto trim trailing spaces on save. Tab autocompletes when under a word. F2 cleans search pattern. Added i3config syntax plugin --- .gitmodules | 3 ++ init.vim | 55 +++++++++++++++++++++++++++------ pack/plugins/start/i3config.vim | 1 + 3 files changed, 49 insertions(+), 10 deletions(-) create mode 160000 pack/plugins/start/i3config.vim diff --git a/.gitmodules b/.gitmodules index 99565cb..124a010 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "pack/plugins/start/vimproc.vim"] path = pack/plugins/start/vimproc.vim url = https://github.com/Shougo/vimproc.vim.git +[submodule "pack/plugins/start/i3config.vim"] + path = pack/plugins/start/i3config.vim + url = https://github.com/mboughaba/i3config.vim.git diff --git a/init.vim b/init.vim index 3729f39..7e9cf48 100644 --- a/init.vim +++ b/init.vim @@ -1,4 +1,4 @@ -" vim: set tw=80 : +" vim: set et sw=2 ts=2 tw=80 : " SETTINGS @@ -32,12 +32,37 @@ set wildignore+=**/node_modules/** " ADDITIONAL COMMANDS +inoremap + " make escape work in terminal and send ESC to terminal with C-Esc tnoremap tnoremap -" clear search with F2 -nnoremap noh +" activate autocompletion using `key` when under a 'keyword' char +" (a-zA-Z + relevant characters for current language), otherwise just send TAB +function! AutocompleteIfKeyword() + let curcol = col('.') - 1 " column position before the cursor + if !curcol " if at the beginning of the line + return "\" " insert TAB character + elseif getline('.')[curcol - 1] =~ '\k' " if current character is a 'keyword' + return g:autocomplete_key " activate autocompletion for current word + else " if the current char is not a 'keyword' + return "\" " insert TAB characher + end +endfunction + +" autocomplete using `key` with tab if cursor is under a 'keyword' char. +" for = see: https://stackoverflow.com/questions/10862457 +inoremap =AutocompleteIfKeyword() + +" use standard vim autocomplete as fallback +let g:autocomplete_key = "\" + +" autocomplete with Tsuquyomi on TypeScript files +autocmd FileType typescript let g:autocomplete_key = "\\" + +" clear search pattern with F2 +noremap :let @/ = "" " Use "," as leader let mapleader = "," @@ -46,22 +71,32 @@ let mapleader = "," nnoremap w " Show next buffer with: Leader n -nnoremap n :bn +nnoremap n :bn + +" Fix indentation with: Leader i +nnoremap i mzgg=G`z " Delete buffer with: Leader d -nnoremap d :bd +nnoremap d :bd -" clear trailing spaces with: Leader t s -nnoremap ts :%s/\s *$//g +" clear trailing spaces in file +function! g:ClearTrailingSpaces() + silent! %s/\s *$//g + let @/ = "" " clear last search +endfunction + +" remove trailing spaces with: Leader t s +nnoremap ts :call ClearTrailingSpaces() + +" automatically remove trailing spaces when saving a file +autocmd BufWrite * call ClearTrailingSpaces() " Reload config with: Leader R -nnoremap R :source ~/.config/nvim/init.vim +nnoremap R :source ~/.config/nvim/init.vim " show Vim's true competitor with: Leader r c m nnoremap rcm :!open https://youtu.be/jn40Ugz0vuk -autocmd FileType typescript imap - " COLORSCHEME " set colorscheme to onedark.im for nvim and airline diff --git a/pack/plugins/start/i3config.vim b/pack/plugins/start/i3config.vim new file mode 160000 index 0000000..c68bbb5 --- /dev/null +++ b/pack/plugins/start/i3config.vim @@ -0,0 +1 @@ +Subproject commit c68bbb54d97ab8cea46b866e86a584f4d7a9db4a