Skip to content

Commit

Permalink
Initial commit & all basic functionnalities
Browse files Browse the repository at this point in the history
  • Loading branch information
Haelle committed Oct 8, 2019
1 parent 0acef1b commit fae7be7
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
playbook.yml
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ansible vimrc

An Ansible role to install Vim with few plugins.

This role is based on https://github.com/amix/vimrc.

Update the conf with (create an alias ;) ; parenthesis are important :
```bash
(cd ~/.vim_runtime && git stash && git pull --rebase && git stash pop)
```

## Usages

### Rails navigation

- `gf`: goto file
- `o`: go back
- `<Ctrl+w>f`: open in split
- `<Ctrl+w>gf`: open in tab

In NerdTree:
- `<cr>`/`<Enter>`: open
- `i`: open in split horizontal
- `s`: open in split vertical

### Main shortcuts

- markdown folding: `za` open/close section
- NerdTree: `<,+nn>` open/close
- Rspec bindings: `<,+t/s/l/a>` to run spec on file/Single/Last/All
- seeing is believing: `F4/F5/F6` mark/run/mark&run code
- Ack: `Ack <keyword> <dir>` search through files
- Find: `<Ctrl+F>` find files by name
- Snipets: `Ctrl+J>` (see them with `:SnipMateOpenSnippetFiles`)
- Comments: `gc, gcc, gcu`
- Swich between single-line to multi-line code `gJ/gS`
- quick replace: `<Ctr+n><Ctrl+n>cNewVarName`

### Automatic usage

- auto remove trailing spaces
- show all invisible characters
- auto resize vim
- auto add end tag in Ruby
- add Git indication on the left column

## Role Variables

No mandatory params, all params are in `defaults/main.yml`

## Example Playbook

```yaml
- hosts: locahost
roles:
- role: vimrc
```
## Development usage
To run it locally create a symlink : `cd /etc/ansible/roles & sudo ln -s /path/to/vimrc .`

## License

BSD
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
vim_dir: ~/.vim_runtime
fonts_dir: ~/.fonts
ibm_fonts_url: https://github.com/IBM/plex/releases/download/v3.0.0/TrueType.zip
77 changes: 77 additions & 0 deletions files/my_configs.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
" Show line numbers
set number

" auto remove trailing white space
autocmd BufWritePre * :%s/\s\+$//e

" show all characters (trailing space, tab, eol)
set list lcs=tab:▸\ ,eol:¬,trail:·

" set tab to 2 for Ruby files
au FileType ruby call RubyTab()
function! RubyTab()
" nb auto indent spaces
set shiftwidth=2
" nb of spaces per tab
set softtabstop=2
endfunction

" Remove indent after newline in YAML files
let g:ansible_unindent_after_newline = 1

" better resizing
autocmd VimResized * :normal =

" RSpec.vim mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
" Enable seeing-is-believing mappings only for Ruby
augroup seeingIsBelievingSettings
autocmd!

autocmd FileType ruby nmap <buffer> <F6> <Plug>(seeing-is-believing-mark-and-run)
autocmd FileType ruby xmap <buffer> <F6> <Plug>(seeing-is-believing-mark-and-run)
autocmd FileType ruby nmap <buffer> <F4> <Plug>(seeing-is-believing-mark)
autocmd FileType ruby xmap <buffer> <F4> <Plug>(seeing-is-believing-mark)
autocmd FileType ruby imap <buffer> <F4> <Plug>(seeing-is-believing-mark)
autocmd FileType ruby nmap <buffer> <F5> <Plug>(seeing-is-believing-run)
autocmd FileType ruby imap <buffer> <F5> <Plug>(seeing-is-believing-run)
augroup END

" remap SnipeMate to Ctrl+J
imap <C-J> <esc>a<Plug>snipMateNextOrTrigger
smap <C-J> <Plug>snipMateNextOrTrigger
" completion
set wildmode=list:longest,list:full
set complete=.,w,t
"stuff to ignore when tab completing
set wildignore=*.o,*.obj,*~
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>

2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for vimrc
24 changes: 24 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
galaxy_info:
author: Alexis Leclerc
description: vim installation & configuration

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: GNU 3.0

min_ansible_version: 2.8

platforms:
- name: Ubuntu
version:
- bionic

galaxy_tags: [vim, system]

dependencies: []
24 changes: 24 additions & 0 deletions tasks/install_vim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Check if amix/vimrc already cloned
stat:
path: '{{ vim_dir }}'
register: vim_directory

- name: Cloning amix/vimrc
git:
repo: https://github.com/amix/vimrc.git
dest: '{{ vim_dir }}'
version: 'HEAD'
when: not vim_directory.stat.exists

- name: Enable execute on file
file:
path: '{{ vim_dir }}/install_awesome_vimrc.sh'
mode: '0755'
when: not vim_directory.stat.exists

- name: Install amix/vimrc
command: '{{ vim_dir }}/install_awesome_vimrc.sh'
args:
chdir: ~/
when: not vim_directory.stat.exists
55 changes: 55 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: Install Vim
package:
name: vim
state: present

- name: Clone & install amix/vimrc
include: install_vim.yml

- name: Install plugins
git:
repo: '{{ item.url }}'
dest: '{{ vim_dir }}/my_plugins/{{ item.name }}'
with_items:
- url: https://github.com/tpope/vim-rails.git
name: vim-rails
- url: https://github.com/vim-ruby/vim-ruby.git
name: vim-ruby
- url: https://github.com/hwartig/vim-seeing-is-believing.git
name: vim-seeing-is-believing
- url: https://github.com/thoughtbot/vim-rspec.git
name: vim-rspec
- url: https://github.com/tpope/vim-endwise.git
name: vim-endwise
- url: https://github.com/pearofducks/ansible-vim.git
name: ansible-vim
- url: https://github.com/mhinz/vim-signify.git
name: vim-signify
- url: https://github.com/AndrewRadev/splitjoin.vim.git
name: splitjoin.vim

- name: Copy my config
copy:
src: my_configs.vim
dest: '{{ vim_dir }}/my_configs.vim'

# this plugin creates bugs in rails.vim
- name: Disable open_file_under_cursor
file:
path: '{{ vim_dir }}/sources_non_forked/open_file_under_cursor.vim'
state: absent

- name: Remove overriden conf of vim-multiple-cursors
blockinfile:
path: '{{ vim_dir }}/vimrcs/plugins_config.vim'
state: absent
marker_begin: '" => vim-multiple-cursors'
marker_end: "let g:multi_cursor_quit_key = '<Esc>'"
marker: "{mark}"

- name: Remap Ctrl+n for YankStack to Ctrl+o
lineinfile:
path: '{{ vim_dir }}/vimrcs/plugins_config.vim'
regexp: '.+yankstack_substitute_newer_paste'
line: nmap <c-o> <Plug>yankstack_substitute_newer_paste
2 changes: 2 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- vimrc
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for vimrc

0 comments on commit fae7be7

Please sign in to comment.