From 32de71752457551f96433f9aff5fba81950d8245 Mon Sep 17 00:00:00 2001 From: Oxbian Date: Tue, 25 Jul 2023 00:02:49 +0200 Subject: Setting up formatting for python --- .vim/after/ftplugin/python.vim | 12 +++++++++++- .vim/keymaps.vim | 41 +++++++++++++++++++---------------------- .vim/plugins.vim | 18 +++++++++--------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/.vim/after/ftplugin/python.vim b/.vim/after/ftplugin/python.vim index bd158fa..41b1d88 100644 --- a/.vim/after/ftplugin/python.vim +++ b/.vim/after/ftplugin/python.vim @@ -1,5 +1,4 @@ " Python - let g:lsp_settings = {} let g:lsp_settings['pylsp-all'] = \ { @@ -18,3 +17,14 @@ let g:lsp_settings['pylsp-all'] = \ } \ }} \ } + +" Define a custom function that executes :LspDocumentFormat and :!isort +if !exists('*FormatPythonFile') + function! FormatPythonFile() + silent execute '!black %' + silent execute '!isort %' + endfunction +endif +" Remap the custom function to ldf +nnoremap ldf :call FormatPythonFile() + diff --git a/.vim/keymaps.vim b/.vim/keymaps.vim index 57f9e8d..5827003 100644 --- a/.vim/keymaps.vim +++ b/.vim/keymaps.vim @@ -38,47 +38,47 @@ nnoremap :w! """"""""""""""""""""""""" " Close the current buffer -map bd :Bclose:tabclosegT +noremap bd :Bclose:tabclosegT " Close all the buffers -map ba :bufdo bd +noremap ba :bufdo bd " Go to the next buffer -map bn :bnext +noremap bn :bnext " Go to the previous buffer -map bp :bprevious +noremap bp :bprevious """""""""""""""""""""""""""" " Tabs """"""""""""""""""""""""""" " Open a new tab -map tn :tabnew +noremap tn :tabnew " Close all others tab -map to :tabonly +noremap to :tabonly " Close current tab page -map tc :tabclose +noremap tc :tabclose " Move tabs after another -map tm :tabmove +noremap tm :tabmove " Go to the next tab -map t :tabnext +noremap t :tabnext " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 -nmap tl :exe "tabn ".g:lasttab +nnoremap tl :exe "tabn ".g:lasttab au TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory -map te :tabedit =escape(expand("%:p:h"), " ")/ +noremap te :tabedit =escape(expand("%:p:h"), " ")/ " Switch CWD to the directory of the open buffer -map cd :cd %:p:h:pwd +noremap cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try @@ -91,10 +91,10 @@ endtry au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif """""""""""""""""""""""" -" NerdTree +" Fern """"""""""""""""""""""" -" Toggle nerdtree +" Toggle fern tree view nnoremap :Fern . """""""""""""""""""" @@ -129,19 +129,19 @@ set laststatus=2 """"""""""""""""""""" " Toggle and untoggle spell checking -map ss :setlocal spell! +noremap ss :setlocal spell! " Next word to spellcheck -map sn ]s +noremap sn ]s " Previous word to spellcheck -map sp [s +noremap sp [s " Add word into the spellcheck dictionnary -map sa zg +noremap sa zg " show the list of alternatives for the word -map s? z= +noremap s? z= """"""""""""""""""" " LSP @@ -177,6 +177,3 @@ nnoremap la :LspCodeAction " Hover information nnoremap lh :LspHover -" Format document -nnoremap ldf :LspDocumentFormat - diff --git a/.vim/plugins.vim b/.vim/plugins.vim index 5d17b17..add6b38 100644 --- a/.vim/plugins.vim +++ b/.vim/plugins.vim @@ -79,15 +79,15 @@ let g:fern_renderer_devicons_disable_warning = 1 " Multi window select in which you open the file function! s:init_fern() abort " Use 'select' instead of 'edit' for default 'open' action - nmap (fern-action-open) (fern-action-open:select) - - nmap a (fern-action-new-path) - nmap d (fern-action-remove) - nmap m (fern-action-move) - nmap r (fern-action-rename) - nmap v (fern-action-open:vsplit) - nmap ga (fern-action-git-stage) - nmap gd (fern-action-git-unstage) + nnoremap (fern-action-open) (fern-action-open:select) + + nnoremap a (fern-action-new-path) + nnoremap d (fern-action-remove) + nnoremap < m (fern-action-move) + nnoremap r (fern-action-rename) + nnoremap v (fern-action-open:vsplit) + nnoremap ga (fern-action-git-stage) + nnoremap gd (fern-action-git-unstage) endfunction augroup my-fern-hijack -- cgit v1.2.3