Vim永久语法高亮显示

时间:2017-09-19 05:32:15

标签: vim macvim

每当我处理TypeScript文件时,我都在使用:set syntax=javascript。我想根据我的文件类型自动设置语法。现在这就是事情,我之前已经完成了添加: au BufNewFile,BufRead,BufReadPost *.ts set syntax=javascript 但是,对于我的~/.vimrc文件,它似乎不再起作用了。

以下是我的.vimrc文件的内容。有没有理由说这不起作用?

colorscheme atom-dark-256
set number
set autoindent
set guifont=monaco:h12
set expandtab
set tabstop=4 shiftwidth=4 expandtab

au BufNewFile,BufRead,BufReadPost *.ts set syntax=javascript
au BufNewFile,BufRead,BufReadPost *.handlebars set syntax=HTML
au BufNewFile,BufRead,BufReadPost *.twig set syntax=HTML
au BufNewFile,BufRead,BufReadPost *.theme set syntax=PHP

我确定它曾经工作得很好,但它因某些原因而停止了。有任何想法吗?如果有帮助,我正在使用MacVim?

1 个答案:

答案 0 :(得分:2)

我们将var WebSocketServer = require('ws').Server, request = require('request'); var mysql = require('mysql'); var dateFormat = require('dateformat'); var each = require('foreach'); var async = require('async'); var moment = require('moment'); //ws://192.168.0.43:7000 wss = new WebSocketServer({host: '192.168.0.43',port: 17000,autoAcceptConnections: true}); // Mysql connection var db = mysql.createConnection({ host: 'localhost', user: 'root', database: 'metropark', timezone: 'utc', dateStrings: true }) client_connection = []; var connections = new Map(); var idCounter = 0; var POLLING_INTERVAL = 1000; var connectionsArray = []; var isInitNotes = false; var notes = []; // Log any errors connected to the db db.connect(function(err){ if (err) console.log(err) }) /* * This function loops on itself since there are sockets connected to the page * sending the result of the database query after a constant interval * */ /* Polling the data in every second */ /* Start - Fetching data from multiple tables */ var pollingLoop = function () { var collection = {}; var parking = {}; var pricing = {}; var stay = {}; var zoneid = []; var parking_id = []; var d = new Date(); var dayweek = d.getDay(); var final_result = { zone_info:{} }; var bay_data = {}; async.series({ Bays: function(callback){ query = db.query('SELECT B.bay_id, B.zone_id, Z.id as zid, B.bearing, B.bay_state_api, B.bay_state, B.bay_state_officer, B.esmart_bay_id, B.longitude, B.latitude, B.vehicle_number, B.node_status, B.last_updated, B.id as bayid, B.uodisable, Z.parking_category, Z.zone_id as zoneid, Z.zone_name, Z.street_name, Z.bounds, Z.latitude as zlatitude, Z.longitude as zlongitude, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer = 2 AND A.is_current = 1 AND A.node_status = 1) as disabled_bays, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer = 3 AND A.is_current = 1 AND A.node_status = 1) as disabled_apporved_bays, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer IN (4,9) AND A.is_current = 1 AND A.node_status = 1) as disabled_apporved_offended_bays, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer = 6 AND A.is_current = 1 AND A.node_status = 1) as disabled_abt_to_expiry, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer = 5 AND A.is_current = 1 AND A.node_status = 1) as abt_to_expiry, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer IN (4,7,10) AND A.is_current = 1 AND A.node_status = 1) as offended_bays, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.bay_state_officer = 8 AND A.is_current = 1 AND A.node_status = 1) as cited_bays, (SELECT COUNT(*) as total FROM mp_bays AS A WHERE A.zone_id = B.zone_id AND A.is_current = 1 AND A.node_status = 0) as faulty_bays, (SELECT S.id FROM mp_stay_logs AS S WHERE S.bay_id = B.id AND S.vehicle_number = B.vehicle_number ORDER BY S.created DESC LIMIT 1) as stay_id, now() as time_now FROM mp_bays AS B INNER JOIN mp_zones Z ON Z.id = B.zone_id WHERE B.esmart_bay_id = "ES0170"'); //'2017-09-14 14:20:20 >= 2017-09-14 14:20:21' query.on('error', function(err){ callback(err); }); query.on('result', function(row){ collection.bay_id = row.bay_id; collection.esmart_bay_id = row.esmart_bay_id; collection.zone_id = row.zoneid; collection.bearing = row.bearing; collection.bay_state_api = row.bay_state_api; collection.bay_state = row.bay_state; collection.bay_state_officer = row.bay_state_officer; collection.esmart_bay_id = row.esmart_bay_id; collection.longitude = row.longitude; collection.latitude = row.latitude; collection.vehicle_number = row.vehicle_number; collection.node_status = row.node_status; collection.last_updated = row.last_updated; collection.bayid = row.bayid; collection.uodisable = row.uodisable; collection.parking_category = row.parking_category; collection.stay_id = row.stay_id; collection.zone_name = row.zone_name; collection.street_name = row.street_name; collection.bounds = row.bounds; collection.zlatitude = row.zlatitude; collection.zlongitude = row.zlongitude; collection.disabled_bays = row.disabled_bays; collection.disabled_apporved_bays = row.disabled_apporved_bays; collection.disabled_apporved_offended_bays = row.disabled_apporved_offended_bays; collection.disabled_abt_to_expiry = row.disabled_abt_to_expiry; collection.abt_to_expiry = row.abt_to_expiry; collection.offended_bays = row.offended_bays; collection.cited_bays = row.cited_bays; collection.faulty_bays = row.faulty_bays; collection.time_now = row.time_now; zoneid.push(row.zone_id); }); query.on('end', function(result){ callback(null, collection); }); }, Parking: function(callback){ console.log("parkingh"); console.log(collection); //if(collection.Bays == null) { if(isEmptyObject(collection)) { callback(null, ""); } else { if(zoneid.length == 0){ parking.open_time = ""; parking.close_time = ""; callback(null, parking); }else{ query = db.query('SELECT parking_type_id, open_time, close_time FROM mp_zones_parking_types WHERE zone_id IN (?) AND FIND_IN_SET(?,applicable_days) AND open_time <= CURTIME() AND close_time >= CURTIME()', [zoneid, dayweek]); //console.log(query); query.on('error', function(err){ callback(err); }); query.on('result', function(row){ //console.log(row); parking_id.push(row.parking_type_id); parking.parking_type_id = row.parking_type_id; parking.open_time = row.open_time; parking.close_time = row.close_time; }); query.on('end', function(result){ callback(null,parking); }); } } }, Duration: function(callback){ //if(collection.Bays == null) { if(isEmptyObject(collection)) { callback(null, ""); } else { if(parking_id.length == 0){ callback(null, ""); } else { if(collection.parking_category == 2) { query = db.query('SELECT MAX(end_time) as duration, (SELECT grace_time FROM mp_settings) as grace_time FROM mp_pricing_schemas WHERE parking_type_id IN (?)', [parking_id]); //console.log(query); query.on('error', function(err){ callback(err); }); query.on('result', function(row){ console.log(row); pricing.duration = row.duration; pricing.grace_time = row.grace_time; }); query.on('end', function(result){ callback(null,pricing); }); } else { query = db.query('SELECT duration, grace_minutes as grace_time FROM mp_parking_types WHERE id IN (?)', [parking_id]); //console.log(query); query.on('error', function(err){ callback(err); }); query.on('result', function(row){ pricing.duration = row.duration; pricing.grace_time = row.grace_time; }); query.on('end', function(result){ callback(null,pricing); }); } } } }, Stay: function(callback){ //if(collection.Bays == null) { if(isEmptyObject(collection)) { callback(null, ""); } else { if(collection.stay_id == null) { stay.arrival_time = collection.last_updated; stay.out_time = ''; stay.purchase_time = ''; stay.expiry_time = ''; stay.vehicle_number = collection.vehicle_number; stay.is_disabled = collection.is_disabled; stay.calc_expiry_time = ""; stay.is_cited = collection.is_cited; stay.citation_id = ""; stay.cited_time = ""; stay.uodisable = collection.uodisable; callback(null, stay); } else { query = db.query('SELECT arrival_time, out_time, purchase_time, expiry_time, vehicle_number, is_disabled, calc_expiry_time, is_cited, citation_id, cited_time, uodisable FROM mp_stay_logs WHERE id IN (?)', [collection.stay_id]); //console.log(query); query.on('error', function(err){ callback(err); }); query.on('result', function(row){ console.log(row); //pricing.duration = row.duration; //pricing.grace_time = row.grace_time; stay.arrival_time = row.arrival_time; stay.out_time = row.out_time; stay.purchase_time = row.purchase_time; stay.expiry_time = row.expiry_time; stay.vehicle_number = row.vehicle_number; stay.is_disabled = row.is_disabled; stay.calc_expiry_time = row.calc_expiry_time; stay.is_cited = row.is_cited; stay.citation_id = row.citation_id; stay.cited_time = row.cited_time; stay.uodisable = row.uodisable; }); query.on('end', function(result){ callback(null,stay); }); } } }, }, function(err, results) { console.log(results); if(!isEmptyObject(results.Bays)) { final_result.zone_info.zone_id = results.Bays.zone_id; final_result.zone_info.zone_name = results.Bays.zone_name; final_result.zone_info.street_name = results.Bays.street_name; //var array = JSON.parse( results.Bays.bounds ); //console.log(array.length) //final_result.zone_info.bounds = array; final_result.zone_info.bounds = results.Bays.bounds; final_result.zone_info.latitude = ""+results.Bays.zlatitude+""; final_result.zone_info.longitude = ""+results.Bays.zlongitude+""; final_result.zone_info.parking_category = ""+results.Bays.parking_category+""; final_result.zone_info.disabled_bays = ""+results.Bays.disabled_bays+""; final_result.zone_info.disabled_apporved_bays = ""+results.Bays.disabled_apporved_bays+""; final_result.zone_info.disabled_apporved_offended_bays = ""+results.Bays.disabled_apporved_offended_bays+""; final_result.zone_info.disabled_abt_to_expiry = ""+results.Bays.disabled_abt_to_expiry+""; final_result.zone_info.abt_to_expiry = ""+results.Bays.abt_to_expiry+""; final_result.zone_info.offended_bays = ""+results.Bays.offended_bays+""; final_result.zone_info.cited_bays = ""+results.Bays.cited_bays+""; final_result.zone_info.faulty_bays = ""+results.Bays.faulty_bays+""; final_result.zone_info.time_now = results.Bays.time_now; var grace_time = results.Duration.grace_time; var duration = results.Duration.duration; var double_duration = duration + duration; var td_duration = duration + grace_time; bay_data.bay_id = results.Bays.bay_id; bay_data.esmart_bay_id = results.Bays.esmart_bay_id; bay_data.latitude = ""+results.Bays.latitude+""; bay_data.longitude = ""+results.Bays.longitude+""; bay_data.bearing = ""+results.Bays.bearing+""; bay_data.bay_state_api = ""+results.Bays.bay_state_api+""; bay_data.bay_state = ""+results.Bays.bay_state+""; bay_data.bay_state_officer = ""+results.Bays.bay_state_officer+""; bay_data.vehicle_number = results.Bays.vehicle_number; bay_data.node_status = ""+results.Bays.node_status+""; bay_data.last_updated = results.Bays.last_updated; bay_data.bayid = ""+results.Bays.bayid+""; bay_data.parking_category = ""+results.Bays.parking_category+""; var open_time = results.Parking.open_time; var close_time = results.Parking.close_time; //var current_datetime = new moment ().format("YYYY-MM-DD HH:MM:SS"); //var current_time = new moment ().format("HH:MM:SS"); var current_datetime = "2017-09-18 17:16:00"; var current_time = "17:16:00"; // baystatus for grouping if(results.Bays.node_status == 1) { if(results.Bays.bay_state_officer == 4 || results.Bays.bay_state_officer == 7 || results.Bays.bay_state_officer == 10) { bay_data.baystatus = "1"; } else if(results.Bays.bay_state_officer == 8) { bay_data.baystatus = "5"; } else if(results.Bays.bay_state_officer == 1) { bay_data.baystatus = "0"; } else { if(results.Bays.uodisable == 1) { bay_data.baystatus = "4"; } else { bay_data.baystatus = "2"; } } } else { bay_data.baystatus = "3"; } bay_data.disable_allow = "1"; if(results.Bays.stay_id > 0) { console.log("yes stay"); if(results.Stay.purchase_time == '0000-00-00 00:00:00') { // total_time_stayed var total_time_stayed = diffHours(results.Stay.cited_time, results.Stay.arrival_time) if(total_time_stayed == "") { bay_data.total_time_stayed = "-"; } else { bay_data.total_time_stayed = total_time_stayed; } // total time var minutes = diffMinutes(current_datetime, results.Bays.last_updated) if(minutes > double_duration) { bay_data.disable_allow = "0"; } if(minutes > grace_time && results.Bays.parking_category == 2) { var remainingTime = minutes - grace_time; bay_data.time = get_time_diff(remainingTime); } else if((minutes > td_duration && results.Bays.parking_category == 1) || (minutes > td_duration && results.Bays.parking_category == 3)) { var remainingTime = minutes - td_duration; bay_data.time = get_time_diff(remainingTime); } else { bay_data.time = "-"; } var time = diffHours(current_datetime,results.Stay.expiry_time); if(time == "") { bay_data.time = "-"; } else { bay_data.time = time; } bay_data.arrival_time = results.Stay.arrival_time; bay_data.out_time = results.Stay.out_time; bay_data.purchase_time = results.Stay.purchase_time; bay_data.expiry_time = results.Stay.expiry_time; bay_data.citation_id = results.Stay.citation_id; bay_data.cited_time = results.Stay.cited_time; bay_data.uodisable = ""+results.Stay.uodisable+""; bay_data.vehicle_number = results.Stay.vehicle_number; } else { // total_time_stayed console.log("total time "+current_datetime+" -- "+results.Stay.purchase_time); var total_time_stayed = diffHours(current_datetime, results.Stay.purchase_time); if(total_time_stayed == "") { bay_data.total_time_stayed = "-"; } else { bay_data.total_time_stayed = total_time_stayed; } // total time if(results.Stay.is_disable == 1) { if(results.Stay.calc_expiry_time != "") { var time = diffHours(results.Stay.calc_expiry_time, current_datetime); } else { var time = diffHours(results.Stay.expiry_time, current_datetime); } } else { var time = diffHours(results.Stay.expiry_time, current_datetime); } if(time == "") { bay_data.time = "-"; } else { bay_data.time = time; } } } else { console.log("no stay"); bay_data.arrival_time = results.Bays.last_updated; bay_data.out_time = ""; bay_data.purchase_time = ""; bay_data.vehicle_number = results.Bays.vehicle_number; bay_data.expiry_time = ""; bay_data.citation_id = ""; bay_data.uodisable = results.Bays.uodisable; var last_updated = moment(results.Bays.last_updated); var lastupdated = last_updated.format("YYYY/MM/DD HH:mm:ss"); var current_date = new moment ().format("YYYY-MM-DD"); var zone_opentime = current_datetime+" "+open_time; var zone_closetime = current_datetime+" "+close_time; if(open_time != "") { if(zone_opentime <= lastupdated) { var time1 = last_updated; } else { var time1 = zone_opentime; } } if(close_time != "") { if(zone_closetime <= current_time) { var time2 = zone_closetime; } else { var time2 = current_datetime; } } if(time1 != "" && time2 != "") { // total_time_stayed var total_time_stayed = diffHours(time2, time1); if(total_time_stayed == "") { bay_data.total_time_stayed = "-"; } else { bay_data.total_time_stayed = total_time_stayed; } } else { bay_data.total_time_stayed = "-"; bay_data.time = "-"; } // total time var minutes = diffMinutes(time2, time1) if(minutes > double_duration) { bay_data.disable_allow = "0"; } if(minutes > grace_time && results.Bays.parking_category == 2) { var remainingTime = minutes - grace_time; bay_data.time = get_time_diff(remainingTime); } else if((minutes > td_duration && results.Bays.parking_category == 1) || (minutes > td_duration && results.Bays.parking_category == 3)) { var remainingTime = minutes - td_duration; bay_data.time = get_time_diff(remainingTime); } else { bay_data.time = "-"; } } final_result.zone_info.bayinfo = bay_data; } if(connectionsArray.length) { pollingTimer = setTimeout( pollingLoop, POLLING_INTERVAL ); updateSockets(final_result); } }); }; /* End - Fetching data from multiple tables */ function diffHours(now, then) { var ms = moment(now,"YYYY/MM/DD HH:mm:ss").diff(moment(then,"YYYY/MM/DD HH:mm:ss")); var d = moment.duration(ms); var s = Math.abs(d.asHours()) + moment.utc(ms).format(":mm:ss"); var hours = Math.abs(d.asHours()); var time = ""; //console.log(Math.round(hours)+"hours"); var hours = Math.round(hours); if(hours > 0) { if(hours == 1) { time += hours+" hour"; } else { time += hours+" hours"; } time += " "; } else { if(hours < 0) { time += hours+" hours"; time += " "; } } if(d.minutes() > 0) { if(d.minutes() == 1) { time += d.minutes()+" minute"; } else { time += d.minutes()+" minutes"; } } else { if(d.minutes() == -1) { time += d.minutes()+" minute"; } else { time += d.minutes()+" minutes"; } } return time; } function diffMinutes(now, then) { var diff = Math.abs(new Date(now) - new Date(then)); var minutes = Math.floor((diff/1000)/60); return minutes; } function get_time_diff(minutes) { if(minutes > 60) { var rm_mins = minutes % 60; var val = minutes - rm_mins; var hours = val/60; if (hours) { if (rm_mins > 0) { var duration = hours + " hour " + rm_mins + " minutes"; } else { var duration = hours + " hours"; } } } else { if(minutes > 1) { var duration = minutes + " minutes"; } else { var duration = minutes + " minute"; } } return duration; } // This should work in node.js and other ES5 compliant implementations. function isEmptyObject(obj) { return !Object.keys(obj).length; } wss.on('connection', function(ws) { //console.log('test'); console.log('Server was connected.'); console.log('Number of connections:' + connectionsArray.length); // start the polling loop only if at least there is one user connected if (!connectionsArray.length) { pollingLoop(); } ws.on('close', function () { var socketIndex = connectionsArray.indexOf( ws ); console.log('socket = ' + socketIndex + ' disconnected'); if (socketIndex >= 0) { connectionsArray.splice( socketIndex, 1 ); } }); console.log( 'A new socket is connected!' ); connectionsArray.push( ws ); }); var updateSockets = function ( data ) { // store the time of the latest update //data.time = new Date(); //var current_datetime = new moment ().format("YYYY-MM-DD HH:MM:SS"); //data.current_datetime = current_datetime; // send new data to all the sockets connected connectionsArray.forEach(function( tmpSocket ){ if(tmpSocket.readyState == 1) { if(!isEmptyObject(data.zone_info)) { console.log("stringify ---"+JSON.stringify(data)); tmpSocket.send( JSON.stringify(data) ); } else { } } }); };的文件类型设置为javascript,以便使用

语法应用*.ts语法
javascript