1

jedi-vim appears to prevent mapping [[ to # and ]] to *

mapping does not alter behaviour produced by [[ or ]] in .py files when jedi-vim in bundle folder (and does alter behaviour in .py files otherwise). Mapping succeeds in altering behaviour on other filetypes (tex files), but not on files with no suffix, whether or not jedi-vim is in plugin folder (~/.vim/bundle).

full vimrc here

" **** BEGIN PLUGIN SECTION ****
" plugins first so they can be overridden with personal settings later
execute pathogen#infect()
execute pathogen#helptags()

" this is for jedi-vim (python autocomplete [Ctrl-space] and \g \d K \n )
let g:jedi#force_py_version = 3
let g:jedi#show_call_signatures = 2
set completeopt=menuone,longest

" this is for supertab, and to get it to use jedi-vim omnicompletion
" this still does not perform as desired - work in progress
" let g:SuperTabDefaultCompletionType = "context"
" this should force supertab to use jedi omnifunc for completion hmm . . .
" let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"


" some vimtex setting - I only use the most basic features of vimtex so its
" just barely functional. vimtex helps with writing latex
let g:tex_flavor="latex"
" **** END PLUGIN SECTION ****


let mapleader = "\\"
set expandtab
set shiftwidth=4
set tabstop=4
set softtabstop=4
set number
set noerrorbells visualbell t_vb=
set autoindent
set ignorecase
set smartcase
syntax on
set t_Co=256
set background=dark
set mouse=a
colorscheme gruvbox


" movements
nnoremap ' `
onoremap ' `
nnoremap " '
onoremap " '
nnoremap ` "
onoremap ` "
vnoremap ` "
onoremap p i(
nnoremap <Up> gk
nnoremap <Down> gj
noremap <PageUp> <C-y>
noremap <PageDown> <C-e>
nnoremap <Home> 10<C-y>
nnoremap <End> 10<C-e>
nnoremap Y y$

" these next two lines dont work and it sends me crazy
nnoremap [[ #
nnoremap ]] *

" search for prev[ or next] non-whitespace in the current column
" often used to find next line with same indent (python block)
nnoremap [<Bslash> :call search('\%' . virtcol('.') . 'v\S', 'bW')<CR>
nnoremap ]<Bslash> :call search('\%' . virtcol('.') . 'v\S', 'wW')<CR>


" make s for spell
nnoremap s= z=

" remember folds
nnoremap zz zf
vnoremap zz zf
set viewoptions-=curdir
set viewoptions-=options
autocmd BufWinLeave *.tex,*.py,*.pyw mkview
autocmd BufWinEnter *.* silent loadview


iabbrev ct COMMENT:
iabbrev mi MAJOR ISSUE:

"single backup on startup
if isdirectory("./.bkp") && filereadable(@%)
    let bkpname=@%.'~'.strftime("%Y-%m-%d-%H")
    silent execute "!cp" @% ".bkp/".bkpname
endif

" Set <F1> to show buffers and user choose one by number
nnoremap <F1> :buffers<CR>:buffer<Space>

" **** BEGIN SECTION: FILETYPES
" format paragraph/range
autocmd filetype tex nnoremap = gwip
autocmd filetype tex nnoremap - gq
autocmd filetype tex setlocal spell spelllang=en_au
autocmd filetype tex set linebreak | set wrap
" autocmd filetype tex set formatoptions=atq2

autocmd filetype java set smartindent

autocmd filetype python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd filetype python set noshowmode
autocmd filetype python onoremap - /_<Enter>
autocmd filetype python iabbrev ct #COMMENT:
autocmd filetype python iabbrev mi #MAJOR ISSUE:

" **** END SECTION: FILETYPES *****

" Set <F2> to compile/execute/produce depending on filetype
autocmd filetype python nnoremap <F2> :!clear;python3 "%"<CR>
autocmd filetype tex nnoremap <F2> :!clear;latexmk -pdf "%"<CR>

:verbose map ]] produces the following output:

x  ]]          *@:call <SNR>30_Python_jump('x', '\v%$|^(class|def|async def)>', 'W', v:count1)<CR>
        Last set from /usr/local/Cellar/vim/8.2.3400/share/vim/vim82/ftplugin/python.vim line 77

o  ]]          *@:call <SNR>30_Python_jump('o', '\v%$|^(class|def|async def)>', 'W', v:count1)<CR>
        Last set from /usr/local/Cellar/vim/8.2.3400/share/vim/vim82/ftplugin/python.vim line 68

n  ]]          *@:call <SNR>30_Python_jump('n', '\v%$|^(class|def|async def)>', 'W', v:count1)<CR>
        Last set from /usr/local/Cellar/vim/8.2.3400/share/vim/vim82/ftplugin/python.vim line 59

n  ]]          * *
        Last set from ~/.vimrc line 39

I am surprised and confused by the double entry for n ]]

4
  • what do you mean with mapping fails? Do you get an error message? Also please show the output in a python file (I suppose that is the filetype when the mapping because of "jedi fails") of :nnoremap [[ and possibly also :nnoremap <buffer> [[ Sep 15 at 5:47
  • By "Mapping fails" i mean that the prior keybinding (move to next section) still continues. FWIW - I now have an imperfect solution. in .vim/after/ftplugin I have created files vim.vim and python.vim, both with the same contents: nunmap [[ nnoremap <buffer> [[ # It still seems odd to me th=at even with the nunmap the <buffer> modifier is still required to create the behaviour I desire. I would still prefer a solution that only involved commands in .vimrc but that may be too much to hope for.
    – Surprised
    Sep 15 at 13:54
  • if you want to get rid of all python specific mappings, you can simply define :let g:no_python_maps=1, if you just want those 2 not to be overwritten, consider creating an issue here: github.com/tpict/vim-ftplugin-python and ask the maintainer to only create the mapping, if there does not exists an existing mapping Sep 15 at 17:05
  • The nunmap shouldn't be necessary, but ~/.vim/after/ftplugin is effectively the standard solution here
    – D. Ben Knoble
    Sep 15 at 19:14
0

Answers from the comments:

  • An ftplugin version (fairly standard): in .vim/after/ftplugin put the following where you need it (e.g., python.vim):
nunmap [[
nnoremap <buffer> [[ #

It is odd that you need to nunmap though.

  • Working with the plugin: if you want to get rid of all python specific mappings, you can simply define :let g:no_python_maps=1, if you just want those 2 not to be overwritten, consider creating an issue here: github.com/tpict/vim-ftplugin-python and ask the maintainer to only create the mapping, if there does not exists an existing mapping

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.