Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: I may have gone down a vim configuration rabbit hole recently...

...

Jump to File (fuzzy search)

ctrlp.vim

Use the https://github.com/ctrlpvim/ctrlp.vim plugin

Code Block
# Using https://github.com/junegunn/vim-plug

call plug#begin('~/.config/nvim/plugged')
Plug 'ctrlpvim/ctrlp.vim'
call plug#end()

Tip: to speed up ctrlp.vim, use ripgrep:

Code Block
if executable('rg')
    let g:ctrlp_user_command = 'rg %s -i --color never --no-heading --hidden --no-messages
        \ -g "" --files'
endif
fzf.vim

Consider using fzf.vim instead which can be faster than ctrlp. The program fzf, which backs fzf.vim, can also be used in your shell as a kind of fuzzy tab-complete and history search. Set fzf's default command to ripgrep instead of find to make it even faster (insert into your ~/.bashrc):

Code Block
languagebash
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,vendor}" -g "!*.{swp,pyc}"'


Quality

syntastic

Install the following plugin using your preferred plugin manager:

...

Note: Improvements to the statusline would be welcome.  The one above doesn't show the usual line/column number information unless all lint errors are resolved.

ale

Alternatively, try installing https://github.com/w0rp/ale which utilizes Vim 8's asynchronous engine. This enables continously linting a file as you edit without any lag.

For NeoVim

Install the following plugin:

...

Jump to Definition and Auto-Complete

There are a few options:

...

python-mode

...

https://github.com/python-mode/python-mode

YouCompleteMe

In addition to auto-complete, YouCompleteMe includes jump-to-definition commands https://github.com/Valloric/YouCompleteMe#goto-commands

YouCompleteMe supports Python in addition to many other languages: https://github.com/Valloric/YouCompleteMe

...

Using tags

Tag files can be generated automatically with vim-gutentags using ctags. Make sure to install exuberant-ctags (ubuntu package) or universal-ctags (a maintained fork of exuberant-ctags, but I'm unclear on it's production-readiness) which adds support for Python among other languages. Then, you can use vim's built-in <ctrl-]> command to jump to the definition of the variable name under the cursor. See :help 29.1 and :help tags for more info about tags.

Debugging

Add this (or something similar) to your .vimrc:

Code Block
"Insert a ipdb breakpoint below or above current line
nnoremap <leader>b oimport ipdb; ipdb.set_trace()  # BREAKPOINT # noqa: E702<Esc>
nnoremap <leader>B Oimport ipdb; ipdb.set_trace()  # BREAKPOINT # noqa: E702<Esc>

Consider using pudb instead which has a graphical TUI:

Code Block
"Insert a pudb breakpoint below or above current line
nnoremap <leader>b oimport pudb.b<Esc>
nnoremap <leader>B Oimport pudb.b<Esc>

Install pytest-pudb into your virtualenv and the breakpoints will work while running tests too.

Testing

Test current function

If you are using tags (see "Jump to Definition and Auto-complete > Using tags" above), tagbar provides a handy function for getting the function/class name that your cursor is currently under. Add this mapping:

Code Block
function! DockerRun(container, command)
    :exe "!docker exec -t " . a:container . " bash -c '" . a:command . "'"
endfunction

autocmd Filetype python nnoremap <leader>L :call DockerRun("edx.devstack.lms", "source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && pytest " . bufname("%") . " -k " . tagbar#currenttag('%s',''))<CR>
autocmd Filetype python nnoremap <leader>S :call DockerRun("edx.devstack.studio", "source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && pytest " . bufname("%") . " -k " . tagbar#currenttag('%s',''))<CR>

Type <leader>L to run current function in the LMS devstack. Or, type <leader>S to run in the Studio devstack.

I prefer to use vim inside of tmux and have a long-running lower pane logged into the LMS or Studio shell below vim that I can send commands to via vimux.

Code Block
autocmd Filetype python nnoremap <leader>R :call VimuxRunCommand("pytest " . bufname("%") . " -k " . tagbar#currenttag('%s',''))<CR>

Those commands are rather hacky. I'm trying to find a better way with either vim-test or pyest.vim, but I haven't gotten anything to work as reliably. For example, it would be nice if the quickfix window was populated with a list of errors that linked to the locations of the tests.

JavaScript

Linting

Install https://github.com/vim-syntastic/syntastic follow README instructions, then add this to your .vimrc:

...

Alternatively, try installing https://github.com/w0rp/ale which utilizes Vim 8's asynchronous engine. This enables continously linting a file as you edit without any lag.

Git

Install https://github.com/tpope/vim-fugitive for performing typical git actions in vim (log, blame, (un)stage, commit, diff, browse in Github, etc.).

...

Search for String in File

Just type "/", a search query and enter. Then "n" to iterate through matches.


fzf.vim

If you have fzf.vim you can do a fuzzy search for a string in your current buffer with :Blines and then press enter to jump to that line. A convienent mapping for this is:

Code Block
nmap <leader>/ :BLines<CR>

Search for String in Project

Use ":grep". Or, install https://github.com/mileszs/ack.vim.

Tip: to speed up ack.vim, use ripgrep:

Code Block
if executable('rg')
    let g:ackprg = 'rg --vimgrep --no-heading --no-messages'
endif

Search for Tag in Project

If you are using tags (see "Jump to Definition and Auto-complete > Using tags" above) then you can search by function or class definition.

tag-matchlist

Use vim's built in :tselect, type name of the function/class, enter, and then jump to a match by typing the list number.

ctrlp.vim

Use :CtrlPTag to fuzzy search for a function/class.

fzf.vim

Use :Tags to fuzzy search for a function/class. fzf tends to be faster than ctrlp.vim in my experience within the edx-platform.