vi/vim coding setup

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

vi/vim coding setup

Post by ayu »

I finally got fed up with my code looking like shit when writing a lot of code in vim, so I took some time to fix the perfect settings for me

This is my current "draft", and I might change it later (I'll update this thread if I do).

Code: Select all

syntax on
filetype indent on
set nowrap
set number
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType c set omnifunc=ccomplete#Complete
If you, like me, fixed these settings after writing loads of code, you can fix the indentation with the following command

Code: Select all

gg=G
Also, if it doesn't work completely, setting the file type will help sometimes.
I was writing an HTML document while doing this, so all I did was

Code: Select all

set ft=html
and then I did gg=G again to tidy it up :)
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: vi/vim coding setup

Post by bad_brain »

stickied! :)
Image

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: vi/vim coding setup

Post by ayu »

I still use vim. But I would like to recommend Sublime 2 and 3 now as well, as I use this these days when writing scripts.
"The best place to hide a tree, is in a forest"

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Re: vi/vim coding setup

Post by pseudo_opcode »

I don't write code anymore, but here's my vim's remnants of the past, it may have hardcoded dependencies(I hope not), so copy/paste may not work 100%

(oh and I think powerline requires patched fonts on OS X)

Code: Select all

set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-scripts/indentpython.vim'
" Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jnurmine/Zenburn'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-fugitive'
Bundle 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}


" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)


" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

" Set shortcuts for split buffer navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" Enable folding
set foldmethod=indent
set foldlevel=99

" set utf-8
set encoding=utf-8

" Enable folding with the spacebar
nnoremap <space> za

" Show docstrings preview(for SimplyFold
let g:SimpylFold_docstring_preview=1

" PEP8 Indentation
"au BufNewFile,BufRead *.py
"    \ set tabstop=4
"    \ set softtabstop=4
"    \ set shiftwidth=4
"    \ set textwidth=79
"    \ set expandtab
"    \ set autoindent
"    \ set fileformat=unix
"
"" 2 space indentation for fullstack dev
"au BufNewFile,BufRead *.js, *.html, *.css
"    \ set tabstop=3
"    \ set softtabstop=2
"    \ set shiftwidth=2

" Mark extra whitespace
"au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/

" Ensure autocomplete window goes away when we're done with it(for
" YouCompleteMe)
let g:ycm_autoclose_preview_window_after_completion=1

" Define shortcut for goto definition(for YouCompleteME)
map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

" python with virtualenv support
py3 << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  execfile(activate_this, dict(__file__=activate_this))
EOF

let python_highlight_all=1
syntax on

colorscheme zenburn
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
set nu
set relativenumber
set clipboard=unnamed
" Always show statusline
set laststatus=2

" Eliminate lag from insert to normal mode
set ttimeoutlen=10

" Show powerline symbols
let g:Powerline_symbols = 'fancy'

" NerdTree shortcuts
nmap <C-s> :w<CR>
imap <C-s> <Esc>:w<CR>a
nmap <C-n> :NERDTreeToggle<CR>

It looks like this
Last edited by pseudo_opcode on 16 Feb 2018, 15:32, edited 1 time in total.
Reason: Added image

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Re: vi/vim coding setup

Post by pseudo_opcode »

cats wrote:I still use vim. But I would like to recommend Sublime 2 and 3 now as well, as I use this these days when writing scripts.
cats, what would you recommend in 2018? :)

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: vi/vim coding setup

Post by ayu »

pseudo_opcode wrote:
cats wrote:I still use vim. But I would like to recommend Sublime 2 and 3 now as well, as I use this these days when writing scripts.
cats, what would you recommend in 2018? :)

I still use, and recommend, Sublime :D

But a lot of people are talking about Atom now -> https://atom.io/" onclick="window.open(this.href);return false;

For my servers it's still vim though.
"The best place to hide a tree, is in a forest"

User avatar
ph0bYx
Staff Member
Staff Member
Posts: 2039
Joined: 22 Sep 2008, 16:00
15
Contact:

Re: vi/vim coding setup

Post by ph0bYx »

I recently switched from Sublime to Visual Studio Code. So far so good :)

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: vi/vim coding setup

Post by ayu »

ph0bYx wrote:I recently switched from Sublime to Visual Studio Code. So far so good :)

Looks nice! : D

For the record, what I generally use for coding:

Python -> PyCharm
PHP -> PhpStorm
Java -> IntelliJ
C# -> Visual Studio 2017

I mainly sit with PHP these days in my spare time, and since I don't have an assignment at work where I can use PHP, the license for PhpStorm expired ](*,). So for now I'm using Sublime for PHP again, until I can switch back to storm :D
"The best place to hide a tree, is in a forest"

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Re: vi/vim coding setup

Post by pseudo_opcode »

I really like atom too, it does have a vim editing mode plugin, as to everyone else I believe.

I have heard very good things about VSCode, and both of them are actually based on Electron framework(which is written on top of Node.js runtime). So all the view rendering is actually done in HTML5/CSS behind the scenes. It is a fine example of capabilities of HTML5 markup language.

I do use Pycharm and Rubymine from Jetbrains, I really love the model dependency diagrams feature.

And PHP? Interesting? I heard php7 had 14x performance gains in execution without any code changes, seems like Laravel is quite popular these days as well.

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: vi/vim coding setup

Post by ayu »

pseudo_opcode wrote:I really like atom too, it does have a vim editing mode plugin, as to everyone else I believe.

I have heard very good things about VSCode, and both of them are actually based on Electron framework(which is written on top of Node.js runtime). So all the view rendering is actually done in HTML5/CSS behind the scenes. It is a fine example of capabilities of HTML5 markup language.

I do use Pycharm and Rubymine from Jetbrains, I really love the model dependency diagrams feature.

And PHP? Interesting? I heard php7 had 14x performance gains in execution without any code changes, seems like Laravel is quite popular these days as well.
Yeah I love PHP.
It has its downsides of course, but PHP7 and Laravel is so worth it.
Easy to setup and do stuff with, and fun to work with.

And I love all the new web tech that has come and that is coming soon (Like web assembly).
Node.js, Web sockets, Redis, Micro services and what not.
It's a really fun field to poke around in :D
"The best place to hide a tree, is in a forest"

Post Reply