" 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 :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() |
This comment has been minimized.
This comment has been minimized.
What version of vim do you have? |
This comment has been minimized.
This comment has been minimized.
VIM - Vi IMproved 7.4 |
This comment has been minimized.
This comment has been minimized.
Do yourself a favor and upgrade to 8.1 - nothing to loose there while you'll have many benefits. Check it out here REgarding your problem, it might be related to end of line characters. |
This comment has been minimized.
This comment has been minimized.
It seems that my vim can't copy to the system clipboard (I'm in Linux Fedora 31). I have to disable the mouse (and the lateral sections) to use the terminal |
This comment has been minimized.
This comment has been minimized.
If my Ctrl-C/Ctrl-X/Ctrl-V key definitions do not work it is probably because your vim wasn't built with system clipboard support. See https://vim.fandom.com/wiki/Accessing_the_system_clipboard for info on how to check if your vim was built with clipboard support or not. Now separate from that, if you like your terminal window's mouse based text selection and clipboard usage, you can typically get those to work even while mouse is enabled in vim. On my Mac, for example, I can bypass vim's mouse support and access the iTerm2 text selection by pressing the Option key when selecting text with the mouse. Try selecting text while pressing Alt, Shift, etc. to see if you find a key that works on your Linux machine. |
This comment has been minimized.
This comment has been minimized.
Oh yes, I could press Shift while selecting with the mouse, you're right (indeed I've also found the same tip here), but in that case I'd better close the left navigator and it's still ugly to see the line numbers. |
This comment has been minimized.
This comment has been minimized.
Hello @miguelgrinberg, Coming from your youtube video, I'm using vim plug as well, and saw you're using tmux, what kind of customisations did you to have both of them working together (the mouse wheel, or the color support for instance) < Best. |
This comment has been minimized.
This comment has been minimized.
@bmillemathias-1a I didn't really go too crazy on the tmux + vim config. On the tmux side I have mouse enabled, which makes scrolling with the wheel work nicely. 256 color support is also enabled with |
This comment has been minimized.
This comment has been minimized.
Hi, -bash: source: filename argument required |
This comment has been minimized.
This comment has been minimized.
This file is not for sourcing, you just have to put it in your home directory. |
This comment has been minimized.
This comment has been minimized.
@miguelgrinberg Thank you very much!! |
This comment has been minimized.
This comment has been minimized.
Thank you Miguel for the video and sharing your config file. I have a question regarding commenting multiple lines of code in vim. I normally just do ctrl + / in VS Code but in vim, some of the solutions I've found take too many keystrokes. There's also several plugins but now I'm just offered too many choices. What is your process for quickly commenting out multiple lines of code? |
This comment has been minimized.
This comment has been minimized.
@mchlsm I don't have a shortcut built for this. You have to put the cursor on the place where you want the # to be in the first line. Select Ctrl-V for visual block mode, then down arrow until the bottom line. Then Shift-I to insert before cursor, then type the # and maybe a space after it, and finally ESC. To uncomment use Ctrl-V down arrow to the bottom line, right arrow if you added a space after the #. Then x to remove the comments. |
This comment has been minimized.
This comment has been minimized.
It's a little strange that you don't see the comment marker appear on every line immediately after you do Shift-I and start typing (you only see it on the main line you initially selected). The rest of the comment marks only appear after you press ESC. For me, I had to press ESC twice. I suppose I will just have to do this more to make it a muscle memory. Uncommenting worked great. Thank you! |
This comment has been minimized.
This comment has been minimized.
I was getting an annoying error for gtk c files with gtk.h include, and found this suggestion useful:
Now it works as expected (notice that also a |
This comment has been minimized.
This comment has been minimized.
How can I add autocomplete. I have tried editing the pluggins but it shows error everytime. Can you help me there. Thanks in advance |
This comment has been minimized.
This comment has been minimized.
I don't use autocomplete plugins because I haven't found one that works well. You may need to raise an issue on the plugin's repo, or ask in StackOverflow. Sorry. |
This comment has been minimized.
This comment has been minimized.
Hi @miguelgrinberg, Thanks for this vimrc file. |
This comment has been minimized.
This comment has been minimized.
To switch tabs I have configured the [ and ] key sequences (backslash and one of the square brackets). |
This comment has been minimized.
This comment has been minimized.
Perfect! Thank You So Much @miguelgrinberg |
This comment has been minimized.
This comment has been minimized.
Hi @miguelgrinberg, really thank you for sharing your vim configuration file. The file browser doesn't work on my vim, when I try to open it with
|
This comment has been minimized.
This comment has been minimized.
@RichardBaker3020 I'm not sure. Make sure your vim is a version 8.x, and also that you don't have any leftovers from a previous installation, by deleting or renaming the |
This comment has been minimized.
This comment has been minimized.
@miguelgrinberg, thanks for sharing this. Are you not currently using code completion? Do you suggest that we use code completion while using vim for python? I enjoyed VSCode for this reason. Also, I was able to find https://github.com/ycm-core/YouCompleteMe which I may add to my vimrc file. |
This comment has been minimized.
This comment has been minimized.
@evanniedojadlo That's correct, I do not use code completion with vim. There are several plugins that can do it, and they fall into two categories: there are those that aren't too good, and those that are good but are painful to install. I use vim as a quick editor that is available everywhere, if I wanted a full blown IDE with code completion there are better choices. That said, there is no reason why you shouldn't experiment and see if you find a vim completion solution that you like. |
This comment has been minimized.
This comment has been minimized.
@miguelgrinberg excellent, thank you! I appreciate that realistic perspective. |
This comment has been minimized.
This comment has been minimized.
Hi, Thanks in advance, Xavier |
This comment has been minimized.
This comment has been minimized.
@xavysp the "backslash n" shortcut is done by pressing the backslash key (i.e. |
This comment has been minimized.
This comment has been minimized.
Do you have a list or notes on most useful/common shortcuts and options for this vimrc? |
This comment has been minimized.
This comment has been minimized.
@nadiiach There are very few shortcuts added in this config file, actually. You can find them by searching for the lines that use the key mapping commands such as |
This comment has been minimized.
This comment has been minimized.
Did you modify some settings for Tagbar? I would like a cleaner tagbar like the one I saw in your video but I get something like Thanks for sharing this configuration. Really helpful. |
This comment has been minimized.
This comment has been minimized.
@hakanohi I haven't changed anything, but clearly you have long symbols in your source code. See here for how to resize the pane. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
@rs9899 My only guess is that you are not using a recent vim version, but that's just that a guess. I suggest you ask in StackOverflow or in the NERDTree project. |
This comment has been minimized.
This comment has been minimized.
Error detected while processing function NERDTreeToggle[1]..45_NERDTreeToggleAllTabs[7]..45_NERDTreeOpenAllTabs[5]..45_NERDTreeMirrorOr vim version is 8.1 |
This comment has been minimized.
This comment has been minimized.
@vaibhavkumar049 as I said above, I'm not the right person to ask about this. Your vim instance is incompatible with this extensions, but I really don't know why. Vim can be compiled with many options enabled or disabled, you are missing something. Go find someone who knows more about this, I really don't know. |
This comment has been minimized.
This comment has been minimized.
i added this and it seems to solve my problem... let me know if it helps:) |
This comment has been minimized.
This comment has been minimized.
@Binit-Dhakal This works for me, there's still an error message though, but I guess that doesn't matter as file explorer could open normally, Thanks :) |
This comment has been minimized.
This comment has been minimized.
@Binit-Dhakal, thankyou so much this plugin of nerdtree works for me too @RichardBaker3020 I think the error is because of another plugin of nerdtree, if you remove that, it would be fine |
This comment has been minimized.
This comment has been minimized.
@Binit-Dhakal thanks, I wasn't aware there was a newer fork of nerdtree. I have tested it and it appears to work fine for me so I have updated this gist to use it. Thanks! |
This comment has been minimized.
This comment has been minimized.
@RichardBaker3020 |
This comment has been minimized.
This comment has been minimized.
Thank you. Does closing buffer works for you ? I've replaced it with
|
This comment has been minimized.
This comment has been minimized.
@iddoeldor: I rarely use the close buffer command, could be that I have never tested it outside of having a single file, yeah. I'll fix it, thanks! |
This comment has been minimized.
This comment has been minimized.
Hello Miguel, I am getting an error like this on the terminal when I try to do "vim .vimrc" which I have copied from this repo. |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
Hi @miguelgrinberg, why aren't you including in the file? |
This comment has been minimized.
This comment has been minimized.
@disooqi I'm using |
This comment has been minimized.
Hi
I get this issue on Linux
I added .vimrc in my home
I launched vim or vi , i get this below
Error detected while processing /u/users/ray1234/.vimrc:
line 2:
E15: Invalid expression: 0^M
line 3:
E15: Invalid expression: empty(glob('~/.vim/autoload/plug.vim'))^M
line 184:
E171: Missing :endif
Press ENTER or type command to continue