Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My .vimrc configuration for working in Python with vim
" plugins
let need_to_install_plugins = 0
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
let need_to_install_plugins = 1
endif
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'itchyny/lightline.vim'
Plug 'joshdick/onedark.vim'
Plug 'ap/vim-buftabline'
Plug 'airblade/vim-gitgutter'
Plug 'preservim/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'jiangmiao/auto-pairs'
Plug 'dense-analysis/ale'
Plug 'majutsushi/tagbar'
Plug 'vim-scripts/indentpython.vim'
Plug 'lepture/vim-jinja'
Plug 'pangloss/vim-javascript'
Plug 'alvan/vim-closetag'
Plug 'maxmellon/vim-jsx-pretty'
call plug#end()
filetype plugin indent on
syntax on
if need_to_install_plugins == 1
echo "Installing plugins..."
silent! PlugInstall
echo "Done!"
q
endif
" always show the status bar
set laststatus=2
" enable 256 colors
set t_Co=256
set t_ut=
" turn on line numbering
set number
" sane text files
set fileformat=unix
set encoding=utf-8
set fileencoding=utf-8
" sane editing
set tabstop=4
set shiftwidth=4
set softtabstop=4
set colorcolumn=80
set expandtab
set viminfo='25,\"50,n~/.viminfo
autocmd FileType html setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType css setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2
" auto-pairs
au FileType python let b:AutoPairs = AutoPairsDefine({"f'" : "'", "r'" : "'", "b'" : "'"})
" word movement
imap <S-Left> <Esc>bi
nmap <S-Left> b
imap <S-Right> <Esc><Right>wi
nmap <S-Right> w
" indent/unindent with tab/shift-tab
nmap <Tab> >>
nmap <S-tab> <<
imap <S-Tab> <Esc><<i
vmap <Tab> >gv
vmap <S-Tab> <gv
" mouse
set mouse=a
let g:is_mouse_enabled = 1
noremap <silent> <Leader>m :call ToggleMouse()<CR>
function ToggleMouse()
if g:is_mouse_enabled == 1
echo "Mouse OFF"
set mouse=
let g:is_mouse_enabled = 0
else
echo "Mouse ON"
set mouse=a
let g:is_mouse_enabled = 1
endif
endfunction
" color scheme
syntax on
colorscheme onedark
filetype on
filetype plugin indent on
" lightline
set noshowmode
let g:lightline = { 'colorscheme': 'onedark' }
" code folding
set foldmethod=indent
set foldlevel=99
" wrap toggle
setlocal nowrap
noremap <silent> <Leader>w :call ToggleWrap()<CR>
function ToggleWrap()
if &wrap
echo "Wrap OFF"
setlocal nowrap
set virtualedit=all
silent! nunmap <buffer> <Up>
silent! nunmap <buffer> <Down>
silent! nunmap <buffer> <Home>
silent! nunmap <buffer> <End>
silent! iunmap <buffer> <Up>
silent! iunmap <buffer> <Down>
silent! iunmap <buffer> <Home>
silent! iunmap <buffer> <End>
else
echo "Wrap ON"
setlocal wrap linebreak nolist
set virtualedit=
setlocal display+=lastline
noremap <buffer> <silent> <Up> gk
noremap <buffer> <silent> <Down> gj
noremap <buffer> <silent> <Home> g<Home>
noremap <buffer> <silent> <End> g<End>
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>
endif
endfunction
" move through split windows
nmap <leader><Up> :wincmd k<CR>
nmap <leader><Down> :wincmd j<CR>
nmap <leader><Left> :wincmd h<CR>
nmap <leader><Right> :wincmd l<CR>
" move through buffers
nmap <leader>[ :bp!<CR>
nmap <leader>] :bn!<CR>
nmap <leader>x :bp<bar>bd#<CR>
" restore place in file from previous session
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" file browser
let NERDTreeIgnore = ['\.pyc$', '__pycache__']
let NERDTreeMinimalUI = 1
let g:nerdtree_open = 0
map <leader>n :call NERDTreeToggle()<CR>
function NERDTreeToggle()
NERDTreeTabsToggle
if g:nerdtree_open == 1
let g:nerdtree_open = 0
else
let g:nerdtree_open = 1
wincmd p
endif
endfunction
function! StartUp()
if 0 == argc()
NERDTree
end
endfunction
autocmd VimEnter * call StartUp()
" ale
map <C-e> <Plug>(ale_next_wrap)
map <C-r> <Plug>(ale_previous_wrap)
" tags
map <leader>t :TagbarToggle<CR>
" copy, cut and paste
vmap <C-c> "+y
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
" disable autoindent when pasting text
" source: https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
@miguelgrinberg
Copy link
Author

miguelgrinberg commented Dec 12, 2020

@mgourab I do not know the reason, but the onedark color scheme is a plugin that should be installed automatically the first time run vim after installing my config file.

@disooqi
Copy link

disooqi commented Feb 15, 2021

Hi @miguelgrinberg, why aren't you including
Plug 'vim-scripts/The-NERD-tree'
Plug 'vim-syntastic/syntastic'

in the file?

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Feb 15, 2021

@disooqi I'm using vimpreserve/nerdtree instead of vim-scripts/The-NERD-tree. And these days I'm also using ALE instead of syntastic.

@yuxiaoy1
Copy link

yuxiaoy1 commented Mar 20, 2021

@mgourab there should be some connection issues with GitHub, you can press enter to find them out.

@yuxiaoy1
Copy link

yuxiaoy1 commented Mar 20, 2021

@miguelgrinberg thanks for the configuration file, I suggest to add let NERDTreeShowHidden=1 to show hidden files, like .env, in file browser.

@YiweiJiang2015
Copy link

YiweiJiang2015 commented Apr 11, 2021

Many thanks for sharing your config. I found one minor change of the plugin sources:

Plug 'majutsushi/tagbar'
>>> Plug 'preservim/tagbar'

Better update this?

@techns27
Copy link

techns27 commented Apr 17, 2021

Hi Sir,

How to enable linter on code save in Vim?

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Apr 17, 2021

@techns27 The linter that I'm using is ALE, and it runs in the background, no need to run it on save.

@Abhishekparas
Copy link

Abhishekparas commented May 7, 2021

I am also having the same color scheme but I am not getting that black-ish background as yours, I have that standard background of one dark theme. Can you please help me out and tell what to do because in that background the colors appear so bright.

@miguelgrinberg
Copy link
Author

miguelgrinberg commented May 7, 2021

@Abhishekparas I'm not sure. In general this is a problem with your terminal configuration and not with the theme. The value of my TERM variable is xterm-256color. If you use a different terminal interface you may see some differences.

@Abhishekparas
Copy link

Abhishekparas commented May 10, 2021

Thanks for replying! I will check it out

@PolyMMA
Copy link

PolyMMA commented Jul 16, 2021

As soon as NERDtree is on, then :bd or :q closes whole vim, not only the current buffer. When I have several buffers up, this is a problem. However, when I close NERDtree, I can close one buffer at a time using the :bd or :q

Anyone else having this issue?

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Jul 22, 2021

@PolyMMA: this is an issue with NERDtree I suppose. I just added a correction to the \x command, which was incorrectly doing :bd. It now works for closing all buffers but the last.

@PolyMMA
Copy link

PolyMMA commented Jul 24, 2021

@miguelgrinberg: Thanks for the soulution. Now \x closes the open buffer. Any plans to mitigate the issues with NERDtree?

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Jul 24, 2021

@PolyMMA NERDtree is not my project, I'm just a user. I don't really have an interest in this, my current set up has a minimum amount of annoyances so I don't have any plans to address it any further.

@Pim-tech
Copy link

Pim-tech commented Aug 6, 2021

I Miguel.
Thank you very much for this purpose.
Does your configuration does step by step debugging?
Thank you.

@Pim-tech
Copy link

Pim-tech commented Aug 6, 2021

I whatched you video too.

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Aug 6, 2021

@Pim-tech No. Vim is a text editor, not an IDE. If you need an interactive debugger, use Visual Studio Code or PyCharm, or if you prefer to debug in the terminal, pudb.

@jgarte
Copy link

jgarte commented Sep 1, 2021

@miguelgrinberg

How do you like pudb?

Do you use it in your workflow regularly?

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Sep 1, 2021

@jgarte pudb is my first debugger of choice these days. It's really good.

@corpmule
Copy link

corpmule commented Oct 17, 2021

@miguelgrinberg and Everyone,

I'm getting errors when I run vim with this vimrc.

I only know enough about all of this ... to be dangerous. :) So I'll probably be asking some stoopid questions.

I'm using version 8.0 in the Windows Linux (Ubuntu) shell or app.

At first the errors were from the "if" statement that runs "curl."

I kept getting permission denied when it attempted to create the ~/.vim/autoload/plugin.vim. I tried chaning the permissions on the directories and files but it didn't help. In fact, this is what it looks like now.

hostname:~$ ls -la ~/.vim/autoload/
ls: cannot access '/home/corpmule/.vim/autoload/plug.vim': Permission denied
...snip...
-????????? ? ?     ?        ?            ? plug.vim

I've never seen anything like that.

I also ran the curl command directly from the command line, using sudo. That might be how the above was actually created.

After I edited the vimrc, to move the ! (bang) -- to be directly after the "silent" command, and, put the url on the same line, those errors went away.

silent! curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

But now ... I get more errors...

Error detected while processing /usr/share/vim/vimrc:
line   17:
E117: Unknown function: plug#begin
line   18:
E492: Not an editor command: Plug 'tpope/vim-sensible
...etc

Those "Not an editor command" erors continue through all the lines (plugins) within this function.

If anybody has an idea what I'm doing wrong, or how I could try to fix this, I'd appreciate it.

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Oct 17, 2021

@corpmule I don't know. I'm not a regular Windows user, but I have used this configuration on WSL occasionally and I don't recall having any problems.

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Nov 7, 2021

@RandomShtuf I'm not sure, but the error comes from the auto-pairs plugin, so it must be related to that. Unfortunately I'm not an expert in vim plugin internals, so I cannot really help you on this.

@RandomShtuf
Copy link

RandomShtuf commented Nov 8, 2021

@RandomShtuf I'm not sure, but the error comes from the auto-pairs plugin, so it must be related to that. Unfortunately I'm not an expert in vim plugin internals, so I cannot really help you on this.

oh... thanks anyway... fortunately i was able to fix it... i just had to remove ~/.vim like you did in your video

@RandomShtuf
Copy link

RandomShtuf commented Nov 8, 2021

another quick question tho... is there a way to show dot files/hidden files on the file manager?

@yuxiaoy1
Copy link

yuxiaoy1 commented Nov 8, 2021

@RandomShtuf you can add let NERDTreeShowHidden=1

@Jooaomar
Copy link

Jooaomar commented Mar 21, 2022

thanks

@amiyalahiri9800
Copy link

amiyalahiri9800 commented Mar 25, 2022

@miguelgrinberg sir I am not able to on file system and tagbar.
could you please tell me how to do that

@mamodrzejewski
Copy link

mamodrzejewski commented Apr 14, 2022

Hi Miguel. Are you using the default macOS terminal? Does not seem to work properly for me when using the nice onedark theme, no matter the settings. Works fine with set termguicolors and iTerm though. Any ideas on this matter? Thanks!

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Apr 14, 2022

@mamodrzejewski I use iterm2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment